---
title: "Expectation and Variance by Integration"
description: "The mean and variance of a continuous variable are integrals against the density, and the same linearity rules from the discrete case still hold."
canonical: https://lightmysky.com/learn/mathematics/expectation-and-variance-by-integration-mt_kRSaKgp3bs
source: https://lightmysky.com/learn/mathematics/expectation-and-variance-by-integration-mt_kRSaKgp3bs.md
retrieved: 2026-11-12
---

> **Agent view.** This is the Markdown twin of the page, for tools and assistants.
> When to use this site, and the call that answers each job: https://lightmysky.com/agent-instructions.md
> API description (OpenAPI 3.1): https://lightmysky.com/openapi.json · Authentication: https://lightmysky.com/auth.md
> Pricing: https://lightmysky.com/pricing.md · Catalog: https://lightmysky.com/llms.txt · Full catalog: https://lightmysky.com/llms-full.txt
> Every machine-readable file on this domain: https://lightmysky.com/.well-known/ai-catalog.json
> Ask for Markdown with `Accept: text/markdown`, a `.md` address, or `?mode=agent`.

# Expectation and Variance by Integration

The mean and variance of a continuous variable are integrals against the density, and the same linearity rules from the discrete case still hold.

Subject: Mathematics · Area: Probability · Ages 19 to 20
Page: https://lightmysky.com/learn/mathematics/expectation-and-variance-by-integration-mt_kRSaKgp3bs

## Ready when they can

- Compute the mean and variance of a continuous variable by integration
- Use linearity of expectation without assuming independence
- Find the expected value of a function of a random variable

## Lesson: Means and spreads by integration

For density f, E[X] = ∫ x f(x) dx over its full range, provided ∫ |x| f(x) dx is finite. This replaces a probability-weighted sum with an integral. For integers n ≥ 0, an antiderivative of x^n is x^(n+1)/(n+1). Integrate polynomials term by term; evaluate at the upper endpoint and subtract the lower value. For X uniform on [0, 8], E[X] = ∫₀⁸ x/8 dx = [x²/16]₀⁸ = 4.

*(drawing: A uniform density on [0, 8] balances at the midpoint, 4. The dot marks its mean, not a probability.)*

**Example.** Find the second moment by integrating x² f(x). For the same uniform variable, E[X²] = ∫₀⁸ x²/8 dx = 64/3. Variance is E[(X - E[X])²] = E[X²] - (E[X])², so it is 64/3 - 16 = 16/3. It cannot be negative because squared deviations are nonnegative.

For finite expectations, E[aX + bY + c] = aE[X] + bE[Y] + c, even when X and Y are dependent. More generally, E[g(X)] = ∫ g(x) f(x) dx when ∫ |g(x)| f(x) dx is finite. A nonlinear g usually needs this integral: E[g(X)] need not equal g(E[X]).

Integration by parts uses ∫ u dv = uv - ∫ v du. For f(x) = λe^(-λx), x ≥ 0, λ > 0, choose dv = f(x)dx and v = -e^(-λx). Taking u = x gives E[X] = 1/λ; taking u = x² gives E[X²] = (2/λ)E[X] = 2/λ². Thus Var(X) = 1/λ². Evaluate each integral from 0 to a finite bound, then let that bound tend to ∞. The boundary terms vanish because exponential decay beats these powers.

To check a reported variance, identify what was calculated. E[X²] is the second moment, not yet the variance. With finite second moment, complete Var(X) = E[X²] - (E[X])². Subtract the squared mean, not the mean. Only when the mean is zero do variance and second moment agree.

**Recap.** Integrate x against the density for the mean, then subtract the squared mean from E[X squared] for the variance.

*Lesson and questions written for this dataset using standard definitions of continuous expectation and variance.*

## Practice

13 questions on this page, each with its working shown.

## Needs first

- [Continuous Random Variables and Density Functions](https://lightmysky.com/learn/mathematics/continuous-random-variables-and-density-functions-mt_jlf4zDTeNm)
- [Expected Value and Variance of a Discrete Random Variable](https://lightmysky.com/learn/mathematics/expected-value-and-variance-of-a-discrete-random-variable-mt_PFdo0Nm3FP)

## Optional connections

- [Improper Integrals and Their Convergence](https://lightmysky.com/learn/mathematics/improper-integrals-and-their-convergence-mt_gvtZPFRA6Z)

## Opens up

- [Martingales and Optional Stopping](https://lightmysky.com/learn/mathematics/martingales-and-optional-stopping-mt_198uXX3jRJ)
- [Normalisation and Expectation Values](https://lightmysky.com/learn/science/normalisation-and-expectation-values-mt_6Y3DZ8P1qm)
- [Joint Distributions, Covariance and Independence](https://lightmysky.com/learn/mathematics/joint-distributions-covariance-and-independence-mt_YyTFTAqhSF)
