LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Log-normal distribution

I've been looking to use the PDF and CDF of the log-normal distribution, because atmospheric aerosols tend to follow those number distributions. However, both seem to be pretty badly garbled. Is there someone at NI I can talk to about this so it can be fixed?

 

I've made corrections to them and attached the vi's below. There is also the comparison between the built-in vi's and the corrected ones in 'lognormal problems.vi'.

 

PS. I wouldn't even look at the Wikipedia page for it, it's hopelessly wrong.

0 Kudos
Message 1 of 5
(3,358 Views)

By my reckoning, the BD constant in the LogNormal PDF vi is wrong, b should be c and a should be b.

 

The simple definition is that ln(x) is a normally distributed variable with mean M and standard deviation S.  Your reference prefers to call the mean ln(b) and the standard deviation ln(c).  LV calls the mean ln(b) and the standard deviation c.  You should be able to adjust for the different definitions if you want to use the built-in functions.

 

You have a similar typo in the fixed PDF vi, and you are missing a factor of x is the denominator of the coefficient of the exponential function, it should be

 

pdf = [1/(x*ln(c)*(2pi)^0.5]*exp[ -(ln(x/b))^2 /(2*(ln(c)^2) ]

 

Missing x is a bug in the code, ln(c) corrects a typo in the comment, but that part of the code is correct.  Fixing that bug and adjusting for the different definitions and I get all of the calculations to match.

 

lognormal.png

 

 

Message 2 of 5
(3,342 Views)

Thank you, Darin. Especially for the x; I wasn't sure whether to include it or not (the text I got it from discusses aerosols, and the distribution changes depending if you're talking about number, surface area, or size distribution). I should have integrated the thing numerically to check. In part, it is a matter of what you want one of the variables to be, the mean or the median. In the code I wrote, it's the median. They are related, where the mean = median*e^[((ln(c)^2)/2]. You can define the median and have the mean go up with an increasing deviation (c), or define the mean and have the median go down with increasing deviation. Deeper discussion in the help for this would improve things (which they may have done since the 8.5.1 that I'm using).

0 Kudos
Message 3 of 5
(3,316 Views)

The lognormal indeed seem to be buggy but I respectfully disagree with the fix of MFiddler. If e.g. std is bigger then the median you get a negative value for the std for the normal distribution, which gives a NaN.

In attachment I fixed files for the lognormal distribution. Random generation of 100.000 numbers from this VI distribution revealed a correct median and std. I didn't look to the pdf yet, but should be copy paste.

 

Best regards,

 

Bo

Download All
0 Kudos
Message 4 of 5
(2,841 Views)

The lognormal indeed seem to be buggy but I respectfully disagree with the fix of MFiddler. If e.g. std is bigger then the median you get a negative value for the std for the normal distribution, which gives a NaN.

In attachment I fixed files for the lognormal distribution. Random generation of 100.000 numbers from this VI distribution revealed a correct median and std. I didn't look to the pdf yet, but should be copy paste.

 

Best regards,

 

Bo

0 Kudos
Message 5 of 5
(2,840 Views)