Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What I would like to do is create a mixture distribution that has a specified mean by varying one parameter in the distribution. To do this I've written the following code;

dist := MixtureDistribution[{0.1,0.9}, {UniformDistribution[{39.3, 40.5}],
TruncatedDistribution[{40.5, 104}, NormalDistribution[a, 11.4]]}]

NSolve[Mean[dist] == 82.63344, a]

Which just returns a "PolynomialGCD::lrgexp" error.

What I ended up doing is putting values in using trial and error until it gave me the correct mean (so it does have a solution). Is there any way so solve this equation without resorting to trial and error?

I think the TruncatedDistribution / Mean combination is what is causing problems. When I remove the TruncatedDistribution NSolve quickly returns a solution. The following link discussed this issue;

Calculating the Mean of a Truncated Multinormal Distribution

When I replaced

 NSolve[Mean[dist] == 82.63344, a]


NSolve[NExpectation[x, x \[Distributed] dist2] == 82.63344, a]

All I got was an execution that seemed to go forever (I aborted after 10 mins).

Any advice on how to solve this equation efficiently would be greatly appreciated.

share|improve this question
FindRoot seems to work fine. FindRoot[Mean[dist] == 82.63344, {a, 1}] – Andy Ross Jan 9 '13 at 23:41
up vote 4 down vote accepted

The mean of a mixture of distributions is the mixture of their means, so simplify your life--and greatly speed up Mathematica--by precomputing the means of the mixture components separately:

d1 = Mean[UniformDistribution[{39.3, 40.5}]];
d2[a_] := Evaluate @ Mean[TruncatedDistribution[{40.5, 104}, NormalDistribution[a, 11.4]]]

A rough guess for the solution a is that it is close to the target mean. Use this as the initial value in FindRoot:

With[{target = 82.63344}, FindRoot[0.1 d1 + 0.9 d2[a] == target, {a, target}]]

$\{a\to 89.6922\}$

If you wish to check--to confirm my initial assertion about the mean of a mixture (in case I was wrong!)--go right ahead:

Mean[MixtureDistribution[{0.1, 0.9}, 
    {UniformDistribution[{39.3, 40.5}], 
    TruncatedDistribution[{40.5, 104}, NormalDistribution[a, 11.4]]}
    ] /. %]


share|improve this answer
Thanks whuber. Great answer. – Cam Jan 10 '13 at 22:06

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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