辽宁工程技术大学上机实验
报告
(2)取定t0=1790,拟合待定参数x0和r;
程序代码:
>> p=@(r,t)r(2).*exp(r(1).*(t-1790));
>> t=1790:10:2000;
>> c=[,,,,,,,,,
,,,,,,,,,,,,];
>> r0=[,];
>> r=nlinfit(t,c,p,r0);
>> sse=sum((c-p(r,t)).^2);
>> plot(t,c,'b*',1790:1:2000,p(r,1790:1:2000),'b') >> axis([1790,2000,0,290])
>> xlabel('年份'),ylabel('人口(单位:百万)') >> title('拟合美国人口数据-指数增长型')
>> legend('拟合数据')
程序调用:
>> r r =
>> sse sse = +003
(3)拟合待定参数t0, x0和r.要求写出程序,给出拟合参数和误差平方和的计算结果,并展示误差平方和最小的拟合效果图.
程序代码:
>> p=@(r,t)r(2).*exp(r(1).*(t-1790+1.*r(3)));
>> t=1790:10:2000;
>> c=[,,,,,,,,,
,,,,,,,,,,,,];
>> r0=[,,1];
>> [r,x]=nlinfit(t,c,p,r0);
>> sse=sum((c-p(r,t)).^2);
>> a=1790+1.*r(3);
>> subplot(2,1,1)
>> plot(t,c,'b*',1790:1:2000,p(r,1790:1:2000),'b')
>> axis([1790,2000,0,290])
>> xlabel('年份'),ylabel('人口(单位:百万)')
>> title('拟合美国人口数据-指数增长型')
>> legend('拟合数据')
>> subplot(2,1,2)
>> plot(t,x,'k+',[1790:2000],[0,0],'k')
>> axis([1790,2000,-20,20])
>> xlabel('年份'),ylabel('人口(单位:百万)')
>> title('拟合误差')
程序调用:
>> r r =
>> x x =
Columns 1 through 5
Columns 6 through 10
Columns 11 through 15
Columns 16 through 20
Columns 21 through 22
>> sse sse = +003
>> a a = +003
2、通过变量替换,可以将属于非线性模型的指数增长模型转化成线性模型,并用Matlab函数polyfit进行计算,请说明转化成线性模型的详细过程,然后写出程序,给出拟合参数和误差平方和的计算结果,并展示拟合效果图.
非线性模型的指数增长模型转化成线性模型
程序代码:
>> t=1790:10:2000;
>>c=[,,,,,,,,,,,,,,,,,,,,,];
Columns 9 through 12
Columns 13 through 16
Columns 17 through 20
Columns 21 through 22
c2 = +004
3、请分析指数增长模型非线性拟合和线性化拟合的结果有何区别原因是什么
非线性拟合
线性拟合
4、如果用阻滞增长模型00
()
00()()e r t t Nx x t x N x --=
+-模拟美国人口1790年至
2000年的变化过程,请用Matlab 统计工具箱的函数nlinfit 计算阻滞增长的以下三个数据拟合问题:
(1)取定x 0=, t 0=1790,拟合待定参数r 和N ; 程序代码:
>> p=@(a,t)(a(2).*./+(a(2).*exp(-a(1).*(t-1790))); >> t=1790:10:2000;
>> c=[,,,,,,,,,,,,,,,,,,,,,]; >> a=nlinfit(t,c,p,[,350]) >> sse=sum((c-p(a,t)).^2) >> plot(t,c,'r*',t,p(a,t),'r') >> axis([1790,2000,0,300])
>> xlabel('年份'),ylabel('人口(单位:百万)') >> title('拟合美国人口数据—阻滞增长型') >> legend('拟合数据') 程序调用: a = sse = +003
(2)取定t0=1790, 拟合待定参数x0, r和N;
程序代码:
>> p=@(a,t)(a(2).*a(3))./(a(3)+(a(2)-a(3)).*exp(-a(1).*(t-1790)));
>> t=1790:10:2000;
>> c=[,,,,,,,,,,,,,,,,,,,,,];
>> a=nlinfit(t,c,p,[,350,])
>> sse=sum((c-p(a,t)).^2)
>> plot(t,c,'r*',t,p(a,t),'r')
>> axis([1790,2000,0,300])
>> xlabel('年份'),ylabel('人口(单位:百万)')
>> title('拟合美国人口数据—阻滞增长型')
>> legend('拟合数据')
程序调用:
a =
sse =
(3)拟合待定参数t0,x0,r和N.要求写出程序,给出拟合参数和误差平方和的计算结果,并展示误差平方和最小的拟合效果图.
>>
p=@(a,t)(a(2).*a(3))./(a(3)+(a(2)-a(3)).*exp(-a(1).*(t-1790+1*a(4)))) ;
>> t=1790:10:2000;
>> c=[,,,,,,,,,,,,,,,,,,,,,];
>> [a,x]=nlinfit(t,c,p,[,350,,10])
>> sse=sum((c-p(a,t)).^2)
>> t0=1790+1*a(4)
>> subplot(2,1,1)
>> plot(t,c,'r*',t,p(a,t),'r')
>> axis([1790,2000,0,300])
>> xlabel('年份'),ylabel('人口(单位:百万)')
>> title('拟合美国人口数据—阻滞增长型')
>> legend('拟合数据')
教师评语。