# 6th order polynomial expression

#### chandimajaya85

Joined Sep 27, 2023
5
I have a set of data, defined by Y=A+BX+CX^2+DX^3+EX^4+FX^5+GX^6.
. I do a calibration of 24 point sample and then do a polynomial curve fit. X would be a voltage, A,B,C,D,E are constants, and Y is a resulting measurement (in engineering units). Lets say, 24 point sample points are [0.08,0.16,0.24,0.32,0.40,0.48,0.56,0.66,0.76,0.86,0.96,1.6,2.6,3.6,4.8,6.0,7.2,8.4,9.6,10.8,12.0,13.2,14.4,16.6] and do a polynomial curve fit. Now, lets say the X voltage is 0.065 do use that polynomial Y to get the result. Will that give a wrong result and error because at first instant of 24 point sample is 0.08 and polynomial Y is different. Its missed that data sample. I would appreciate if any one can help on this. Thank you.

#### BobTPH

Joined Jun 5, 2013
8,062
It would be extrapolating instead of interpolating, and yes, extrapolating can give large errors. Why not sample the entire range of x’s before fitting a curve?

#### MrChips

Joined Oct 2, 2009
29,794
I see one array, let’s say Y data. Where is the X data?

• panic mode

#### BobTPH

Joined Jun 5, 2013
8,062
I see one array, let’s say Y data. Where is the X data?
I think that is the X. He is asking what happens if then the runs an X (0.065) that is out of the range used to compute the polynomial.

#### joeyd999

Joined Jun 6, 2011
5,033
High-order polynomial equations tend to explode radically outside the range of their training data set.

Often, natural phenomena follow curves that are much better estimated by other forms (i.e. power, exponential, log, etc.)

The trick is to find the form that best matches your expected data, both within the training range, and outside of it.

I've had great success using a software package called TableCurve 2d:

https://systatsoftware.com/tablecurve2d/

It'll take your Excel data and quickly map it against over 4000 different equations, and rank them by best fit, along with providing the required coefficients.

You may find that you can far better map the data with far fewer than your current 7 terms.

The software is expensive, but they provide a free 30 day full- function eval license.

#### MrChips

Joined Oct 2, 2009
29,794
The first thing you do is plot Y vs X from your data. Then you visually look at the trend. There are very few physical phenomenon that have a 6th order relationship.

When you find a suitable mathematical model, the model will allow you to go beyond the range of your collected data points.

#### WBahn

Joined Mar 31, 2012
29,472
I have a set of data, defined by Y=A+BX+CX^2+DX^3+EX^4+FX^5+GX^6.
. I do a calibration of 24 point sample and then do a polynomial curve fit. X would be a voltage, A,B,C,D,E are constants, and Y is a resulting measurement (in engineering units). Lets say, 24 point sample points are [0.08,0.16,0.24,0.32,0.40,0.48,0.56,0.66,0.76,0.86,0.96,1.6,2.6,3.6,4.8,6.0,7.2,8.4,9.6,10.8,12.0,13.2,14.4,16.6] and do a polynomial curve fit. Now, lets say the X voltage is 0.065 do use that polynomial Y to get the result. Will that give a wrong result and error because at first instant of 24 point sample is 0.08 and polynomial Y is different. Its missed that data sample. I would appreciate if any one can help on this. Thank you.
Depends on several things. Assuming that those are your x-values, the an X value of 0.065 is just barely outside the edge of the captured data, so if a 6th order polynomial is a good model for the relationship between X and Y within the range, then the deviation is probably not going to be too extreme just outside of it.

But if it's not a good model, then all bets are off. This is also true if a significantly lower-order polynomial is the best model -- higher-than-necessary models get real flaky real fast because they start oscillating wildly in order to force the model to go through the data points.

You need to plot your modeled curve against the actual data and see if it looks reasonable.

Why do you think you need a 6th order polynomial in the first place?

#### BobTPH

Joined Jun 5, 2013
8,062
Why do you think you need a 6th order polynomial in the first place?
Yes, that would be very unusual, and I agree on the wild behavior outside the range on higher order polynomials.

A cubic spline interpolation might be nearly as good within the range, and the fact that the first two derivatives must match at each point lets you direct where it goes outside the range. Cubic splines are also called Bézier curves.

#### WBahn

