how to generate log normal random number
10 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
mohamad khazaeezade
il 19 Giu 2018
Risposto: Jeff Miller
il 20 Giu 2018
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?
0 Commenti
Risposta accettata
Steven Lord
il 19 Giu 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 Commenti
Steven Lord
il 19 Giu 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.
Più risposte (1)
Jeff Miller
il 20 Giu 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
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!