Why is this polynomial equation badly conditioned?

爷,独闯天下 提交于 2019-12-02 07:17:11

The problem can be attributed to the type of coefficient matrix that polyfit builds from the x vector: a Vandermonde matrix.

When

  • the elements of the x vector vary too much in magnitude, and
  • the degree of the fitting polynomial is too high,

you get an ill-conditioned matrix, and the associated linear system cannot be solved reliably.

Try to centre and scale your x vector first, before applying polyfit, as advised at the bottom of the polyfit help page:

Since the columns in the Vandermonde matrix are powers of the vector x, the condition number of V is often large for high-order fits, resulting in a singular coefficient matrix. In those cases centering and scaling can improve the numerical properties of the system to produce a more reliable fit.

(my emphasis)

The warning is because the data that you are supplying to polyfit with your desired degree of polynomial isn't suitable. Specifically, there is an insufficient amount of variability in your data so that you can successfully achieve a good fit. Therefore, MATLAB gives you that warning because the data can't be fit properly with your desired degree polynomial.

The solution to this is to either get more points so that you can get the desired fit of the polynomial degree you want or to decrease the degree of polynomial you want.

Try values that are less than 5... 4, 3 or perhaps 2:

coeff = polyfit(x, y, 4);
%// or
%coeff = polyfit(x, y, 3);
%coeff = polyfit(x, y, 2);

Try each degree until you don't get the warning anymore. However, without the actual data, I can only speculate what's wrong, and this is my best guess.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!