最小二乘拟合 matlab算法程序!
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/23 21:10:43
最小二乘拟合 matlab算法程序!
最小二乘拟合 matlab算法程序!
最小二乘拟合 matlab算法程序!
原贴请看:
>> clear
>> f=inline('a(1)*x+a(2)*x.^2.*exp(-a(3)*x)+a(4)','a','x');
x=[0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1];
y=[2.3201 2.6470 2.9707 3.2885 3.6008 3.9090 4.2147 4.5191 4.8232 5.1275];
[xx,res]=lsqcurvefit(f,ones(1,4),x,y);
xx',res
要建立也是可以的.就是把上面那个inline弄成.m
如下:
在Matlab下输入:edit zhidao_15.m,然后将下面两行百分号之间的内容,复制进去,保存
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function y=zhidao_15(a,x)
y=a(1)*x+a(2)*x.^2.*exp(-a(3)*x)+a(4);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
在Matlab下面输入:
x=[0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1];
y=[2.3201 2.6470 2.9707 3.2885 3.6008 3.9090 4.2147 4.5191 4.8232 5.1275];
[xx,res]=lsqcurvefit('zhidao_15',ones(1,4),x,y);
xx',res