# RandomVariate does not fill range of PDF of distribution

I've declared my own probability distribution as follows

dist[a_, b_] := ProbabilityDistribution[Cos[(b x)/2]^2 Sinc[a x]^2, {x, -400, 400}];


When I try to create a random variate using this probability distribution I only get data points in a range (-400, -245).

data = RandomVariate[dist[200, 500], 10^4];
Histogram[data, 200, "ProbabilityDensity"] Just to clarify, this isn't an issue with the histogram, when I look at data it does only contain numbers in the range seen above.

• Your distribution is not define as it is called in the RandomVariate call. – Andy Ross Oct 2 '13 at 12:57
• Thank you Andy, I've edited the question so that it makes sense! – mrkprc1 Oct 2 '13 at 13:03
• Also, don't use D as your distribution name, that is a built-in symbol. As a general rule it is always good to start your own function names in lower case to avoid such conflicts. – Andy Ross Oct 2 '13 at 13:31
• Ok, again this is a problem that comes from copy/pasting straight from mathematica notebook. My distribution is not called D, I'm using the curly D that I could not get on this page, I'll edit again to save confusion! – mrkprc1 Oct 2 '13 at 13:35
• You can gain some insight into what happends by plotting the CDF of your not properly normalised pdf. The CDF ranges from 0 to the integral of the function, not 1. This is useful, you can check CDF[dist, xmax ] == 1 to verify a properly normalized distribution. Now the InverseCDF simply inverts the ill formed CDF, but truncates to the range 0-1. If you go through that exercise you can see the weird behavior makes some sense. – george2079 Oct 2 '13 at 16:09

A pdf is only well-defined if it integrates to unity over the domain of support. You have set up the domain of support as (-400, 400). You would have to check what values of $a$ and $b$ (if any) are appropriate for that domain of support. But, more to the point, your domain of support is ill-defined for the parameter values you have provided:

f = Cos[(b x)/2]^2 Sinc[a x]^2;

Integrate[ f /. {a -> 200, b -> 500}, {x, -400, 400}] // N


0.00785395

If you set up the domain of support on the real line {x,-Infinity, Infinity}:

Integrate[f /. {a -> 200, b -> 500}, {x, -Infinity, Infinity}]


Pi/400

... you just need to multiply your pdf by 400/Pi, and you are all set (given those parameter values for $a$ and $b$).

• Ok, so if I change my probability distribution to D[a_, b_, A_]:=ProbabilityDistribution[ (Cos[(b x)/2]^2 Sinc[a x]^2)/Integrate[Cos[(b x)/2]^2 Sinc[a x]^2, {x, -A, A}], {x, -A, A}]; should that then work since it guarantees normalisation for any range A? – mrkprc1 Oct 2 '13 at 13:30
• Wow "The integral of the PDF over the distribution domain needs to be unity:" is burried in the docs under "properties and relations". Poor documentation considering how ill behaved the function is if you dont precisely meet that criteria. – george2079 Oct 2 '13 at 15:23
• @george2079 Pardon me, but this shouldn't be in the docs at all, as this is elementary maths. According to the law of total probability, for a "set of pairwise disjoint events whose union is the entire sample space" the sum of all probabilities should be 1. (For continuous distributions, replace sum with integral.) – István Zachar Oct 2 '13 at 21:04
• It should be clearly documented that it doesn't check for validity. – george2079 Oct 3 '13 at 12:17