1
$\begingroup$

I have a customized distribution and I have to draw some random number from it.

How do I use RandomVariate to draw random number from a custum distribution? My naive attempt RandomVariate[mydist] fails with and Mathematica throws the error:

RandomVariate::udist: "The specification is not a random distribution recognized by the system"

My distribution is:

me =511000;
M = 938000000;
c = 29979200;
en=10^8;
z = 1;
ρ = 2.33;
en = 10^6;
τ[T_?NumericQ] := T/M ;
β[T_?NumericQ] := Sqrt[1 - (1/(τ[T] + 1))^2];
wm[T_?NumericQ] := (2 me β[T]^2)/(1 - β[T]^2);
Zs[T_?NumericQ] = z (1 - Exp[-((125 β[T])/z^(2/3))]);  

mydist[w_]:= 1/Σ[en] 0.307075*14/28.0855 10^6 ρ 10^-4/(β[en]^2 (w + 173)^2) (1 - (β[en]^2 (w + 173))/wm[en] + (Pi β[en] Zs[en]^2)/137 Sqrt[(w + 173)/wm[en]] (1 - (w + 173)/wm[en]))

$\Sigma[en]$ is the normalization, the integral of the rest between 1 and w[en]

$\endgroup$
4
  • 2
    $\begingroup$ How is the custom distribution defined? Can you provide a short example? $\endgroup$ – Jason B. Jul 28 '18 at 14:59
  • $\begingroup$ Have a look at the answers here How to generate a RandomVariate of a custom distribution?, see if they can help. $\endgroup$ – Jason B. Jul 28 '18 at 15:14
  • $\begingroup$ How is w defined? $\endgroup$ – Coolwater Jul 28 '18 at 15:16
  • $\begingroup$ Does the positive support for w range from 1 to wm[en] rather than w[en]? If so and after fixing that, you've defined the probability density function. To get random samples you'll need to tell Mathematica what the distribution is by using ProbabilityDistribution. That's what the error message is telling you. $\endgroup$ – JimB Jul 28 '18 at 17:58

Browse other questions tagged or ask your own question.