问题描述:
matlab 时间序列模型求解
yt=[101.5 102.7 102.4 102.8 103.1 102.9 103.3 103.5 103.6 104.4 105.1 104.6 104.9 104.9 105.4 105.3 105.5 106.4 106.5]
n=length(yt);
alpha=0.2; st1(1)=yt(1); st2(1)=yt(1);
for i=2:n
st1(i)=alpha*yt(i)+(1-alpha)*st1(i-1)
st2(i)=alpha*st1(i)+(1-alpha)*st2(i-1)
end
%xlswrite('cpi2.xls',[st1',st2'])
a=2*st1-st2
b=alpha/(1-alpha)*(st1-st2)
yhat=a+b
%xlswrite('cpi2.xls',yhat','Sheet1','C2')
str=char(['C',int2str(n+2)]);
c=a(n)+b(n)
z=yhat-yt
plot(1:n,yt,'*',1:n,yhat(1:n),'O')
legend('实际值','预测值',2)
将这段代码中的yt=[101.5 102.7 102.4 102.8 103.1 102.9 103.3
103.5 103.6 104.4 105.1 104.6 104.9 104.9 105.4
105.3 105.5 106.4 106.5]改为yt=[102.7 104.0 103.2 104.9 105.0 104.7 106.1 106.5 105.9 104.1 103.7 102.7 104.1】即把19个数据改为13个数据,需要改其他地方的什么代码才能成功运行?
yt=[101.5 102.7 102.4 102.8 103.1 102.9 103.3 103.5 103.6 104.4 105.1 104.6 104.9 104.9 105.4 105.3 105.5 106.4 106.5]
n=length(yt);
alpha=0.2; st1(1)=yt(1); st2(1)=yt(1);
for i=2:n
st1(i)=alpha*yt(i)+(1-alpha)*st1(i-1)
st2(i)=alpha*st1(i)+(1-alpha)*st2(i-1)
end
%xlswrite('cpi2.xls',[st1',st2'])
a=2*st1-st2
b=alpha/(1-alpha)*(st1-st2)
yhat=a+b
%xlswrite('cpi2.xls',yhat','Sheet1','C2')
str=char(['C',int2str(n+2)]);
c=a(n)+b(n)
z=yhat-yt
plot(1:n,yt,'*',1:n,yhat(1:n),'O')
legend('实际值','预测值',2)
将这段代码中的yt=[101.5 102.7 102.4 102.8 103.1 102.9 103.3
103.5 103.6 104.4 105.1 104.6 104.9 104.9 105.4
105.3 105.5 106.4 106.5]改为yt=[102.7 104.0 103.2 104.9 105.0 104.7 106.1 106.5 105.9 104.1 103.7 102.7 104.1】即把19个数据改为13个数据,需要改其他地方的什么代码才能成功运行?
问题解答:
我来补答展开全文阅读