sympy.stats.Rayleigh() in Python

sympy.stats.Rayleigh() in Python

The Rayleigh distribution is a continuous probability distribution used mainly in the field of physics and engineering. It's often used to model the magnitude of a 2D random vector whose coordinates are independent and identically distributed Gaussian random variables.

sympy.stats provides the Rayleigh class to represent and manipulate the Rayleigh distribution.

Here's a simple demonstration of the Rayleigh distribution in sympy.stats:

  • Defining a Rayleigh distributed random variable:
from sympy.stats import Rayleigh, density from sympy import Symbol, pprint sigma = Symbol("sigma", positive=True) # scale parameter z = Rayleigh("z", sigma) # Define a Rayleigh random variable 
  • Getting the probability density function (PDF):
density_z = density(z) pprint(density_z, use_unicode=True) 
  • Computing specific values:

For instance, if you want to compute the value of the density function at a specific point x:

x = Symbol("x") density_val = density_z.doit().subs(x, 1) print(density_val) 
  • Other statistics:

You can also compute the mean, variance, and other statistics:

from sympy.stats import E, variance mean = E(z) var = variance(z) print("Mean:", mean) print("Variance:", var) 

Remember that for the Rayleigh distribution:

  • Mean=σπ/2
  • Variance=(2−π/2)σ2

Ensure you have SymPy installed to run the above code:

pip install sympy 

You can then use the provided examples as a foundation to explore more functionalities related to the Rayleigh distribution in SymPy.


More Tags

formats jquery-cookie prometheus-alertmanager exists quaternions ng-modal audio-recording rx-java zlib iot

More Programming Guides

Other Guides

More Programming Examples