I am trying to write some code to run a Monte Carlo simulation. I am stuck on the first bit which requires the generation of input values to the calculations. If each input value has a probability distribution, for each run I need to pick values from this distribution by choosing an area value between 0 and 1 each time, where the area under the distribution is normalized to be 1.
Can anyone help me? I have been hunting for several hours and have not really got anywhere. I have looked at some examples in numerical recipes in C but am not sure if what I am looking at is what I need.
I have the following thoughts, which may or may not have anything correct in them:
If I have a probability distribution f(x), where x goes from xmin to xmax, then f(x)dx over all x = 1.
If I pick a random area value, e.g. 0.3, I need to find the value of x, xval, which is the point at which the area under the curve is 0.3.
So I need to integrate f(x) from xmin to xval and equate that to 0.3 in order to find xval
Eg if f(x) = x^2 then f(x)dx = x^3/3
So (xval^3 – xmin^3)/3 = 0.3 then I just need to find xval
Is this right?
If so, I just need to find the integrated formula for all the probability distributions
e.g. if my distribution is x^2 then I don’t need to know this, I just need to know that my integrated formula is x^3/3
Thank you for taking the time to read this.