###### 是小狐狸啊

2017-06-12 12:10 阅读 2.5k

# MatLab 灰色预测模型预测人口数目 建模代码出错

10

``````x0=[60.2,61.5,62.8,64.6,66,67.2,66.2,65.9,67.3,69.1,70.4,72.5,74.5,76.3,78.5,80.7,83,85.2,87.1,89.2,90.9,92.4,93.7,95,96.259,97.5,98.705,100.1,101.654,103.008,104.357,105.851,107.5,109.3,111.026,112.704,114.333,115.823,117.171,118.517,119.85,121.121,122.389,123.626,124.761,125.786,126.743,127.627,128.453,129.227,129.988,130.756]';
n=length(x0)';
m=1954:2005;
lamda=x0(1:n-1)./x0(2:n)%计算级比
range=minmax(lamda')%计算级比的范围
x1=cumsum(x0);%累加运算
B=[-0.5*(x1(1:n-1)+x1(2:n)),ones(n-1,1)];
Y=x0(2:n);
u=B\Y %拟合参数u(1)=a,u(2)=b
x=dsolve('Dx+a*x=b','x(0)=x0')%求解微分方程的符号解
x=subs(x,{'a','b','x0'},{u(1),u(2),x0(1)})%带入估计参数值和初始值
yuce1=subs(x,'t',[0:n-1])%求已知数据的预测值
y=vpa(x,6)%其中的6表示显示6位数字
yuce=[x0(1),diff(yuce1)]%差分运算，还原数据
plot(m,x0,'*',m,yuce,'r')
xlabel('年份')
ylabel('年终人口总数量（千万人）')
title('每年年终人口总数目与预测值')
legend('原始值','预测值')
epsilon=x0'-yuce %计算残差
delta=abs(epsilon./x0')%计算相对误差
rho=1-(1-0.5*u(1))/(1+0.5*u(1))*lamda'%计算级比偏差值，u(1)=a
``````
• 点赞
• 写回答
• 关注问题
• 收藏
• 复制链接分享