File Exchange

image thumbnail

lognormal

version 1.1.0.0 (2.35 KB) by Walther
Creates a lognormal distribution with desired mode (peak-value) .

3 Downloads

Updated 15 Nov 2010

View Version History

View License

lognormal: creates lognormal distribution with desired mode (peak-value)

usage: lognormal(mode_log,sigma_n,n,plotit)

--- INPUT arguments:
'mode_log' ---> can be any positive value (is the most frequent value of the lognormal distribution -> the peak in the histogram)
'sigma_n' ---> standard deviation of the corresponding normal distribution
--> CAUTION: it is not the standard deviation of the lognormal distribution, because it is a somewhat unuseful value for an asymmetric distribution
'n' ---> number of n-values the distribution should have
'plotit' ---> plot switch (0=no,1=yes)

How it works:
1.) calculate the mean(normal) from the input mode_log (lognormal) and sigma_n (normal) with mu_n = log(mode_log) + sig_n^2
2.) create random normal distrubution r with n-values
3.) shift and transform the normal distribution with dist_n = mu_n + sig_n * r
4.) transform the normal distribution to lognormal with dist_log = exp(dist_n)
5.) calculate the output mode of the lognormal distribution with mode_out = exp(mean(dist_n)-std(dist_n)^2)

--- OUTPUT arguments:
'output' struct with several fields:

'dist_n' ---> created normal distribution
'mu_n_in' ---> input mean value for the normal distribution calculated from input 'mode_log' and 'sigma'
'mu_n_out' ---> output mean value of the normal distribution
'sig_n_in' ---> input standard deviation ('sigma') of the normal distribution
'sig_n_out' ---> output standard deviation of the normal distribution
'dist_log' ---> created lognormal distribution
'mode_log_in' ---> input mode of the lognormal distribution
'mode_log_out' ---> output mode of the lognormal distribution calculated from mean and standard deviation of the normal distribution 'dist_n'
'mu_log' ---> output mean value of the lognormal distribution
'sig_log' ---> output standard deviation of the lognormal distribution

--- Example usage:
output = lognormal(1-e4,1,1e5,1)
- will create a lognormal distribution with mode 0.0001
- the corresponding normal distribution will have a standard deviation of 1
- 10'000 values will be created
- both distributions will be plotted

Cite As

Walther (2021). lognormal (https://www.mathworks.com/matlabcentral/fileexchange/29407-lognormal), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (3)

joe joe

Pang Suyoung

Peter

I think there might be an error in line 62. It should be

if nargin == 3 || (plotit ~= 0 && plotit ~= 1)

Otherwise plotting will be always switched on.

Other then that it works as intended. Thanks!

MATLAB Release Compatibility
Created with R2009b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!