【多项式f(x)=a(1)*X^m+…+a(m)*X+a(m+1)拟合】
x=[];
y=[];
A=polyfit(x,y,m) %m为猜测的拟合多项式的系数
z=polyval(A,x);
plot(x,y,'+',x,z) %画出拟合曲线,描出已知点
【非线性拟合lsqcurvefit】
建立M文件:
function f=curvefun1(x,xdata)
f=x(1)+x(2)*exp(x(3)*xdata)
%x(1)=a;x(2)=b;x(3)=k;
主程序:
xdata=[];或者xmin:n:xmax; %已知x的数据
ydata=[]; %已知y的数据
x0=[a0,b0,k0]; %a0,b0,k0分别为迭代初始值
x=lsqcurvefit ('curvefun1',x0,xdata,ydata)
f=curvefun1(x,xdata)
【非线性拟合lsqnonlin】
建立M文件:
function f=curvefun2(x)
xdata=[];或者xmin:n:xmax; %已知x的数据
ydata=[]; %已知y的数据
f=x(1)+x(2)*exp(x(3)*xdata)- ydata
%x(1)=a;x(2)=b;x(3)=k;
【求曲线交点】
[x,y]=solve('y=-0.0259*x^2+0.4631*x+0.0315','y=0.2*x^2-5.5059*x+38.9763')
【求积分】
int(P) 对表达式P进行不定积分.
int(P,v) 以v为积分变量对P进行不定积分.
int(P,v,a,b) 以v为积分变量,以a为下限,b为上限对P进行定积分.
int('x*log(1+x)',0,1) 得
ans = 1/4
主程序:
x0=[a0,b0,k0]; %a0,b0,k0分别为迭代初始值
x=lsqnonlin('curvefun2',x0)
f=curvefun2(x)
【拟合判断】
SSE (趋向0最好)-- The sum of squares due to error. This statistic measures the deviation of the responses from the fitted values of the responses. A value closer to 0 indicates a better fit.
R-square(趋向1最好) -- The coefficient of multiple determination. This statistic measures how successful the fit is in explaining the variation of the data. A value closer to 1 indicates a better fit.
Adjusted R-square(趋向1最好) -- The degree of freedom adjusted R-square. A value closer to 1 indicates a better fit. It is generally the best indicator of the fit quality when you add additional coefficients to your model.
RMSE(趋向0最好) -- The root mean squared error. A value closer to 0 indicates a better fit.