Lesson 12 of 15

Normal Distribution

The Bell Curve

XN(μ,σ2)X \sim N(\mu, \sigma^2) is the most important distribution in probability. Its PDF is:

f(x)=1σ2πexp((xμ)22σ2)f(x) = \frac{1}{\sigma\sqrt{2\pi}} \exp\left(-\frac{(x-\mu)^2}{2\sigma^2}\right)

E[X]=μ,Var(X)=σ2E[X] = \mu, \qquad \text{Var}(X) = \sigma^2

Standard Normal

ZN(0,1)Z \sim N(0, 1). Any normal can be standardized: Z=(Xμ)/σZ = (X - \mu)/\sigma.

CDF via Error Function

The CDF has no closed form in elementary functions, but Python provides it via math.erf:

Φ(x)=P(Zx)=12[1+erf(x2)]\Phi(x) = P(Z \leq x) = \frac{1}{2}\left[1 + \text{erf}\left(\frac{x}{\sqrt{2}}\right)\right]

import math

def normal_cdf(mu, sigma, x):
    return 0.5 * (1 + math.erf((x - mu) / (sigma * math.sqrt(2))))

def normal_pdf(mu, sigma, x):
    return (1 / (sigma * math.sqrt(2 * math.pi))) * math.exp(-0.5 * ((x - mu) / sigma)**2)

The 68-95-99.7 Rule

RangeProbability
μ±σ\mu \pm \sigma68.27%
μ±2σ\mu \pm 2\sigma95.45%
μ±3σ\mu \pm 3\sigma99.73%

Why It's Everywhere

The Central Limit Theorem (next lesson) guarantees that the sum of many independent random variables converges to a normal distribution, regardless of the original distribution.

Your Task

Implement normal_full(mu, sigma, x) that prints CDF(x)(x) then PDF(x)(x) of N(μ,σ2)N(\mu, \sigma^2), each rounded to 4 decimal places.

Pyodide loading...
Loading...
Click "Run" to execute your code.