Normal Distribution

The probability density of normal distribution is:

N(μ,σ2)=1σ2πe(xμ)22σ2\huge N(\mu, \sigma^2) = \frac{1}{\sigma \sqrt{2\pi}}e^{- \frac{(x-\mu)^2}{2\sigma^2}}

Here,

  • μ\mu is the mean (or expectation) of the distribution. It is also equal to median and mode of the distribution.

  • σ2\sigma^2 is the variance.

  • σ\sigma is the standard deviation.

If μ=0\mu = 0 and σ=1\sigma =1 , then the normal distribution is known as standard normal distribution: ϕ(x)=ex222π\large \phi(x) = \frac{e^{-\frac{x^2}{2}}}{\sqrt{2\pi}}

Every normal distribution can be represented as standard normal distribution:

N(μ,σ2)=1σϕ(xμσ)\large N(\mu, \sigma^2) = \frac{1}{\sigma}\phi(\frac{x-\mu}{\sigma})

Consider a real-valued random variable, XX. The cumulative distribution function of XX (or just the distribution function of XX) evaluated at xx is the probability that XX will take a value less than or equal to xx:

FX(x)=P(Xx)F_X(x) = P(X\leq x)

Also,

P(aXb)=P(a<X<b)=FX(b)FX(a)P(a \leq X \leq b) = P(a < X < b) = F_X(b) - F_X(a)

The cumulative distribution function for a function with normal distribution is:

Φ(x)=12(1+erf(xμσ2))\huge \Phi(x) = \frac{1}{2}(1+\text{erf}(\frac{x-\mu}{\sigma\sqrt2}))

phi = lambda x: 0.5 * (1 + math.erf((x - mean)/(std * (2 ** 0.5))))

Where erf\text{erf} is the function:

erf(z)=2πf02ex2dx\large \text{erf}(z) = \frac{2}{\sqrt\pi}f_0^2 e^{-x^2} dx

Task In a certain plant, the time taken to assemble a car is a random variable, XX, having a normal distribution with a mean of hours and a standard deviation of 22 hours. What is the probability that a car can be assembled at this plant in:

  1. Less than 19.519.5 hours?

  2. Between 2020 and 2222 hours?

import math
mean, std = 20, 2
cdf = lambda x: 0.5 * (1 + math.erf((x - mean) / (std * (2 ** 0.5))))

# Less than 19.5
print('{:.3f}'.format(cdf(19.5)))
# Between 20 and 22
print('{:.3f}'.format(cdf(22) - cdf(20)))

Task The final grades for a Physics exam taken by a large group of students have a mean of μ=70\mu = 70 and a standard deviation of σ=10\sigma = 10. If we can approximate the distribution of these grades by a normal distribution, what percentage of the students:

  1. Scored higher than 8080 (i.e., have a grade>80\text{grade}>80)?

  2. Passed the test (i.e., have a grade60\text{grade}\geq60)?

  3. Failed the test (i.e., have a grade<60\text{grade}<60)?

import math

def arg_erf(x, u, o):
    return (x-u)/(o * math.sqrt(2))

def F(x, arg_x):
    return 0.5 * ( 1 + math.erf(arg_x) )

u, o = input().split() # u = 70, o = 10
u, o = float(u), float(o)

a = float(input())   # a = 80
b = float(input())   # b = 60

arg_a = arg_erf(a, u, o)
arg_b = arg_erf(b, u, o)

first_ans = (1 - F(a, arg_a))
second_ans = (1 - F(b, arg_b))
third_ans = F(b, arg_b)

print(round(first_ans*100.0, 2))
print(round(second_ans*100.0, 2))
print(round(third_ans*100.0, 2))

Last updated