回 帖 发 新 帖 刷新版面

主题:[讨论][求助]matlab模拟编程_高手请进!

小妹正在自学matlab, 有问题向高手求助,先谢了!

某地区人口增长情况如下(就是说,第0年人口为1,...第80年人口为1.890):
t=[0 10 25 50 75 80]
A=[1.000 1.080 1.201 1.375 1.75 1.890]

请按照要求写出相应的程序:

1. 对N(t)=a(0)+a(1)t+a(2)t^(2)+a(3)t^3使用多项式模型(polyniminal)模拟:
(1) 使用多项式模型推导该地区第0年到第150年的人口;
(2) 绘图。将多项式模型的结果用solid red line 标注;将估计值用蓝色星号标准。要求添加相应的标题和横竖坐标名。

2. 使用polyfit函数模拟下面高阶函数的系数:
 N(t)=a(0)+a(1)t+...+a(g-1)t^(g-1)+a(g)t^g
(1)计算期为[0,150]。请写出相应的程序,要求能够计算任意阶数的相应值。
(2)对模拟值和实际值作图。
(3)当增加polynomial的阶数后发生了什么变化?

[em2][color=0000FF]0000FF[/color]

回复列表 (共1个回复)

沙发

这是第一道题的,自己解出来了,欢迎高人指点。

% the program is written for the Exl_1a
% the estimated polynomial function form is: N(t)=a_0+a_1*t+a_2*t^2+a_3*t^3+a_4*t^4
% show the estimated results in the figure

% "t" is year and "A" the population   
t=[0 10 25 50 75 85 ];
A=[1 1.08 1.201 1.475 1.750 1.890];
 
% Derive the population between 0 and 150 based on t and A
coeff=polyfit(t, A, 4);
eval_time=0:10:150;
Growth_function=polyval(coeff, eval_time);
% Plot the result of the polynomial and the measured values of the
% population in the same figure
plot(eval_time, Growth_function, 'r')
hold on
plot(t, A, '*b')
% add legend and title
legend('Result of polynominal','Measured Population')
xlabel('Year') 
ylabel('Growth rate')
title('Population')

% end of the program

我来回复

您尚未登录,请登录后再回复。点此登录或注册