二次移动平均法的matlab编程
来源:学生作业帮 编辑:百度作业网作业帮 分类:综合作业 时间:2024/08/18 21:11:07
二次移动平均法的matlab编程
请给出他的具体编程,或者看一下我这个程序有什么问题谢谢了~
clear
A=[1532 1645 1770 1790 1551 1840 1880 1830 1921];
[m,n]=size(A);
for i=1:1:m
for j=1:n-2
B(i,j)=A(i,j)+A(i,j+1)+A(i,j+2);
end
end
b=B/3
for i=1:1:m
for j=1:n-4
c(i,j)=b(i,j)+b(i,j+1)+b(j+2);
end
end
d=c/3
for i=1:1:m
for j=1:n-4
e(i,j)=b(i,j+2);
end
end
e;
for i=1:1:m
for j=1:n-4
f(i,j)=2*e(i,j)-d(i,j);
end
end
f
for i=1:1:m
for j=1:n-4
g(i,j)=2*(e(i,j)-d(i,j))/2;
end
end
g
请给出他的具体编程,或者看一下我这个程序有什么问题谢谢了~
clear
A=[1532 1645 1770 1790 1551 1840 1880 1830 1921];
[m,n]=size(A);
for i=1:1:m
for j=1:n-2
B(i,j)=A(i,j)+A(i,j+1)+A(i,j+2);
end
end
b=B/3
for i=1:1:m
for j=1:n-4
c(i,j)=b(i,j)+b(i,j+1)+b(j+2);
end
end
d=c/3
for i=1:1:m
for j=1:n-4
e(i,j)=b(i,j+2);
end
end
e;
for i=1:1:m
for j=1:n-4
f(i,j)=2*e(i,j)-d(i,j);
end
end
f
for i=1:1:m
for j=1:n-4
g(i,j)=2*(e(i,j)-d(i,j))/2;
end
end
g
![二次移动平均法的matlab编程](/uploads/image/z/15149404-28-4.jpg?t=%E4%BA%8C%E6%AC%A1%E7%A7%BB%E5%8A%A8%E5%B9%B3%E5%9D%87%E6%B3%95%E7%9A%84matlab%E7%BC%96%E7%A8%8B)
close all
clear,clc
% 统计数据 实际值
arr = [1532 1645 1770 1790 1551 1840 1880 1830 1921]';
[m,nn]=size(arr)
N = 2 % 步长
% 1次 平滑
s1 = zeros(m,1);
for i=N:m
s1(i) = sum(arr(i-N+1:i,:))/N;
end
sx1 = s1
% 2次 平滑
s2 = zeros(m,1);
for i=2*N-1:m
s2(i) = sum(s1(i-N+1:i,:))/N;
end
sx2 = s2
% 计算线性趋势的截距和斜率
% a = 2*m1 - m2
% b = 2/(N-1)*(m1 - m2)
a = 2*s1 - s2;
b = 2/(N-1)*(s1 - s2);
a(1:2*N-2) = 0;
b(1:2*N-2) = 0;
a
b
% 预测
% fx(t) = a(t) + b(t)*tou % fx(t+tou) = a(t) + b(t)*tou
% tou表示预测超前期数;fx(t)表示第t+tou期的预测值 % fx(t+tou)表示第t+tou期的预测值
tou1 = 1 % 超前预测1期
fx1 = a + b *tou1
tou2 = 2 % 超前预测2期
fx2 = a + b *tou2
clear,clc
% 统计数据 实际值
arr = [1532 1645 1770 1790 1551 1840 1880 1830 1921]';
[m,nn]=size(arr)
N = 2 % 步长
% 1次 平滑
s1 = zeros(m,1);
for i=N:m
s1(i) = sum(arr(i-N+1:i,:))/N;
end
sx1 = s1
% 2次 平滑
s2 = zeros(m,1);
for i=2*N-1:m
s2(i) = sum(s1(i-N+1:i,:))/N;
end
sx2 = s2
% 计算线性趋势的截距和斜率
% a = 2*m1 - m2
% b = 2/(N-1)*(m1 - m2)
a = 2*s1 - s2;
b = 2/(N-1)*(s1 - s2);
a(1:2*N-2) = 0;
b(1:2*N-2) = 0;
a
b
% 预测
% fx(t) = a(t) + b(t)*tou % fx(t+tou) = a(t) + b(t)*tou
% tou表示预测超前期数;fx(t)表示第t+tou期的预测值 % fx(t+tou)表示第t+tou期的预测值
tou1 = 1 % 超前预测1期
fx1 = a + b *tou1
tou2 = 2 % 超前预测2期
fx2 = a + b *tou2