Did I find the right examples for you? yes no

# sympy.stats.LogNormal

All Samples(6)  |  Call(5)  |  Derive(0)  |  Import(1)
Create a continuous random variable with a log-normal distribution.

The density of the log-normal distribution is given by

.. math::
f(x) := \frac{1}{x\sqrt{2\pi\sigma^2}}
e^{-\frac{\left(\ln x-\mu\right)^2}{2\sigma^2}}

with :math:x \geq 0.
(more...)


        def LogNormal(name, mean, std):
r"""
Create a continuous random variable with a log-normal distribution.

The density of the log-normal distribution is given by

.. math::
f(x) := \frac{1}{x\sqrt{2\pi\sigma^2}}
e^{-\frac{\left(\ln x-\mu\right)^2}{2\sigma^2}}

with :math:x \geq 0.

Parameters
==========

mu : Real number, the log-scale
sigma : Real number, :math:\sigma^2 > 0 a shape

Returns
=======

A RandomSymbol.

Examples
========

>>> from sympy.stats import LogNormal, density
>>> from sympy import Symbol, simplify, pprint

>>> mu = Symbol("mu", real=True)
>>> sigma = Symbol("sigma", positive=True)
>>> z = Symbol("z")

>>> X = LogNormal("x", mu, sigma)

>>> D = density(X)(z)
>>> pprint(D, use_unicode=False)
2
-(-mu + log(z))
-----------------
2
___      2*sigma
\/ 2 *e
------------------------
____
2*\/ pi *sigma*z

>>> X = LogNormal('x', 0, 1) # Mean 0, standard deviation 1

>>> density(X)(z)
sqrt(2)*exp(-log(z)**2/2)/(2*sqrt(pi)*z)

References
==========

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

return rv(name, LogNormalDistribution, (mean, std))


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,

def test_lognormal():
mean = Symbol('mu', real=True, bounded=True)
std = Symbol('sigma', positive=True, real=True, bounded=True)
X = LogNormal('x', mean, std)
# The sympy integrator can't do this too well

    # Test sampling: Only e^mean in sample std of 0
for i in range(3):
X = LogNormal('x', i, 0)
assert S(sample(X)) == N(exp(i))
# The sympy integrator can't do this too well

    sigma = Symbol("sigma", positive=True)

X = LogNormal('x', mu, sigma)
assert density(X)(x) == (sqrt(2)*exp(-(-mu + log(x))**2
/(2*sigma**2))/(2*x*sqrt(pi)*sigma))