mardi 25 septembre 2018

Generating random numbers with a cumulative distribution function

I am aware of the fact that rand returns a single uniformly distributed random number in the interval (0,1).

But I am also asked for using the following cumulative distribution function:

F(x) = \int_{-\inf}^{x} f(y) dy

I know how to generate uniformly distributed random numbers within an interval with the formula:

r = a + (b-a).*rand(N,1).

Where (a,b) is the interval and N the number of #

But how can I use uniformly distributed random numbers (in the interval [0,1] of course) and the inverse of the cumulative distribution function defined above in order to generate random numbers distributed uniformly in an interval (let's say [-2,1])?

NOTE: Sorry about the way I showed the integral but MathJax does not work in Stackoverflow. I do not know if there is another way to expose it. Please let me know if there is and I will change it. Thank you




Aucun commentaire:

Enregistrer un commentaire