早教吧 育儿知识 作业答案 考试题库 百科 知识分享

紧急:用matlab中的最小二乘法拟合指数函数(人口问题)t=[1971:1:1990];y=[8.5229 8.7177 8.9221 9.0859 9.2420 9.3717 9.4974 9.6259 9.7542 9.8705 10.0072 10.1654 10.3008 10.4357 10.5851 10.7507 10.9300 11.1026 11.2704 11.4333];拟

题目详情
紧急:用matlab中的最小二乘法拟合指数函数(人口问题)
t=[1971:1:1990];
y=[8.5229 8.7177 8.9221 9.0859 9.2420 9.3717 9.4974 9.6259 9.7542 9.8705 10.0072 10.1654 10.3008 10.4357 10.5851 10.7507 10.9300 11.1026 11.2704 11.4333];
拟合曲线y=exp(a*t+b)
希望您上机操作一下,给出具体的编写程序.
x=[1971:1990];
y=[8.5229 8.7177 8.9221 9.0859 9.2420 9.3717 9.4974 9.6259 9.7542 9.8705 10.0072 10.1654 10.3008 10.4357 10.5851 10.7507 10.9300 11.1026 11.2704 11.4333];
z=log(y);
p=polyfit(x,z,1)
y1=polyval(p,x);
由此程序求得y1=exp(0.0147*x-26.7773)
再绘图plot(x,y,'o',x,y1),结果点都在拟合的曲线的下面,谁能帮我找出毛病并修改一下?
并写出答案的结果
▼优质解答
答案和解析
呵呵,还需要转换一次啊.及y1=exp(z1)
clear all
x=[1971:1990];
y=[8.5229 8.7177 8.9221 9.0859 9.2420 9.3717 9.4974 9.6259 9.7542 9.8705 10.0072 10.1654 10.3008 10.4357 10.5851 10.7507 10.9300 11.1026 11.2704 11.4333];
fun=inline('exp(a(1)*t+a(2))','a','t')
a=nlinfit(x,y,fun,[0.01 -20])
xx=1970:1990;
yy=exp(a(1)*xx+a(2));
plot(x,y,'o',xx,yy)
z=log(y);
p=polyfit(x,z,1)
z1=polyval(p,x);
y1=exp(z1);
figure
plot(x,y,'*',x,y1)
结果:
a =
0.014631 -26.68
p =
0.01468 -26.777