我有一个简单的问题,但我自己解决不了。我想用MATLAB的曲线拟合工具箱来拟合高阶多项式。如果我想要拟合1到9阶的多项式,它就可以工作。但是,令我惊讶的是,它不适用于次数高于9的多项式。为了简单起见,你可以看看下面的简单代码吗,不幸的是,它对我不起作用。
l=1:0.01:10;y=l.^10;
[xData, yData] = prepareCurveData(l,y);
ft = fittype( 'poly10' );
[Fit, gof] = fit( xData, yData, ft, 'Normalize', 'on' );提前谢谢你,巴巴克
发布于 2018-04-22 22:55:35
这可能会令人惊讶,但它是有文档记录的:List of Library Models for Curve and Surface Fitting。您可以始终使用polyfit,但根据它发出的警告,一旦您开始获得该次数的多项式,拟合可能无论如何都会出现问题。
发布于 2018-04-23 11:57:32
此答案是对. 的补充
函数fit中没有poly10。但至少有两种替代方法可以拟合任意次数的多项式:例如polyX,其中x可以是1,2,...,M,(如果需要的话)。
clc; clear;
%%data
l=1:0.01:10;y=l.^10;
[xData, yData] = prepareCurveData(l,y);
%%High degree polynomial fitting
%set the degree of the polunomial
Degree=10;
%Fit with customize option
%generate the cell array from 'x^Degree' to 'x^0'
syms x
Str=char(power(x,Degree:-1:0));
%set the fitting type & options, then call fit
HighPoly = fittype(strsplit(Str(10:end-3),','));
options = fitoptions('Normalize', 'off','Method','LinearLeastSquares','Robust','off');
[curve,gof] = fit(xData,yData,HighPoly,options)
%Polyfit with the degree of Degree
p = polyfit(xData,yData,Degree)但fit和polyfit都显示了一些警告,在我看来,这是由于Runge's phenomenon,这是一个区间边缘振荡的问题,当在一组等间距插值点上使用高次多项式插值时,会出现振荡问题。
丢弃这种或类似情况下的数据,在真实函数是高次多项式的情况下,在Pn[R]中说,在复杂函数的拟合中,不推荐使用高次多项式。
编辑:泛化代码。
https://stackoverflow.com/questions/49966992
复制相似问题