How to generate random numbers of lognormal distribution within specific range in Matlab
- by Harpreet
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.
Grain sizes should follow lognormal distribution.
The mean of the grain sizes is fixed as 0.84 and the standard deviation should be as low as possible but not zero.
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.
Now I want to find the probabilities (weight percentage) of the grains falling in each grain size.
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);
%%