I am trying to use Mathematica to obtain the probability distribution of $\frac{1}{2}(A + B)$ where $A$ and $B$ are independent random variables each distributed according to the uniform distribution, with lower and upper bounds of $L$ and $H$ respectively.

I suspect the distribution is triangular with lower and upper bounds of $L$ and $H$ respectively and mode equal to $\frac{1}{2}(A + B)$. However, I am having difficulty using TransformedDistribution to show that.

My code is:

\[ScriptCapitalD] = TransformedDistribution[1/2 (A + B), {B \[Distributed] UniformDistribution[{L, H}], A \[Distributed] UniformDistribution[{L, H}]}]
  • $\begingroup$ That was a typo. But I am still not getting what I expect. $\endgroup$ – user120911 Mar 23 at 19:16
  • $\begingroup$ Did you try PDF[\[ScriptCapitalD], y]? $\endgroup$ – JimB Mar 23 at 19:18
  • 2
    $\begingroup$ Why not check the PDFs? Simplify[PDF[TransformedDistribution[(a + b)/2, {a, b} \[Distributed] UniformDistribution[{{l, h}, {l, h}}]], t] == PDF[TriangularDistribution[{l, h}], t], l < t < h] $\endgroup$ – J. M. is away Mar 23 at 20:04
  • 1
    $\begingroup$ I think I have found a bug! Try the following two expressions. The only difference is that I use U in one and H in the other for the upper limit. Simplify[PDF[TransformedDistribution[(A + B)/2, {A, B} \[Distributed] UniformDistribution[{{L, U}, {L, U}}]], t] == PDF[TriangularDistribution[{L, U}], t], L < t < U] and Simplify[PDF[TransformedDistribution[(A + B)/2, {A, B} \[Distributed] UniformDistribution[{{L, H}, {L, H}}]], t] == PDF[TriangularDistribution[{L, H}], t], L < t < H] $\endgroup$ – user120911 Mar 23 at 20:35
  • 1
    $\begingroup$ @user120911 It does look like a bug to me. I think you should report it to WRI. $\endgroup$ – Silvia Mar 24 at 19:35

You get what you expect if you do it it in two steps

\[ScriptCapitalD] = 
  x \[Distributed] TransformedDistribution[(A + B), {
     B \[Distributed] UniformDistribution[{L, H}],
     A \[Distributed] UniformDistribution[{L, H}]}]]

(* TriangularDistribution[{L, H}] *)
  • $\begingroup$ That is very nice! $\endgroup$ – user120911 Mar 23 at 20:24

(((-30 + z)Sign[-30 + z])/2 - (-20 + z) Sign[-20 + z] + ((-10 + z)*Sign[-10 + z])/2)/100

For plotting, assign values to L and H:

L = 10; H = 30;
Plot[Evaluate@PDF[\[ScriptCapitalD]][x], {x, 10, 30}]

enter image description here

pdF[l_, h_] := Module[{L = l, H = h}, Evaluate[PDF[\[ScriptCapitalD]]]]
Plot[Evaluate @ Flatten@Table[pdF[l, h][x], {l, {0, 5}}, {h, {10, 15}}], {x, 0, 15},
  PlotRange -> All, 
 PlotLegends -> (Flatten @ Table[ToString@{l, h}, {l, {0, 5}}, {h, {10, 15}}])]

enter image description here

  • $\begingroup$ That confirms my intution, but can you get Mathematica to output the PDF for the triangular distribution? That is what I am having trouble doing. $\endgroup$ – user120911 Mar 23 at 19:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.