Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Suppose I want to generate a histogram of $n$ trials a slightly complicated random variable in Mathematica. Is there an easy way to do this?

For instance, to make a histogram of a normal variable one can simple use

Histogram[RandomVariate[NormalDistribution[0, 1], 200]]

I want to create a histogram of a more complicated random variable. The random variable comes from random matrix theory, but its specific form is probably not so important. If we call it X, running

Histogram[RandomVariate[X, 200]]


RandomVariate::udist: "The specification X is not a random distribution recognized by the system." Indeed, even running

Histogram[RandomVariate[NormalDistribution[0, 1]^2, 200]]

returns this error message, and I think if I understood what's going wrong in this latter case my problem would be resolved also.

There is a Mathematica help page on the topic, but all the examples of random variables given there are for prepackaged probability distributions.

share|improve this question
Have you looked at ProbabilityDistribution[] –  george2079 Nov 26 '13 at 21:07
What do you mean by NormalDistribution[0, 1]^2? It is square of the probability density function or x^2 where x distributed as NormalDistribution[0, 1]? TransformedDistribution, EmpiricalDistribution and SmoothKernelDistribution can be helpful. Could you provide an example of the distribution? –  ybeltukov Nov 26 '13 at 21:09
Break your problem down to pieces and find the smallest piece that you can't get working. Do you need to plot the PDF or do you just need to generate a large number of random variates? It seems to me that you need the latter. In this case Histogram is irrelevant to the question. NormalDistribution[0, 1]^2 is not correct syntax. As george said, look at ProbabilityDistribution. –  Szabolcs Nov 26 '13 at 21:09
You don't have a problem with Histogram, you have a problem defining a distribution. Have a look at Create Your Own Distribution Workshop. –  Sjoerd C. de Vries Nov 26 '13 at 21:19

1 Answer 1

I think this is what you are after..

     2 Sqrt[π] (PDF[NormalDistribution[0, 1]][x])^2, {x, -∞, ∞}], 2000]]

Note that the argument to ProbabilityDistribution[] has to be a proper probability density function in the sense that it integrates to unity. (Thats where that 2 Sqrt[π] comes from)

share|improve this answer
Thanks! Sorry for the delayed response. This does indeed produce a histogram of X^2 where X is a standard normal variable. I'm afraid I oversimplified the problem in this example though. How would one go about creating a histogram, summing a series of independent identically distributed variables for instance? The actual problem I want to solve concerns operations on the eigenvalues of random matrices. Would it be most appropriate to simply create a new question, or to edit the question above to be more precise? –  Brad Rodgers Nov 29 '13 at 15:46

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.