紧急:用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];拟
来源:学生作业帮助网 编辑:六六作业网 时间:2025/01/11 09:49:13
紧急:用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),结果点都在拟合的曲线的下面,谁能帮我找出毛病并修改一下?
并写出答案的结果
紧急:用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];拟
呵呵,还需要转换一次啊.及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
y1要取指数吧!
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...
全部展开
y1要取指数吧!
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)
p =
0.0147 -26.7773
>> y1=polyval(p,x);
>> y1
y1 =
Columns 1 through 12
2.1575 2.1722 2.1869 2.2015 2.2162 2.2309 2.2456 2.2603 2.2749 2.2896 2.3043 2.3190
Columns 13 through 20
2.3337 2.3483 2.3630 2.3777 2.3924 2.4071 2.4217 2.4364
>> y2=exp(y1)
y2 =
Columns 1 through 12
8.6494 8.7773 8.9071 9.0389 9.1725 9.3082 9.4458 9.5855 9.7273 9.8711 10.0171 10.1653
Columns 13 through 20
10.3156 10.4681 10.6229 10.7800 10.9395 11.1012 11.2654 11.4320
>> plot(x,y,'o',x,y2)
收起