Example.
Consider the following probabalistic problem.
The distribution of IQ scores can be modeled by a normal distribution with mean 95 and standard deviation 10. Estimate the fraction of population with IQ between 100 and 110.
sage: mu=95
sage: s=10
sage: var('x')
sage: p(x)=(1/s/sqrt(2*pi))*exp(-(x-mu)^2 /2/s^2)
sage: integral(p(x),x,100,110)
sage: n(_)
0.241730337457129
Example. Consider the following probabalistic problem.
The probability density function of a certain random variable \( X \) is \( p(x) =2k\,e^{-kx} \) The range of \( X \) is from 0 to 4.
What is the value of \( k \) ?
sage: var('x')
sage: var('k')
sage: p(x)=2*k*exp(-k*x)
sage: integral(p(x),x,0,4)
-2*k*(e^(-4*k)/k - 1/k)
# if you want to find antiderivative first, type:
sage: p.integral(x)
x |--> -2*e^(-k*x)
sage: solve(-2*k*(e^(-4*k)/k - 1/k) ==1,k)
[k == log(I*2^(1/4)), k == log(-2^(1/4)), k == log(-I*2^(1/4)), k == 1/4*log(2)]
Another way:
sage: A=integral(p(x),x,0,4)
sage: A.full_simplify()
2*(e^(4*k) - 1)*e^(-4*k)
sage: k = 1/4*log(2)
Find the mean.
sage: integral(t*p(t),t,0,4)
-2*k*((4*k + 1)*e^(-4*k)/k^2 - 1/k^2)
sage: mu(k)=-2*k*((4*k + 1)*e^(-4*k)/k^2 - 1/k^2)
sage: mu(1/4*log(2))
sage: n(_)
1.77078016355585
Derive the formula for cumulative distribution function \( P(x) \)
sage: var('t')
sage: PP(x)=integral(p(t),t,0,x)
sage: PP(x)
-2*k*(e^(-4*k)/k - 1/k)
What is the median ?
sage: solve(PP(t)==1/2,t)
[t == log(4/3)/k]
sage: n(log(4/3)*4/log(2))
1.66014999711537
# another way:
sage: PPP(x,k)=-2*k*(e^(-k*x)/k - 1/k)
sage: PPP(x,1/4*log(2))
-2*(e^(-1/4*x*log(2))/log(2) - 1/log(2))*log(2)
sage: find_root(-2*(e^(-1/4*x*log(2))/log(2) - 1/log(2))*log(2) ==1/2,0,4)
1.6601499971153482
sage: f = PP(x)==.5
sage: f.roots(x)
sage: n(_)
[(log(4/3)/k, 1)]
Estimate of the fraction of the population between 2 and 4.
sage: pp(k)=integral(p(t),t,2,4)
sage: pp(1/4*log(2))
sage: n(_)
0.414213562373095
Enter search terms or a module, class or function name.