필터 지우기
필터 지우기

how to generate log normal random number

조회 수: 10 (최근 30일)
mohamad khazaeezade
mohamad khazaeezade 2018년 6월 19일
답변: Jeff Miller 2018년 6월 20일
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?

채택된 답변

Steven Lord
Steven Lord 2018년 6월 19일
"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
mohamad khazaeezade
mohamad khazaeezade 2018년 6월 19일
Thank you very much ... please write the code that I want ... I'm a bit confused
Steven Lord
Steven Lord 2018년 6월 19일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Jeff Miller
Jeff Miller 2018년 6월 20일
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!

Translated by