Given probability density function, ¶
,
The mean value of is estimated analytically:¶
the median¶
median: ,
the second moment¶
second moment:
the variance is the second moment less the squared mean value¶
from pylab import *
import numpy as npdef p(x,b):
return 2*x/(b**2)
b = 2
x = linspace(0,b,200)
y = p(x,b) plot(x,y)
xlabel('$x$')
ylabel('$p(x)$')
# approximate using the numerical integration
print(trapz(y*x,x))
print(2.*b/3)1.3333501679250523
1.3333333333333333
print(trapz(y*x**2,x))
print(b**2/18)2.000050503775157
0.2222222222222222
import sympysympy.var('x,b,p,m')
p = 2*x/b**2
print (p)2*x/b**2
sympy.integrate(p*x,(x,0,b))Loading...
sympy.integrate(p*x**2,(x,0,b))Loading...
sympy.integrate(p,(x,0,m))Loading...
sympy.solve(m**2/b**2 - 0.5,m)[-0.707106781186548*b, 0.707106781186548*b]