LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

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

Solved!
Go to solution

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

 

Message 1 of 4
(3,017 Views)

Intersting. I agree that this is just some random instability due to the limitations of floating point math. For example if you would change the last digit of the repetitive input numbers from 1 to 3, everything is positive.

 

From a purely mathematical point of view, the math is clean, but from a software engineering view, maybe this could be improved by either rearranging the algorithm a little bit or by brute force (coercing the variance to >=0, ;)). Someody needs to study this.

 

 

0 Kudos
Message 2 of 4
(2,999 Views)

Hi Henning

 

Thanks for bringing this to my attention I agree that the result should not be able to be negative.

 

I have reported this to R&D under CAR # 446514. 

 

 

Best Regards

Anders Rohde | CLD | Platinum Applications Engineer | National Instruments Denmark

0 Kudos
Message 3 of 4
(2,918 Views)
Solution
Accepted by topic author heel

CAR 446514 discussed in this thread was fixed in  LabVIEW 2014.  For a more complete list of bugs fixed in LabVIEW 2014, check the LabVIEW 2014 Bug Fixes. You can download an evaluation copy of LabVIEW 2014 at www.ni.com/trylabview/ or if you have an earlier version of LabVIEW installed and an active SSP subscription, you will be able to download the latest version of LabVIEW through NI Update Service.

 

Regards,

 

Jeff Peacock 

 

Product Support Engineer | LabVIEW R&D | National Instruments | Certified LabVIEW Architect 

 

Message 4 of 4
(2,728 Views)