3
$\begingroup$

How can I define a distribution and get the expectation in Mathematica for $a=a_H$ with probability $\lambda$ and $a=a_L$ with probability $1−\lambda$, where $\lambda\in(0,1)$?

$\endgroup$

2 Answers 2

9
$\begingroup$

There are many ways. Here's one:

dist = TransformedDistribution[x aH + (1 - x) aL, x \[Distributed] BernoulliDistribution[λ]]
Mean[dist]
(* aL+aH λ-aL λ *)
$\endgroup$
7
$\begingroup$

As JimB notes, there are many ways. Here's another:

dist = EmpiricalDistribution[{\[Lambda], 1 - \[Lambda]} -> {aH, aL}];
Mean[dist]
(* aL (1 - \[Lambda]) + aH \[Lambda] *)
$\endgroup$

Your Answer

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

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