LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Best Poly Fit Coefficients do not agree with Best Poly Fit

Using General Poly Fit.vi (with Givens algorithm, although others behave similarly), I found that the Best Polynomial Fit data array fit my data very well but the corresponding Polynomial Fit Coefficients did not. This is surprising since I would have thought that the Best Polynomial Fit data array would have been generated from the Poly Fit Coefficients. It appears the difference is a small offset between 5 and 20 on the Y-values. I used MS Excel to check the Poly Fit Coefficients output with the Best Poly Fit data array otput. I am using a 5-th order fit with an array of 59 data points. The input x-data ranges from 363.6 to 386.8 at 0.4 spacing. The input Y-values range from 149.75 to 974.29. The inpu
t Y-data is well behaved � almost linear. Should I expect this difference between the fit coefficients and data array output? I could add in an offset to correct the Best Poly Fit Coefficients; but this correction shouldn't be necessary.

Danny
0 Kudos
Message 1 of 3
(2,678 Views)
Hi Danny,

Double check your calculation using the coefficients and the precision of the calculations. When fitting nearly linear data to a 5th order fit, the coefficients generated are pretty large. I did a check with your data (simulated) and compared the Best Poly Fit with an array calculated using the Poly fit Coefficients. The two agreed to around 1e-7. The difference is due to machine precision.

See the attached. I whipped it together quicly so it's not very neat, but I think you'll follow what I've done.

Tim
Message 2 of 3
(2,678 Views)
Hi Tim,

Thanks so much for the very quick reply. I tried my actual numbers using your vi and found that my results were good. That forced me to look harder at my code. Since I was using the Differentiation.vi, I needed to convert the Poly Fit Coefficients to a string for use in the Differentiation.vi formula input. To do this, I used the Number to Exponential String.vi. Well, the default precision for this vi is 6� who�d a thought that. As soon as I changed it to 8 the numbers came out much better. I could have bumped it up more for even better results; but, 8 was sufficient.

You were right on the mark! Thanks again!

Danny
0 Kudos
Message 3 of 3
(2,678 Views)