LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reduce high order polynomials to closest approximation of a lower order polynomial

Ok I have a problem with my higher order polynomials.  The math falls apart with large numbers. I assume it's a truncation error.  I need a way to reduce the order of the polynomial.  For instance I have an algorithm that takes two polynomials and uses "polynomials composition.vi" to combine the two polynomials into a single high order equation.  when I test it with small numbers, it works fine. but as the numbers get larger, the error goes off the charts.  is there a polynomial reducing algorithm?  I need a routine that will take a 60th order equation and reduce it to a best fit 10th order equation or whatever. anybody got any bright ideas?  *calling all Summa Cum Nerdlys!*
0 Kudos
Message 1 of 8
(5,154 Views)
It is hard to believe that a 60th order polynomial would have any physical meaning. What is your underlying data?
 
Are you trying to do this symbolically or do you have some real data? If you have real data, you could just fit it to a polynomial of sufficient order using the "polynomial fit" tool.
0 Kudos
Message 2 of 8
(5,142 Views)
If I do a best fit of a Nominal to actual curve and then do a best fit of a Nominal to Engineering units curve, I end up with two symbolic equations describing the calibration curve for an analog out channel. The Nominal to Actual curve would be generated by nominally outputing 1 volts and actually outputing 0.9999 volts.  The Nominal to Actual curve would correct this part of the calibration.  The Nominal to engineering Curve would be like 0-100 psig equals 0-10 volts, or whatever.  Then I map the nominal to engineering units curve  into the nominal to actual curve such that the operator enters 50 psig, and the analog output channel outputs 5.0011 volts so that the actual output read by an instrument is 5.000.  Understand?  Anyway the "polynomials composition.vi" combines the two equations and the result is an extremely high order equation.  I could limit the size of the two equations going in to the "polynomials composition.vi" but I need a way to reduce the output of that vi. 
0 Kudos
Message 3 of 8
(5,135 Views)
I just tried limiting the best fit criterion to 5th order for the equations going into the "polynomials composition.vi" and the result is now down to 25th order.  This is producing better results, as in, the math no longer falls apart.  But I fear I am sacrificing accuracy since the root mean square error is now higher with lower order equations.
0 Kudos
Message 4 of 8
(5,126 Views)

High-order polynomials are notoriously ill-behaved away from the data points used for the best-fit.  Did you ever try plotting that polynomial with, say, 20 points between the points used to define the poly?  You end up with w/ at least two distinct problems.  One, the high order dictates a large # of inflection points, producing lots and lots of ziggy-zaggies.  Two, round-off and truncation errors are magnified tremendously. 

Anyway, have you considered using the cubic spline technique, or even a humble linear interpolation lookup table?  Chaining two of these together, one for each mapping, can often give surprisingly good results.  Most real-world device performance curves or calibration curves tend to be pretty well-mannered anyway, in my experience.  The main exceptions where I've used single polynomials (and rarely higher than 3rd order) are where there's a solid theory to predict the curve shape/polynomial order, and there are very very few actual data points present in the cal curve.

-Kevin P.

 

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
0 Kudos
Message 5 of 8
(5,108 Views)
That is an interesting idea. take my extremely high order polynomial and plot 20 points in the range of interest, then re-fit the data with a lower order polynomial.  This whole thing is planing for unlikely events.  most instruments I deal with are linear.  I can only think of two examples of strange curves.  one: Load and torque cells act funny around zero load. Two: some servo valves have parabolic performance curves.  I am getting into trouble here only in the analog out calibration routines, because I need to map two polynomials together. so if I have two 5th order equations, I end up with a 25th order combination.  on the analog in calibration I only need 1 equation so even a 10th order equation is overkill. I have witnessed first hand the truncation errors that occur in 60th or 100th order equations.  effectively you can only carry about 14 digets of prescition in a double. so any math taking place in my extremely high order equations is getting truncated and horribly misfigured. I will have to investegate cubic splines, I am trying to limit the amount of data I have to lug around in the code, That is why I need one formula per channel.  Currently on this example I read 56 analog-ins and write 8 analog-outs.  each channel gets converted to Engineering units with a polynomial equation 20 times per second and my CPU usage is only 12%.
0 Kudos
Message 6 of 8
(5,105 Views)
"act funny around zero load."
 
Not sure if this will help;
 
Have you attempt to weight the samples at the low end higher? Take 10X as many samples in the range where things are flakey. This will have the end effect of tweaking you coefficients to work better at the low end.
 
Just trying to help,
 
Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 7 of 8
(5,099 Views)
Weighting or manually loading the samples with tare loads would be a good idea if the test were not automated.  the test stand goes through a load spectrum that my client defined, and is inflexible in the load values. so in an endurance test, the torques shift about every 2 seconds and the loads are all over the place.  imagine clockwise torque of 285,000 in-lbs, followed by counterclockwise torque of 500 in-lbs.  this thing realy gets slammed around. for weeks.  The only solution in that case is very acurate cal curves.  The test I just described samples at 1kHz.  I think I will just limit the polynomials to 5th order and move on.  Version 2.0 will be more complex. 🙂
0 Kudos
Message 8 of 8
(5,093 Views)