如何约束polyfit系数。达到一定的精度(matlab)?

时间:2015-06-08 16:24:39

标签: matlab

我希望将多项式曲线(4 ou 5度)拟合到我的数据中。我用EXCEL做了这个,我得到的系数大约是10 ^ -13为第5个,10 ^ -9为第4个,10 ^ -5为第3个... 我想将所有系数约束为不低于10 ^ -2。曲线不适合那么好,但没关系。 如何使用polyfit函数执行此操作?

然后,从数学的角度来看。限制系数是否有意义?或者它是无用的,我最好继续使用二度polyfit(系数低于10 ^ -2)。

我之所以这样问:我正在进行一些研究,从物理角度来看,测试5度polyfit很有意思,但我不能使用低于10 ^ -2的系数。

谢谢

1 个答案:

答案 0 :(得分:1)

使用fit而不是polyfit

%What is the degree of the polynomial (quartic)
polyDegree = 4;

%This sets up the options
opts = fitoptions( 'Method', 'LinearLeastSquares' );

%All coefficients of degrees not specified between x^n and x^0 can have any value greater than 10^-2
opts.Lower = 1E-2;
opts.Upper = inf(1, polyDegree + 1);

%Do the fit using the specified polynomial degree.
[fitresult, gof] = fit( x, y, ['poly', num2str(polyDegree)] , opts );