Jupyter Snippet CB2nd 04_stats

Jupyter Snippet CB2nd 04_stats

15.4. Computing exact probabilities and manipulating random variables

from sympy import *
from sympy.stats import *
init_printing()
X, Y = Die('X', 6), Die('Y', 6)
P(Eq(X, 3))

png

P(X > 3)

png

P(X > Y)

png

P(X + Y > 6, X < 5)

png

Z = Normal('Z', 0, 1)  # Gaussian variable
P(Z > pi)

png

E(Z**2), variance(Z**2)

png

f = density(Z)
var('x')
f(x)

png

%matplotlib inline
plot(f(x), (x, -6, 6))

png

Eq(Integral(f(x), (x, pi, oo)),
   simplify(integrate(f(x), (x, pi, oo))))

png