0

I have the following data:

x = [0 5 10 15 20 25 30 35].';
y = [72.3 73.6 75.1 77.0 77.6 77.9 79.2 80.4].';

When I enter this code:

pg7 = polyfit(x,y,7);

The following warning appears and I don't know why:

Warning: Polynomial is badly conditioned. Add points with distinct X values, reduce the degree of the polynomial, or try
centering and scaling as described in HELP POLYFIT. 
ndmeiri
  • 4,979
  • 12
  • 37
  • 45
  • https://uk.mathworks.com/matlabcentral/answers/330095-warning-says-polynomial-is-badly-conditioned-but-it-seems-to-fit-with-the-data – Paolo May 21 '18 at 14:52

2 Answers2

1

You are trying to do a polynomial regression of order 7 on 8 data points. This will not be a regression but an interpolation as 8 points uniquely determines a 7th order polynomial.

So do as the error message tells you, add more points or lower the degree.

Alternatively, if you truly are after the interpolation, then do a Lagrange interpolation instead of fitting.

Nicky Mattsson
  • 3,052
  • 12
  • 28
0

The warning states that there are possible numeric issues related to the fitting process, because your x values are not centered around 0 and because you're using a determined model.

Using the curve fitting tool (cftool) you can see that the difference between centering and scaling and not doing so is between a fitting SSE of 1.831e-24 and 6.664e-27, respectively.

In other words - in this specific case, centering and scaling your data practically doesn't matter and the warning can be safely ignored.

On a different note, unless you have a good reason to do so, you probably shouldn't be fitting the maximum-possible-degree polynomial to your data (known as "overfitting"), as this is believed to captured noise and not the underlying phenomenon. Consider using a lesser-degree polynomial (e.g. 6), spline, pchip etc.

Dev-iL
  • 23,742
  • 7
  • 57
  • 99