# Plotting three related distributions on the same axis

The following solution to this problem was found by @Wolfies:

(E^(-((-2 z + \[Mu]1 + \[Mu]2)^2/(2 (\[Sigma]1^2 + \[Sigma]2^2)))) Sqrt[2/\[Pi]] (-1 + Erf[((z - \[Mu]2) \[Sigma]1^2 + (-z + \[Mu]1) \[Sigma]2^2)/(Sqrt[2] \[Sigma]1 \[Sigma]2 Sqrt[\[Sigma]1^2 + [Sigma]2^2])]))/(-1 + Erf[(\[Mu]1 - \[Mu]2)/(Sqrt[2] Sqrt[\[Sigma]1^2 + \[Sigma]2^2])] Sqrt[\[Sigma]1^2 +[Sigma]2^2])

Note that $$Z = \frac{X + Y}{2}$$ where $$X$$ and $$Y$$ are independent random variables that both follow the Normal distribution, with possibly different means and variances (denoted by subscripts $$1$$ for $$X$$ and $$2$$ for $$Y$$).

I am now trying to plot the two normal distributions together with the random variable $$Z$$ described by Wolfies' solution, on the same axis. What gets me is that $$Z$$ does not have the size I would expect relative the two Normal distributions; the distribution for $$Z$$ is too large.

Below is a plot of $$Z$$ and $$X$$ on two different axis, and the size problem is clear:

• You missed a set of parentheses in translating @wolfies answer. You should be using: (E^(-((-2 z + \[Mu]1 + \[Mu]2)^2/(2 (\[Sigma]1^2 + \[Sigma]2^2)))) \ Sqrt[2/\[Pi]] (-1 + Erf[((z - \[Mu]2) \[Sigma]1^2 + (-z + \[Mu]1) \[Sigma]2^2)/(Sqrt[ 2] \[Sigma]1 \[Sigma]2 Sqrt[\[Sigma]1^2 + \ \[Sigma]2^2])]))/((-1 + Erf[(\[Mu]1 - \[Mu]2)/(Sqrt[ 2] Sqrt[\[Sigma]1^2 + \[Sigma]2^2])]) Sqrt[\[Sigma]1^2 + \ \[Sigma]2^2]).
– JimB
Apr 22, 2019 at 21:59
• Oh! You are right. Now I get something that makes much more sense. Apr 22, 2019 at 22:25

After correcting the density you should get something like the following:

Manipulate[Plot[{PDF[NormalDistribution[μ1, σ1], z],
PDF[NormalDistribution[μ2, σ2], z],
(E^(-((-2 z + μ1 + μ2)^2/(2 (σ1^2 + σ2^2)))) Sqrt[2/π]*
(-1 + Erf[((z - μ2) σ1^2 + (-z + μ1) σ2^2)/(Sqrt[2] σ1 σ2 Sqrt[σ1^2 + σ2^2])]))
((-1 + Erf[(μ1 - μ2)/(Sqrt[2] Sqrt[σ1^2 + σ2^2])]) Sqrt[σ1^2 + σ2^2])}, {z, -10, 10},
PlotLegends -> {"\!$$\*SubscriptBox[\(X$$, $$1$$]\)",
"\!$$\*SubscriptBox[\(X$$, $$2$$]\)",
"(\!$$\*SubscriptBox[\(X$$, $$1$$]\)+\!$$\*SubscriptBox[\(X$$, \
$$2$$]\))/2 given \!$$\*SubscriptBox[\(X$$, $$1$$]\) < \
\!$$\*SubscriptBox[\(X$$, $$2$$]\)"},
PlotRange -> All],
{{σ1, 1, "\!$$\*SubscriptBox[\(σ$$, $$1$$]\)"}, 0.1, 5, Appearance -> "Labeled"},
{{σ2, 1, "\!$$\*SubscriptBox[\(σ$$, $$2$$]\)"}, 0.1, 5, Appearance -> "Labeled"},
{{μ1, 0, "\!$$\*SubscriptBox[\(μ$$, $$1$$]\)"}, 0, 5, Appearance -> "Labeled"},
{{μ2, 0, "\!$$\*SubscriptBox[\(μ$$, $$2$$]\)"}, 0, 5, Appearance -> "Labeled"},
TrackedSymbols :> {μ1, μ2, σ1, σ2}]