From: ValeX on
i have a numerical pdf of variable dem and parameters z and s:
pdfconv[dem, z, s]

I want to draw random real number from it. The mathematica helps talks
about Random`DistributionVector but i cant understand how to do.
I'd like to define my distribution distconv[z,s] so that i can use it
in this command:
RandomReal[distconv[z,s]]

many thanks

From: Sjoerd C. de Vries on
If you can find the inverse cumulative distribution function of your
distribution (invCDF) you can define the function as:

distconv /:
Random`DistributionVector[distconv[z_, s_], n_Integer,
prec_?Positive] :=
invCDF[z, s] /@ RandomReal[{0, 1}, n, WorkingPrecision -> prec] /;
VectorQ[{z, s}, NumericQ] && Element[{z, s}, Reals]

As an example of how to find the invCDF, here I show you how to do
this for the normal distribution:

x /. Solve[CDF[NormalDistribution[z, s]][x] == xi, x][[1, 1]]

During evaluation of In[183]:= Solve::ifun: Inverse functions are
being used by Solve, so some solutions may not be found; use Reduce
for complete solution information. >>

Out[183]= z + Sqrt[2] s InverseErf[-1 + 2 xi]

We may now define invCDF as:

invCDF[z_, s_] := z + Sqrt[2] s InverseErf[-1 + 2 #] &

This was rather easy as Mathematica knows the CDF of the
NormalDistribution. You will have to find the one for your
distconv[z_, s_] yourself and hope its invertible (and not too
computationally expensive).

Prove that it works:

Histogram[RandomReal[distconv[0, 1], 10000]]

Cheers -- Sjoerd


On Mar 19, 9:39 am, ValeX <rjov...(a)gmail.com> wrote:
> i have a numerical pdf of variable dem and parameters z and s:
> pdfconv[dem, z, s]
>
> I want to draw random real number from it. The mathematica helps talks
> about Random`DistributionVector but i cant understand how to do.
> I'd like to define my distribution distconv[z,s] so that i can use it
> in this command:
> RandomReal[distconv[z,s]]
>
> many thanks


From: ValeX on
It works perfectly, thank you very much!