6
$\begingroup$

Let's consider two balanced dice. I am modelling each of them using

d1 = ProbabilityDistribution[1/6, {x, 1, 6, 1}]
d2 = ProbabilityDistribution[1/6, {x, 1, 6, 1}]

Call $x$ the result of the first dice and $y$ the result of the second dice after they are thrown, let $z=2x+y$. How can I make a probability distribution corresponding to $z$ using $d_1$ and $d_2$ ? I tried adding them

d3=2*d1+d2

but this didn't work.

$\endgroup$
1
  • 2
    $\begingroup$ I think you want TransformedDistribution. $\endgroup$
    – Eric Brown
    Commented Nov 26, 2015 at 18:57

1 Answer 1

11
$\begingroup$

As Eric Brown suggested you should use TransformedDistribution[]. Also I'd suggest using built in distributions if possible, here I mean DiscreteUniformDistribution[].

tf = TransformedDistribution[
  A + B, {A \[Distributed] DiscreteUniformDistribution[{1, 6}], 
   B \[Distributed] DiscreteUniformDistribution[{1, 6}]}]
PDF[tf, x]
DiscretePlot[PDF[tf, x], {x, 2, 12}]

enter image description here

$\endgroup$
1
  • 3
    $\begingroup$ Just as a tiny comment: it would be better to first evaluate: ee = PDF[tf, x], and then DiscretePlot[ee {x, 2, 12}] . By contrast, DiscretePlot[PDF[tf, x], {x, 2, 12}] might take about 100 times longer to plot, because it tells Mma to calculate PDF[t,x] at each value of x (rather than just solving it once). $\endgroup$
    – wolfies
    Commented Nov 28, 2015 at 17:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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