# How to find the inverse of non-standard CDF in Matlab?

The cumulative distribution function (CDF) for a truncated log-normal distribution is represented as shown below. How can I find its inverse in Matlab?

CDF_truncated_lognormal_distribution = lognormal_cdf(r)./(lognormal_cdf(rmax) - lognormal_cdf(rmin))

Where, lognormal_cdf() in above equation is a CDF of the standard log-normal distribution, and rmax and rmin are constants.

I need to find the inverse of above CDF in order to plug uniform random numbers (=U[0,1]) as a CDF value in the inverse equation and determine random number r of the truncated log-normal distribution.

• We closed the cross-post on Stats.SE due to the duplication, but if you want to migrate this to stats, it would be on topic and we would accept it. (It already has a good answer here, though.) – whuber Dec 21 '11 at 3:34

To generate random numbers from a truncated lognormal distribution, you don't need to explicitly compute the inverse CDF of the truncated distribution. You can do this using only the forward and inverse CDFs of the regular lognormal distribution. You need to:

Generate a uniform random sample of size n in the range [0,1]:

n = 10;
u = rand(n,1);


Set the limits of the truncated lognormal CDF:

a = logncdf(rmin,mu,sigma);
b = logncdf(rmax,mu,sigma);


Map the uniform random sample to be in the range [a,b]:

x = a + (b-a)*u;


Use the lognormal inverse CDF to generate the sample:

r = logninv(x,mu,sigma);

• @S_H. You're right. I edited my answer. – Kavka Dec 21 '11 at 3:36