I have a cdf calculated as follows:
mu = 0; var = 1; x = -10:0.01:10; y = cumtrapz((2*pi*(var))^(-0.5)* exp(-((x-mu).^2)/(2*(var))));
This gives the cdf of my probability distribution function (pdf): (2*pi*(var))^(-0.5)* exp(-((x-mu).^2)/(2*(var)))
But i want to sample the values of x randomly for this pdf. So I've created the cdf stored in variable y.
If i can find the inverse cdf, then i can uniformly select y values and then calculate using inverse cdf the corresponding x values that become my sample.
with the inverse function of the cdf, i want to get x in terms of y,
eg, y = F(x)
then x = Finverse(y)
like in figure:
I want to pass in y in the figure to Finverse(y) which is inverse of cdf, and then i can get x as:
x = Finverse(y)
But, i've tried many methods till now, but none seem to help.
i've tried to use :
i = erfinv(y)
but this gives me values as vector, but i need function so that i can pass in the values of y to get x. Please help.
Best Answer