# Deriving a Rayleigh distribution

When I tried to find this Rayleigh distribution Mathematica couldn't come with an answer:

PDF[TransformedDistribution[
Sqrt[x1^2 + x2^2], {x1 \[Distributed]
NormalDistribution[μ1, σ],
x2 \[Distributed] NormalDistribution[μ2, σ]},
Assumptions -> μ1 == μ2 == 0], r]


I want to derive the Rayleigh distribution in parametric form. Mathematica could solve this for N~[0,1] and the answer is Rayleigh[1], but for N~[0,k] it has no answer.

• Why not to use the RayleighDistribution? – m0nhawk Apr 11 '15 at 15:37
• Well, computer algebra systems can't solve every problem you throw at them. Questions like "why can't Mathematica solve it" are not a very good fit here usually. If the question is "how to compute this", then the anwser is what m0nhawk said. – Szabolcs Apr 11 '15 at 15:38
• @Szabolcs My shrink used to answer all my questions like that. – Dr. belisarius Apr 11 '15 at 15:42
• @OP What is your question? – shrx Apr 11 '15 at 18:11
• My Question is how Can I Solve this using Mathematica Mathematica Solve this Problem for Normal Distribution ~ [0,1] and returns RayleighDistribution[1] but for Normal Distribution~[0,k] has no Answer!!! – Hamid reza Apr 12 '15 at 6:05

You can use BinormalDistribution instead of two univariate normal distributions:

TransformedDistribution[Sqrt[x1^2 + x2^2],
{x1, x2} ~Distributed~ BinormalDistribution[{0, 0}, {σ, σ}, 0]]
(* RayleighDistribution[σ] *)

TransformedDistribution[Sqrt[x1^2 + x2^2],
{x1, x2} ~Distributed~ BinormalDistribution[{m, m}, {σ, σ}, 0]]
(* RiceDistribution[Sqrt[2] m, σ] *)

TransformedDistribution[Sqrt[x1^2 + x2^2],
{x1, x2 } ~Distributed~ BinormalDistribution[{m1, m2}, {σ1, σ2}, 0]]
(* BeckmannDistribution[m1, m2, σ1, σ2, 0] *)

• Thanks a lot @Simon! This Solution is very better!!! – Hamid reza Apr 12 '15 at 12:50

You can get the desired result in two steps:

d1 = TransformedDistribution[x1^2 + x2^2,
{Distributed[x1, NormalDistribution[0, σ]],
Distributed[x2, NormalDistribution[0, σ]]}]
(* ExponentialDistribution[1/(2 σ^2)] *)

d2 = TransformedDistribution[Sqrt[z], Distributed[z, d1]]
(* RayleighDistribution[σ] *)

PDF[d2,r]


$\begin{cases} \frac{r e^{-\frac{r^2}{2 \sigma ^2}}}{\sigma ^2} & r>0 \\ 0 & \text{True} \end{cases}$

You can also fold the two steps into a single step:

With[{d1 =TransformedDistribution[x1^2 + x2^2,
{Distributed[x1, NormalDistribution[0, σ]],
Distributed[x2, NormalDistribution[0, σ]]}]},
TransformedDistribution[Sqrt[z], Distributed[z, d1]]]
(*  RayleighDistribution[σ] *)


Update: The results above are obtained in Version 9.0.1.0. As noted by @m0nhawk in the comments, in version 10, TransformedDistribution[Sqrt[z], Distributed[z, d1]] gives the result

WeibullDistribution[2, Sqrt[2] σ]


which is equivalent to RayleighDistribution[σ]:

PDF[WeibullDistribution[2, Sqrt[2] σ], r] == PDF[d2, r]
(* True *)

• I'm getting WeibullDistribution[2, Sqrt[2]/Sqrt[1/\[Sigma]^2]] for d2. Mathematica 10.1. – m0nhawk Apr 12 '15 at 9:51
• @m0nhawk, interesting. I am using v9.0.1.0. Btw, WeibullDistribution[2, Sqrt[2] σ] is equivalent to RayleighDistribution[σ]. – kglr Apr 12 '15 at 9:57
• Yeah, I know, I just provide a usefull information that other Mathematica version have other output. – m0nhawk Apr 12 '15 at 9:58
• @m0nhawk, thank you. Updated with a note on the version 10 output. – kglr Apr 12 '15 at 10:04
• Mathematica Should do this Automatically but didn't! is This a Bug? – Hamid reza Apr 12 '15 at 10:33