How to generate random numbers of lognormal distribution within specific range in Matlab

Posted by Harpreet on Stack Overflow See other posts from Stack Overflow or by Harpreet
Published on 2010-06-18T13:55:22Z Indexed on 2010/06/18 14:33 UTC
Read the original article Hit count: 296

My grain sizes are defined as D=[1.19,1.00,0.84,0.71,0.59,0.50,0.42]. The problem is described below in steps.

  1. Grain sizes should follow lognormal distribution.
  2. The mean of the grain sizes is fixed as 0.84 and the standard deviation should be as low as possible but not zero.
  3. 90% of the grains (by weight %) fall in the size range of 1.19 to 0.59, and the rest 10% fall in size range of 0.50 to 0.42.
  4. Now I want to find the probabilities (weight percentage) of the grains falling in each grain size.
  5. It is allowable to split this grain size distribution into further small sizes but it must always be in the range of 1.19 and 0.42, i.e. 'D' can be continuous but 0.42 < D < 1.19.

I need it fast. I tried on my own but I am not able to get the correct result. I am getting negative probabilities (weight percentages). Thanks to anyone who helps.

I didn't incorporate the point 3 as I came to know about that condition later. Here are simple steps I tried:

%%

D=[1.19,1.00,0.84,0.71,0.59,0.50,0.42];

s=0.30; % std dev of the lognormal distribution

m=0.84; % mean of the lognormal distribution

mu=log(m^2/sqrt(s^2+m^2)); % mean of the associated normal dist.

sigma=sqrt(log((s^2/m^2)+1)); % std dev of the associated normal dist.

[r,c]=size(D);

for i=1:c

D(i)=mu+(sigma.*randn(1));

w(i)=(log(D(i))-mu)/sigma; % the probability or the wt. percentage of the grain sizes

end

grain_size=exp(D);

%%

© Stack Overflow or respective owner

Related posts about matlab

Related posts about distribution