Quantcast
Channel: LabVIEW topics
Viewing all articles
Browse latest Browse all 66670

"Variance PtByPt.vi" generates negative values for certain input values

$
0
0

With certain sequences of input values the Variance PtByPt.vi can generate negative values. This is due to the finite precision in the calculations.

 

Because it is very common to calculate the standard deviation by taking the square root of the variance, this behavior can take you by surprise as the result will be NaN's and not almost 0 as you would expect. Depending on the data, this can be frequent or extremely in frequent. In general - a nuisance to debug.

 

The cure is simple: Take the Abs() value before the square root. Attached is a vi which demonstrates the case.

 

I would suggest to include this correction (or similar) into the "Variance PtByPt.vi" because it does give rise to unexpected and hard to find errors.

 

By definition - variance  cannot  be  negative.

 

variance is negative.png

Front panel.png

 


Viewing all articles
Browse latest Browse all 66670

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>