# quadratic fit tool wrong coefficients

2 views (last 30 days)
sander de lange on 14 Nov 2019
Commented: Looky on 18 Nov 2019
I have plotted a large data list of 46 points where I plot the temperature against wavelength. Then I fit with the toolbox from matlab and I get a nice quadratic comparison. If that equation is then used to enter values, it appears that there is a mistike with the fit. Is there anyone who can help me with this problem?

Looky on 14 Nov 2019
Did you use the displayed formular or the calculated coefficients?
Simple test: your x values are roughly 1e-6 , squared and multiplied with the first coefficient of 5.4e18 this leaves something like 5e6 but your y values are 1e2. This means you will need at least 5 diggits of your first coeffcient, but better go with 7 or 8.
Also, be aware that while the fit looks good, it is most likely untrustworthy out of your x region. Have a look at the confidence bounds of the coeffcient parameters. So what do you want to do with it?
sander de lange on 15 Nov 2019
I want to be able to calcute with the fit. If I now measure a wavelength via the fit, I can calculate a temperature, then I want to measure the temperature and then compare this measured value with the calculated temperature, but if I now calculate with the fit, very strange temperatures will come out . Because when I get fit I get the message: polynomial is badly conditioned. Add points with distinct x values, select a polynomial with a lower degree, or select Center and scale data x data. My questions are for this story:
-What does this message mean?
- And why is this fit the right one?
Looky on 18 Nov 2019
The error message mostly comes from your very small x-values. Fitting works best if you normalize and center your data. This has statistical and numerical reasons, ask google for details. What to do against this problem, you can read in the answer by Steven Lord below.
If you use the curve fitting toolbox (cftool) it is a matter of ticking a box. (if you have a problem there, just comment under Steven Lords answer).
However, in your case this only solves part of the problem. If you look at your data it looks very much like a line with a very small curvature. A parabola works okay in modelling this, because two of the three parameter for a parabola describe a line already.
Parabola: f(x) = p1*x^2 + p2*x + p3
where p2 and p3 can describing a simple line.
However, the distinct characteristics of a parabola (the vertex/turning point or the axis of symmetry) are not present in your data. This is a problem for your fit, since the parameter p1 can have many different values that will all give a parabola that fits your data in your x-region well. (I can go into more detail if that is of interest)
This means, your fit will (after centering and normalizing) have p2 and p3 with goodish confidence bounds and p1 with a horrible confidence bound (untrustworthy).
However, as you can see, the curve itself works perfectly to describe the behaviour of your data within the give x-region.
The question you have to ask yourself now is:
Is it okay if the fit works only within the given x-region?
If no, then you have a problem, because the prediction your fit can make outside your x-region is not really trustworthy unless you have anymore information on how the parabola might look. E.g.: at a wavelength of x the temperature must be zero or any other physical meaning that might help in improving the fit.

Steven Lord on 14 Nov 2019
Because your parameters are so large, I strongly encourate you to center and scale your data as shown in step 7c in the first example on this documentation page (if you're using the Curve Fitting App) or the "Modify Default Fit Options to Normalize Data" and "Use Identical Fit Options in Multiple Fits" examples on this documentation page (if you're doing programmatic fitting.)
As Looky indicated, the coefficients displayed when you display the fit object do not show the full precision of the coefficients. If you want to evaluate the fit, evaluate the fitted curve or fitted surface directly. This is especially important if you center and scale your data as evaluating the object will automatically apply the same normalization to the data with which you evaluate the fit object.