Height and Area of the Bell Curve — medium Probability Distributions problem | Incognition
Height and Area of the Bell Curve
20 pts · 20 coins
Probability DistributionsMedium
Height and Area of the Bell Curve
A mill fills bags of flour, and the fill weight X (in grams) is modelled as normal: X∼N(μ,σ2). For any weight x, quality control asks two different questions.
How dense is the curve at x? That is the PDF value f(x), the height of the bell curve at x:
f(x)=σ2π1e−2σ2(x−μ)2
What fraction of bags weigh at most x? That is the CDF value F(x)=P(X≤x), the area under the curve to the left of x.
The normal CDF has no formula built only from arithmetic and powers. Python's standard library does ship the error functionmath.erf, though, and the CDF of the standard normal Z∼N(0,1) can be written with it:
Φ(z)=21[1+erf(2z)]
Task: write normal_pdf_cdf(x, mu, sigma) that returns the tuple (f(x), F(x)) for X∼N(μ,σ2), each rounded to 4 decimal places.
sigma is the standard deviation σ (always greater than 0), not the variance.
Φ above is the CDF of N(0,1) only; your function must work for any μ and σ.
Use only the standard library.
For example, a mill aiming at μ=512 g with σ=15 g wants to know how often a bag comes in at or under the 500 g printed on the label: that is the second number returned by normal_pdf_cdf(500, 512, 15).