Build mathematical modelsLesson 41 of 48 · 8 min

Integrate a probability density

Check a density’s total mass and calculate an expectation on its stated support.

Maths refresher: Density versus probability

Probabilities are areas under a density. A density can exceed one at a point while its total integral remains one.

∫012x dx=1,E[X]=∫01x(2x) dx=23\int_0^1 2x\,dx=1,\qquad E[X]=\int_0^1 x(2x)\,dx=\frac23
Worked example

The density reaches 2 at x=1x=1, but the probability of an interval is its area, not that endpoint height.

Maths prerequisite map ↗

A continuous probability density assigns probability through integrals over intervals. Its height is not the probability of a single point. A valid density must be nonnegative and have total mass one over its support.

See the mathematics
00.2750.550.8251.1-0.10.51.11.72.3xy
00.2750.550.8251.1-0.10.51.11.72.3xy
f(x)=2x  (0≤x≤1),∫01f(x) dx=1f(x)=2x\;(0\le x\le1),\quad\int_0^1 f(x)\,dx=1
f(x)=2x(0≤x≤1)∫01f(x) dx=1\begin{gathered}f(x)=2x\quad(0\le x\le1)\\\int_0^1 f(x)\,dx=1\end{gathered}
Starter reference. The density is zero outside [0, 1]. Probability is area: the shaded mass is one, while the height at a point is not its probability.

Use the authored density 2x2x between zero and one, and zero elsewhere. Symbolic integration checks its normalisation and calculates its mean and variance. The integration limits encode the support and must not be discarded.

An expectation weights each value by the density before integrating. The variance is the second moment minus the square of the mean. These exact answers can later benchmark numerical integration or Monte Carlo, but they describe this chosen teaching distribution rather than measured population evidence.

Does a density value of 2 necessarily make the probability model invalid?

Write a prediction (optional)

Exact calculation for an authored density

Select Run Python with the code unchanged.

Tools
About Python

Python and the course packages can load while you read. Each run starts with fresh user variables; imported modules stay loaded. Stop replaces the worker. Runtime details ↗

Ctrl+Enter or ⌘+Enter runs Python.

Compare with the worked example

Executed from the published Python during the site build. Your own run appears above. Build environment ↗

Scale for unit mass
22
Mass on [0,1]
11
Mean
23\frac{2}{3}
Variance
118\frac{1}{18}
P(X > 3/4)
716\frac{7}{16}
Worked text output
Scale for unit mass: 2
Mass on [0,1]: 1
Mean: 2/3
Variance: 1/18
P(X > 3/4): 7/16

Read the starter result

Mass on [0,1] checks that the density integrates to one. Mean and Variance describe this authored distribution. The model assigns density zero outside its support.

Edit and compare

Replace shape = x with shape = x**2. The code chooses the multiplier that makes total probability one. Select Run Python. Read Scale for unit mass, verify Mass on [0,1] and compare Mean with the first run.

Return to the editor

Scope. Nonnegativity and normalisation are mathematical checks; they do not validate an assumed distribution against real data.

Try a fresh case

How is P(a<X<b)P(a<X<b) obtained from a continuous density f?

Choose an answer
Need a hint?
Hint 1

Think of area under the curve.

Hint 2

Use the relevant interval and support.

Your notesNotes save in this browser when storage is available.