clc,clear
%根据问题更改
yt=[3.36,3.34,3.53,3.51,3.38,3.34,3.36,3.23,3.19,3.17,2.92,2.81]; n=length(yt);
sub=0;
for alpha=0.1:0.1:0.3
sub=sub+1;
st1_0=mean(yt(1:3)); st2_0=st1_0;st3_0=st1_0;
st1(1)=alpha*yt(1)+(1-alpha)*st1_0;
st2(1)=alpha*st1(1)+(1-alpha)*st2_0;
st3(1)=alpha*st2(1)+(1-alpha)*st3_0;
for i=2:n
st1(i)=alpha*yt(i)+(1-alpha)*st1(i-1);
st2(i)=alpha*st1(i)+(1-alpha)*st2(i-1);
st3(i)=alpha*st2(i)+(1-alpha)*st3(i-1);
end
a=3*st1-3*st2+st3;
b=0.5*alpha/(1-alpha)^2*((6-5*alpha)*st1-2*(5-4*alpha)*st2+(4-3*alpha)*st3);
c=0.5*alpha^2/(1-alpha)^2*(st1-2*st2+st3);
yhat=a+b+c;
subplot(1,3,sub)
plot(1:n,yt,1:n,yhat(1:n))
legend('Actual','Forecast')
disp(1/n*sum((yt-yhat(1:n)).^2))
disp(yhat)
end
来源:CSDN
作者:Ruanes
链接:https://blog.csdn.net/Ruanes/article/details/104246538