Joined Mar 31, 2012
29,472
Yes, that would be very unusual, and I agree on the wild behavior outside the range on higher order polynomials.
Or even inside the range of the data. Go too much higher than the optimal degree and you end up with something that just oscillates between nearly positive and negative infinity at a period close to half the sample spacing and that has zero, or almost zero, RMS error because it goes almost through every data point, albeit it nearly vertically.

• BobTPH

#### crutschow

Joined Mar 14, 2008
33,317
My HP-42s calculator has a BEST curve-fit function that would fit an input series of XY data to a Linear, Log, Exponential, or Power function, whichever gave the best fit to the data.
I have a virtual version of that calculator on my computer, that replaces my real one with a bad key, which performs that function.

#### chandimajaya85

Joined Sep 27, 2023
5
It would be extrapolating instead of interpolating, and yes, extrapolating can give large errors. Why not sample the entire range of x’s before fitting a curve?
Thank you very much for the reply. if extrapolating gives large errors. How do I prove it, that it gives error. How do I find the accuracy and error.

#### Ian0

Joined Aug 7, 2020
8,935
What does the data represent?
Does it deviate from a linear or quadratic only because of the limits of error on each data point? Or does it really require a 6th Order curve?

#### chandimajaya85

Joined Sep 27, 2023
5
Thank you very much for replies. This is a seperate question but its related to 6th polynominal expression. After it is defined for curve fit for sample data. Can it be use it for correction factor to correct the data to match with a equipment as in calibration

#### joeyd999

Joined Jun 6, 2011
5,033
Thank you very much for replies. This is a seperate question but its related to 6th polynominal expression. After it is defined for curve fit for sample data. Can it be use it for correction factor to correct the data to match with a equipment as in calibration
This is the way I do it for the products I manufacture -- though I use models that are tailored to the expected curves.

The firmware is coded to compute its own coefficients (stored in non- volatile memory) based on a range of known sampled input data.

#### MrChips

Joined Oct 2, 2009
29,794

The proper approach is to match a mathematical model to a physical process. You need to find the best mathematical model and I can assure you that it is not a 6th order polynomial.

Real data collected come with errors. You need to show error bars on your plot. The goal of the mathematical modelling process is to find the best model that fits the data within the confines of the errors on the data. The purpose of the model is not to fit all data points perfectly.

Once a proper model has been found, you use that model and ignore the data.

#### chandimajaya85

Joined Sep 27, 2023
5

The proper approach is to match a mathematical model to a physical process. You need to find the best mathematical model and I can assure you that it is not a 6th order polynomial.

Real data collected come with errors. You need to show error bars on your plot. The goal of the mathematical modelling process is to find the best model that fits the data within the confines of the errors on the data. The purpose of the model is not to fit all data points perfectly.

Once a proper model has been found, you use that model and ignore the data.
Thats mean, I have to take many sample points to come up a mathematical model. 24 points samples want be enough to put a mathematical model. Is that right.

#### MrChips

Joined Oct 2, 2009
29,794
Thats mean, I have to take many sample points to come up a mathematical model. 24 points samples want be enough to put a mathematical model. Is that right.
No. Two data points is sufficient to yield a mathematical model if the proper model is a straight line.

Show us the X and Y data and we can take it from there.

#### chandimajaya85

Joined Sep 27, 2023
5
This is the way I do it for the products I manufacture -- though I use models that are tailored to the expected curves.

The firmware is coded to compute its own coefficients (stored in non- volatile memory) based on a range of known sampled input data.
Thank you for the reply. But the product reports the same unit for example voltage and I am trying to calibrate to the same voltage to put a correction factor to the voltage. putting up a curve fit, will that fix the issue. Y will be voltage and X will be voltage for that curve fit expresion. It does not make sense to find a curve fit to apply for correction factor to the data.

#### BobTPH

Joined Jun 5, 2013
8,062
Thank you for the reply. But the product reports the same unit for example voltage and I am trying to calibrate to the same voltage to put a correction factor to the voltage. putting up a curve fit, will that fix the issue. Y will be voltage and X will be voltage for that curve fit expresion. It does not make sense to find a curve fit to apply for correction factor to the data.
Show us the damn data!

#### Ian0

Joined Aug 7, 2020
8,935
More importing is know what the data represent. Is the function they represent naturally linear, or naturally square-law etc.?