(以下转自水母)
是*lll*同学给出的一个总结。 *
*向*lll*表示感谢。 *
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*
*%只考虑线性拟合*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*%原始数据 *
t = [0 .3 .8 1.1 1.6 2.3]';
y = [0.5 0.82 1.14 1.25 1.35 1.40]';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*%多项式拟合 *
p=polyfit(t,y,2)
%利用左除
X = [ones(size(t)) t t.^2];
a = X\y
%regress函数
X = [ones(size(t)) t t.^2];
*这是*lll*同学给出的一个总结。 *
*向*lll*表示感谢。 *
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*
*%只考虑线性拟合*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*%原始数据 *
t = [0 .3 .8 1.1 1.6 2.3]';
y = [0.5 0.82 1.14 1.25 1.35 1.40]';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*%多项式拟合 *
p=polyfit(t,y,2)
%利用左除
X = [ones(size(t)) t t.^2];
a = X\y
%regress函数
X = [ones(size(t)) t t.^2];
b=regress(y,X)
%lsqcurvefit函数
fun=inline('x(1)*t.^2+x(2)*t+x(3)','x','t');
x=lsqcurvefit(fun,[0,0,0],t,y)
%Curve Fitting Toolbox
fit1= fit(t,y,'poly2')
%Curve Fitting Toolbox(自定义多项式)
mymodel = fittype('a*t^2+b*t+c','independent','t');
%mymodel = fittype('a*x^2+b*x+c');
fit1= fit(t,y,mymodel,'start',[0,0,0])
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%指数形式的拟合
X = [ones(size(t)) exp(-t) t.*exp(-t)];
a = X\y
%lsqcurvefit函数
fun=inline('x(1)+x(2)*exp(-t)+x(3).*t.*exp(-t)','x','t');
x=lsqcurvefit(fun,[0,0,0],t,y)
%Curve Fitting Toolbox
mymodel = fittype('a+b*exp(-t)+c*t*exp(-t)','independent','t');
%mymodel = fittype('a+b*exp(-x)+c*x*exp(-x)');
fit1= fit(t,y,mymodel,'start',[0,0,0])
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%不含常数项的多项式拟合
%利用左除
X = [t t.^2];
a = X\y
%regress函数
X = [t t.^2];
b=regress(y,X)
%lsqcurvefit函数
fun=inline('x(1)+x(2)*exp(-t)+x(3).*t.*exp(-t)','x','t');
x=lsqcurvefit(fun,[0,0,0],t,y)
%Curve Fitting Toolbox
mymodel = fittype('a+b*exp(-t)+c*t*exp(-t)','independent','t');
%mymodel = fittype('a+b*exp(-x)+c*x*exp(-x)');
fit1= fit(t,y,mymodel,'start',[0,0,0])
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%不含常数项的多项式拟合
%利用左除
X = [t t.^2];
a = X\y
%regress函数
X = [t t.^2];
b=regress(y,X)
|