Variance

## Description

The Varience of a probability density function is

(1)\begin{align} Var(X)=E((x-E(X))^2) = \int_{-\infty}^{\infty} (x-E(X))^2 f(x) dx. \end{align}

The Sage cell below calculates the Variance of the exponential distribution when $\lambda=4$.

## Sage Cell

#### Code

```
l=4
f(X)=l*exp(-l*x)
E(X)=integral(x*f(X),x,0,+infinity)
Var(X)=integral(( x-E(X) )^2 * f(X), x, 0, infinity )
Var(X)
```

## Options

#### Expected Value for Discrete Distributions

The Expected Value of a discrete probability distribution function is

(2)\begin{align} E(X) = \sum_{x=0}^{\infty} x f(x) dx. \end{align}

The Sage cell below calculates the expected value of the poisson distribution when $\lambda=15$.

#### Code

```
lamb = 15
var('k')
f(k)=exp( -lamb) * (( lamb^k ) / ( factorial(k)))
E(k)=sum(k * f(k) , k, 0, infinity)
Var(k)=sum((k-E(k))^2*f(k), k, 0, infinity)
Var(k)
```

## Tags

Primary Tags: Probability

Secondary Tags: Random Variables: Variance, Continuous Distributions, Discrete Distributions

## Related Cells

None

## Attribute

Permalink:

Author:

Date: 16 Oct 2018 18:03

Submitted by: James A Phillips