01-18-2014 04:24 PM - edited 01-18-2014 04:25 PM
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.
Solved! Go to Solution.
01-18-2014 05:52 PM
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.
01-22-2014 07:35 AM
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
08-21-2014 03:58 PM - last edited on 12-03-2024 11:18 AM by Content Cleaner
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