好文档 - 专业文书写作范文服务资料分享网站

(建议下载)时间序列MATLAB程序

天下 分享 时间: 加入收藏 我要投稿 点赞

时间序列

移动平均法

百度文库爱是看得见萨科技的沃尔克我去额咳咳,省得麻烦迫切

clc,clear

y=[533.8 574.6 606.9 649.8 705.1 772.0 816.4 892.7 963.9 1015.1 1102.7];

m=length(y); n=[4,5]; %n为移动平均的项数for i=1:length(n) %由于n的取值不同,下面使用了细胞数组 for j=1:m-n(i)+1

yhat{i}(j)=sum(y(j:j+n(i)-1))/n(i); end

y12(i)=yhat{i}(end); %提出第12月份的预测值 s(i)=sqrt(mean((y(n(i)+1:end)-yhat{i}(1:end-1)).^2)); %求预测的标准误差end

y12, s %分别显示两种方法的预测值和预测的标准误差

指数平滑

一次指数平滑

程序:

clc,clear

yt=load('dianqi.txt'); %读取dianqi.txt的数据,n=length(yt); %求yt的长度

alpha=[0.2 0.5 0.8]; %输入a的值m=length(alpha)

yhat(1,[1:m])=(yt(1)+yt(2))/2; %求第一个预测值 索引for i=2:n yhat(i,:)=alpha*yt(i-1)+(1-alpha).*yhat(i-1,:);

百度文库爱是看得见萨科技的沃尔克我去额咳咳,省得麻烦迫切end

yhat %求预测值

err=sqrt(mean((repmat(yt,1,m)-yhat).^2)) %求预测的标准误差

xlswrite('dianqi.xls',yhat) %把预测数据写到Excel文件,准备在word表格中使用yhat1988=alpha*yt(n)+(1-alpha).*yhat(n,:) %求1988的预测值

二次指数平滑

百度文库爱是看得见萨科技的沃尔克我去额咳咳,省得麻烦迫切 程序

clc,clear

yt=load('c:\\Users\\asus\\Desktop\\剑魔\\fadian.txt'); %原始发电总量数据以列向量的方式存放在纯文本文件中n=length(yt);alpha=0.3;

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('fadian.xls',[st1',st2']) %把数据写入表单Sheet1中的前两列at=2*st1-st2;

bt=alpha/(1-alpha)*(st1-st2);

yhat=at+bt; %最后的一个分量为1986年的预测值

xlswrite('fadian.xls',yhat','Sheet1','C2') %把预测值写入第3列str=['C',int2str(n+2)]; %准备写1987年预测值位置的字符串

xlswrite('fadian.xls',at(n)+2*bt(n),'Sheet1',str)%把1987年预测值写到相应位置

yt=load('c:\\Users\\asus\\Desktop\\剑魔\\fadian.txt'); %原始发电总量数据以列向量的方式存放在纯文本文件中n=length(yt);alpha=0.3;

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('fadian.xls',[st1',st2']) %把数据写入表单Sheet1中的前两列at=2*st1-st2;

bt=alpha/(1-alpha)*(st1-st2);

yhat=at+bt; %最后的一个分量为1986年的预测值

xlswrite('fadian.xls',yhat','Sheet1','C2') %把预测值写入第3列str=['C',int2str(n+2)]; %准备写1987年预测值位置的字符串

xlswrite('fadian.xls',at(n)+2*bt(n),'Sheet1',str)%把1987年预测值写到相应位置

百度文库爱是看得见萨科技的沃尔克我去额咳咳,省得麻烦迫切

(建议下载)时间序列MATLAB程序

时间序列移动平均法百度文库爱是看得见萨科技的沃尔克我去额咳咳,省得麻烦迫切clc,cleary=[533.8574.6606.9649.8705.1772.0816.4892.7963.91015.11102.7];m=length(y);
推荐度:
点击下载文档文档为doc格式
00jw92gi7d7e16g2f5026bod04q32p00ow2
领取福利

微信扫码领取福利

微信扫码分享