Did I find the right examples for you? yes no

All Samples(2)  |  Call(1)  |  Derive(0)  |  Import(1)
Create a continuous random variable with a triangular distribution.

The density of the triangular distribution is given by

.. math::
    f(x) := \begin{cases}
              0 & \mathrm{for\ } x < a, \\
              \frac{2(x-a)}{(b-a)(c-a)} & \mathrm{for\ } a \le x < c, \\
              \frac{2}{b-a} & \mathrm{for\ } x = c, \\
              \frac{2(b-x)}{(b-a)(b-c)} & \mathrm{for\ } c < x \le b, \\(more...)

        def Triangular(name, a, b, c):
    r"""
    Create a continuous random variable with a triangular distribution.

    The density of the triangular distribution is given by

    .. math::
        f(x) := \begin{cases}
                  0 & \mathrm{for\ } x < a, \\
                  \frac{2(x-a)}{(b-a)(c-a)} & \mathrm{for\ } a \le x < c, \\
                  \frac{2}{b-a} & \mathrm{for\ } x = c, \\
                  \frac{2(b-x)}{(b-a)(b-c)} & \mathrm{for\ } c < x \le b, \\
                  0 & \mathrm{for\ } b < x.
                \end{cases}

    Parameters
    ==========

    a : Real number, :math:`a \in \left(-\infty, \infty\right)`
    b : Real number, :math:`a < b`
    c : Real number, :math:`a \leq c \leq b`

    Returns
    =======

    A RandomSymbol.

    Examples
    ========

    >>> from sympy.stats import Triangular, density, E
    >>> from sympy import Symbol, pprint

    >>> a = Symbol("a")
    >>> b = Symbol("b")
    >>> c = Symbol("c")
    >>> z = Symbol("z")

    >>> X = Triangular("x", a,b,c)

    >>> pprint(density(X)(z), use_unicode=False)
    /    -2*a + 2*z
    |-----------------  for And(a <= z, z < c)
    |(-a + b)*(-a + c)
    |
    |       2
    |     ------              for z = c
    <     -a + b
    |
    |   2*b - 2*z
    |----------------   for And(z <= b, c < z)
    |(-a + b)*(b - c)
    |
    \        0                otherwise

    References
    ==========

    .. [1] http://en.wikipedia.org/wiki/Triangular_distribution
    .. [2] http://mathworld.wolfram.com/TriangularDistribution.html
    """

    return rv(name, TriangularDistribution, (a, b, c))
        


src/s/y/sympy-HEAD/sympy/stats/tests/test_continuous_rv.py   sympy(Download)
from sympy.stats import (P, E, where, density, variance, covariance, skewness,
                         given, pspace, cdf, ContinuousRV, sample,
                         Arcsin, Benini, Beta, BetaPrime, Cauchy,
                         Chi, ChiSquared,
                         ChiNoncentral, Dagum, Erlang, Exponential,
    c = Symbol("c")
 
    X = Triangular('x', a, b, c)
    assert density(X)(x) == Piecewise(
                 ((2*x - 2*a)/((-a + b)*(-a + c)), And(a <= x, x < c)),