Clear Filters
Clear Filters

how to generate log normal random number

16 views (last 30 days)
hi, i use this code to generate 5 random number with average 8.3 and standard deviation 2.7:
mu=8.3; %mean (m)
sigma=2.7; %standard deviation (m)
d = lognrnd(mu,sigma,5,1)
But the result:
d =
8333.6
15284
73.374
256.03
1203.6
this numbers generated, but mean of this numbers Not equal to 8.3
Where did i make mistakes?

Accepted Answer

Steven Lord
Steven Lord on 19 Jun 2018
"mu and sigma are the mean and standard deviation, respectively, of the associated normal distribution" (emphasis added) and
"The mean m and variance v of a lognormal random variable are functions of µ and σ that can be calculated with the lognstat function."
The functions given after that second quote are not "m = mu" and "v = sigma^2".
  2 Comments
mohamad khazaeezade
mohamad khazaeezade on 19 Jun 2018
Thank you very much ... please write the code that I want ... I'm a bit confused
Steven Lord
Steven Lord on 19 Jun 2018
Also from the documentation: "If X is distributed lognormally with parameters µ and σ, then log(X) is distributed normally with mean µ and standard deviation σ."
mu=8.3; %mean (m)
sigma=2.7; %standard deviation (m)
d = log(lognrnd(mu,sigma,5000,1));
mean(d)
std(d)
Note that I generated 5000 numbers, not 5.
If you want the numbers that are generated from lognrnd and are lognormally distributed to have a specified mean and std, not the normally distributed numbers that you get by transforming those numbers, see the second set of equations in the Description section on the documentation page to compute the parameters for your lognrnd call.

Sign in to comment.

More Answers (1)

Jeff Miller
Jeff Miller on 20 Jun 2018
Cupid has a class for a version of the lognormal where you specify the mean and sd of the scores you want. You can make an object of that class and generate random numbers from it like this:
myDist = LognormalMS(8.3,2.7);
myDist.Random(1,5)
ans =
5.2133 6.8788 8.7989 24.554 18.997

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!