You can use this page to check any of your computations regarding expected value, variance, and standard deviation of a continuous random variable. The default information below is for the a normal distribution. For any other problem, you'll need to adjust the probability density function, and the bounds of your integrals.

<sagecell>

  1. Define the variables in the problem

var('a,b,x')

  1. State your pdf, the bounds of your integral, and any assumptions you may need to make.

f(x)=1/(b*sqrt(2*pi))*exp(-(x-a)^2/(2*b^2)) leftbound=-infinity rightbound=infinity assume(b>0)

  1. The following integral should equal 1, otherwise it's not a pdf.

pdfcheck=integrate(f(x),(x,leftbound,rightbound)).simplify()

  1. Compute the expected value

Ex=integrate(x*f(x),(x,leftbound,rightbound)).simplify()

  1. Compute the variance

Varx=integrate((x-Ex)^2*f(x),(x,leftbound,rightbound)).simplify()

  1. Now show all the computations in a nice pretty table.

table([ ["pdf = f(x)",f(x)], ["Area Under Curve",pdfcheck], ["Expected Value",Ex], ["Variance",Varx], ["Standard Deviation",sqrt(Varx).simplify()] ])</sagecell>

If you have a discrete random variable, then the code below will check your computations.

<sagecell>

  1. List your outcomes and their respective probabilities.

outcomes = [0 , 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] probability = [1/36, 2/36, 3/36, 4/36, 5/36, 6/36, 5/36, 4/36, 3/36, 2/36, 1/36]

  1. Perform the computations

var('k') pdfcheck=sum(probability) Ex=sum([outcomes[k] * probability[k] for k in [0..(len(probability)-1)]]) Varx=sum([(outcomes[k]-Ex)^2 *probability[k] for k in [0..(len(probability)-1)]])

  1. Now show all the computations in a nice pretty table.

table([ ["Sum of probabilties",pdfcheck], ["Expected Value",Ex], ["Variance",Varx], ["Standard Deviation",sqrt(Varx).simplify()] ])</sagecell>