作业帮 > 综合 > 作业

matlab指数拟合:

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/07/20 06:17:24
matlab指数拟合:
设通过测量得到时间t与变量y的数据:
t=[0 0.3 0.8 1.1 1.6 2.3];
y=[0.5 0.82 1.14 1.25 1.35 1.41];
分别采用多项式:y=a0+a1t+a2t2
和指数函数 y=b0+b1e^t+b2te^t
进行拟合,并计算均方误差、画出拟合效果图进行比较.
t=[0 0.3 0.8 1.1 1.6 2.3];
y=[0.5 0.82 1.14 1.25 1.35 1.41];
[p1,s1]=polyfit(t,y,2);
s1=s1.normr;
p2=[ones(length(t),1) exp(t)' t'.*exp(t')]\y';
s2=norm([ones(length(t),1) exp(t)' t'.*exp(t')]*p2-y');
t1=0:0.1:2.3;
y1=polyval(p1,t1);
y2=[ones(length(t1),1) exp(t1)' t1'.*exp(t1')]*p2;
plot(t,y,'-*',t1,y1,t1,y2)
legend('原数据','多项式','指数')