误差分析
实际数据 49 61 78 96 104 Matlab程序如下
clc,clear
模拟数据 51.0148 63.1412 77.2111 92.1548 104.4780 残差 -2.0148 -2.1412 0.7889 3.8452 -0.4780 相对误差 0.0411 0.0351 0.0101 0.0401 0.0046 x0=[41,49,61,78,96,104]; n=length(x0);
x1=cumsum(x0) %x1为累加数列 a_x0=diff(x0);
a_x0=[0,a_x0] % a_x0为累减数列 for i=2:n
z(i)=0.5*(x1(i)+x1(i-1)); end
B=[-x0(2:end)',-z(2:end)',ones(n-1,1)]; Y=a_x0(2:end)'; u=B\\Y ?,a2,b的值
x=dsolve('D2x+a1*Dx+a2*x=b','x(0)=c1,x(5)=c2');
x=subs(x,{'a1','a2','b','c1','c2'},{u(1),u(2),u(3),x1(1),x1
(6)});
yuce=subs(x,'t',0:n-1);
digits(6),x=vpa(x) %x为时间响应式 x0_hat=[yuce(1),diff(yuce)] %预测的数据 epsilon=x0-x0_hat %计算残差 delta=abs(epsilon./x0) %计算相对误差
7.波形预测模型
上海证券交易所综合指数的波形预测。
根据上海证券交易所综合指数的周收盘指数数据,从1997年2月21日到1998年10月31日的
周收盘指数曲线如图所示: 解:
取9条等间隔的等高线,分别为
?1=1140,?2=1170,?3=1200,?4=1230,?5=1260,?6=1290,?7=1320,?8=1350,
?9=1380
?i的等高时刻序列分别为
对应于?1=1140,
Q1(0)=(4.4,31.7,34.2,41,42.4,76.8,78.3)
对应于?2=1170,
(0)Q2=(5.2,19.8,23,25.6,26.9,31.2,34.8,39.5,44.6,76,76.2,79.2)
对应于?3=1200,?4=1230,?5=1260,?6=1290,?7=1320,?8=1350,?9=1380
分别为
Q3(0)=(5.9,19.5,24.8,25.2,26.5,30.3,46.2,53.4,55.4,75.5,79.7)
(0)Q4=(6.5,19.2,28.3,29.5,49.7,50.8,56.2,76.4,82.9,85)
Q5(0)=(7,14.2,16.4,16.5,18.8,56.7,75.2) Q6(0)=(8.3,13.4,16.9,56.2,74.6) Q7(0)=(8.8,12.8,60.2,71.8,72.7,73.6) Q8(0)=(9.6,12.5,61.8,69.8,70.9,71.8) Q9(0)=(10.8,12.4,64.1,69)
对Qi(0)(i=1,2,3,…9)序列,进行GM(1,1)预测,起响应时分别为
y1=-109.738+114.138*exp(0.214831*t)
y2=-94.0581+99.2581*exp(0.158430*t) y3=-94.6529+100.553*exp(.166865*t)
y4=-145.162+151.662*exp(.159938*t) y5=-3.68695+10.6869*exp(.446077*t) y6=-12.1881+20.4881*exp(.550388*t) y7=-176.276+185.076*exp(.191636*t)
y8=-182.496+192.096*exp(.185059*t) y9=-34.6983+45.4983*exp(.488018*t)
对在1998年11月到2000年3月这5个月进行预测,可得?等高时刻的预测序列 Q1=(99.3,123.1)
?(0) Q2=(97.3,114.1,133.6) Q3=(96.9,114.5,135.2) Q4=(110.9,130.2,152.8) Q5=(87.3,136.4) Q6=(135.9)
Q7=(101.9,123.4,149.5) Q8=(98.5,118.5,142.6) Q9=(123.7)
据此可以画出上海证券交易所综合指数1998年11月到2000年3月的预测波形图 如下
?(0)?(0)?(0)?(0)?(0)?(0)?(0)?(0)
Matlab程序如下: %GM(1,1)函数
function gm11(x0,t)
n=length(x0); x1=cumsum(x0);
lamda=x0(1:n-1)./x0(2:n); for i=2:n
z(i)=0.5*(x1(i)+x1(i-1)); end
B=[-z(2:n)',ones(n-1,1)]; Y=x0(2:n)';
u=B\\Y;
x=dsolve('Dx+a*x=b','x(0)=x0');
x=subs(x,{'a','b','x0'},{u(1),u(2),x1(1)}); yuce1=subs(x,'t',[0:n-1]); digits(6),y=vpa(x)
yuce1=subs(x,'t',[0:n-1+t]); yuce=[x0(1),diff(yuce1)]
%预测数据
clc,clear
x1=[4.4,31.7,34.2,41,42.4,76.8,78.3];
x2=[5.2,19.8,23,25.6,26.9,31.2,34.8,39.5,44.6,76,76.2,79.2]; x3=[5.9,19.5,24.8,25.2,26.5,30.3,46.2,53.4,55.4,75.5,79.7]; x4=[6.5,19.2,28.3,29.5,49.7,50.8,56.2,76.4,82.9,85]; x5=[7,14.2,16.4,16.5,18.8,56.7,75.2]; x6=[8.3,13.4,16.9,56.2,74.6]; x7=[8.8,12.8,60.2,71.8,72.7,73.6]; x8=[9.6,12.5,61.8,69.8,70.9,71.8]; x9=[10.8,12.4,64.1,69]; gm11(x1,4) gm11(x2,4) gm11(x3,4) gm11(x4,4) gm11(x5,4) gm11(x6,4) gm11(x7,4) gm11(x8,4) gm11(x9,4)