# Using Mathematica to derive the PDF of the normal distribution

I am trying to use Mathematica, in this case in a well known and rather simple list of equations, but I get stuck whit Mathematica. Since I am just starting to use Mathematica for mathematical purposes, I am aware that this might be to simple. However, I would like to get a good demonstration of how to proceed.

Here is what I have done so far.

D[f[x], x]

D[f, f] == -k (x - μ) \[DifferentialD]x

D[f, f] == -k (x - μ) \[DifferentialD]x
∫\[DifferentialD]f/f == ∫(x - μ) \[DifferentialD]x

Log[f] == x^2/2 - x μ (
Log[f] == x^2/2 - x μ + Log[c]
Solve[Log[f] == x^2/2 - x μ + Log[c], f]


This is where I get stuck, and if you look at the page that I have linked, you see that this is not the answer given there. Could someone who is capable provide a step by step solution of how to derive this. I think it would be helpful for many people just starting to use Mathematica for this purpose. I also think that having an example to look at would make it easier to find your own solutions later on in other cases.

• first of all, I think there's an error in your second line: should be "1/f [DifferentialD]f == -k (x - [Mu]) [DifferentialD]x" according to the page.
– Phab
Apr 8 '14 at 10:01

Try this ... I changed your code a bit:

eqn1 = f'[x] == -k (x - μ) f[x]

eqn2 = 1/f ⅆf == -k (x - μ) ⅆx

∫1/
f[x] ⅆf[
x] == ∫-k (x - μ) ⅆx

Exp[Log[f[x]]] == Exp[k (-(x^2/2) + x μ)]
(* you'll see it's the same as *)
DSolve[eqn1, f[x], x]


Gives for me:

Out1: $f'(x)=-k f(x) (x-\mu )$

Out2: $\frac{df}{f}=-k (x-\mu ) dx$

Out3: $\log (f(x))=k \left(\mu x-\frac{x^2}{2}\right)$

Out4: $f(x)=e^{k \left(\mu x-\frac{x^2}{2}\right)}$

Out5: $\left\{\left\{f(x)\to c_1 e^{k \left(\mu x-\frac{x^2}{2}\right)}\right\}\right\}$

• Why are you 1/f. I understand that Df with regards to f equals 1. Which is 1/1 but do not get it in this case. Apr 8 '14 at 13:36
• @ALEXANDER It's just like in the link you gave: Multiply the first equation by dx and divide it by f (or f[x]) ... lefthandside and righthandside and you'll get the second equation. It has nothing to do with Integration so far. But now, if you integrate both sides you'll have to integrate 1/f*df on the lhs thats [Integral]1/f[x] [DifferentialD]f[x]
– Phab
Apr 8 '14 at 13:56

Here is a stepwise approach:

sol = First@DSolve[f'[x] == -k (x - μ) f[x], f[x], x];


yields:

{f[x] -> E^(k (-(x^2/2) + x μ)) C}


In this case to get to the normal PDF:

c1 = First@
Solve[Integrate[f[x] /. sol, {x, -Infinity, Infinity},
GenerateConditions -> False] == 1, C]


yields:

{C -> (E^(-((k μ^2)/2)) Sqrt[k])/Sqrt[2 π]}


Note the constant is product of usual normalization constant and constant term of polynomial in exponent. To get to desired form:

exp = (f[x] /. sol) /. c1
FullSimplify[
ReplacePart[
exp, {1, 2} -> Factor[Collect[Together[exp[[1, 2]]], k]]] /.
k -> 1/σ^2,
Assumptions -> (Element[σ, Reals] && σ > 0)]


yields:

E^(-((x - μ)^2/(2 σ^2)))/(Sqrt[2 π] σ)


The first step substitutes solutions and constants. The second step involves factorizing the polynomial after addding fraction and taking out constant then subsitution of k for reciprocal of variance.