function [yucezhi]=hs(data,cishu)
data=[195821.88 184039.60 203143.59 206044.36 215879.79 209281.31 212024.50 209429.16 196409.18 197450.76 178736.91 198378.23];
cishu=12;
[MM,NN]=size(data);
A=data;
B=A;
ZZ=zeros(MM,cishu);
for jj=1:cishu
c=zeros(2,1);
for j=1:MM
B=cumsum(A(j,:));
n=length(A(j,:));
for i=1:(n-1)
C(i)=(B(i)+B(i+1))/2;
end
D=A(j,:);D(1)=[];
D=D';
E=[-C;ones(1,n-1)];
c=inv(E*E')*E*D;
c=c';
a=c(1);b=c(2);
F=[];F(1)=A(1);
for i=2:n
F(i)=(A(j,1)-b/a)/exp(a*(i-1))+b/a;
end
G=[];G(j,1)=A(j,1);
for i=2:n
G(j,i)=F(i)-F(i-1);
end
for k=1:1:n%
H(k,1)=exp(-a*(k-1));
H(k,2)=1;
end
Z=inv(H'*H)*H'*F';
A1=Z(1);
B1=Z(2);
WW(j)=(1-exp(a)) *A1;
for k=1:n+1
y(j,k)=WW(j)*exp(-a*k);
end
end
y;
yy=y;
y(:,n+1)=[];
Y=A./y;
YY=yy(:,n+1);
for kk=1:MM
nn=3;
g(1)=min(Y(kk,:)); g(4)=max(Y(kk,:));
ch=(g(4)-g(1))/nn;g(2)=g(1)+ch;g(3)=g(2)+ch;
[h cd]=size(Y);
for i=1:cd
if Y(kk,i)<g(2);
BB(kk,i)=1;
elseif Y(kk,i)<g(3);
BB(kk,i)=2;
else Y(kk,i)<g(4);
BB(kk,i)=3;
end
end
for k=1:3
aa=0;bb=0;cc=0;
for i=1:(cd-k)
if BB(kk,i)==1
aa=aa+1;
elseif BB(kk,i)==2
bb=bb+1;
else
cc=cc+1;
end
end
FM=[aa;bb;cc];
for j=1:3
w=0;
for i=1:(cd-k)
if BB(kk,i)==BB(kk,cd-k)&BB(kk,i+k)==j
w=w+1;
end
end
P(k,j)=w/FM(BB(kk,cd-k),:);
end
end
Q=sum(P,1);
wz=find(Q==max(Q));
y1(kk)=((g(wz(1))+g(wz(1)+1))/2);
end
y1;
yyy=y1'.*YY ; %最终预测值
ZZ(:,jj)=yyy;
A=[A yyy];
end
yucezhi=ZZ;
end
matlab仿真不出来,求大神教教我,谢谢了
答案:3 悬赏:10 手机版
解决时间 2021-02-21 04:26
- 提问者网友:未信
- 2021-02-20 14:49
最佳答案
- 五星知识达人网友:冷風如刀
- 2021-02-20 15:16
你是在定义函数,不是在运行程序,明白他们之间的区别!而且函数定义格式是
function yucezhi=hs(data,cishu);
把程序里面的数据和次数值那几行都删掉,再写一个m文件调用
调用格式是aa=hs(data,cishu);
这是函数文件,保存名应该是函数名hs
function yucezhi=hs(data,cishu)
[MM,NN]=size(data);
A=data;
B=A;
ZZ=zeros(MM,cishu);
for jj=1:cishu
c=zeros(2,1);
for j=1:MM
B=cumsum(A(j,:));
n=length(A(j,:));
for i=1:(n-1)
C(i)=(B(i)+B(i+1))/2;
end
D=A(j,:);D(1)=[];
D=D';
E=[-C;ones(1,n-1)];
c=inv(E*E')*E*D;
c=c';
a=c(1);b=c(2);
F=[];F(1)=A(1);
for i=2:n
F(i)=(A(j,1)-b/a)/exp(a*(i-1))+b/a;
end
G=[];G(j,1)=A(j,1);
for i=2:n
G(j,i)=F(i)-F(i-1);
end
for k=1:1:n%
H(k,1)=exp(-a*(k-1));
H(k,2)=1;
end
Z=inv(H'*H)*H'*F';
A1=Z(1);
B1=Z(2);
WW(j)=(1-exp(a)) *A1;
for k=1:n+1
y(j,k)=WW(j)*exp(-a*k);
end
end
y;
yy=y;
y(:,n+1)=[];
Y=A./y;
YY=yy(:,n+1);
for kk=1:MM
nn=3;
g(1)=min(Y(kk,:)); g(4)=max(Y(kk,:));
ch=(g(4)-g(1))/nn;g(2)=g(1)+ch;g(3)=g(2)+ch;
[h cd]=size(Y);
for i=1:cd
if Y(kk,i)<g(2);
BB(kk,i)=1;
elseif Y(kk,i)<g(3);
BB(kk,i)=2;
else Y(kk,i)<g(4);
BB(kk,i)=3;
end
end
for k=1:3
aa=0;bb=0;cc=0;
for i=1:(cd-k)
if BB(kk,i)==1
aa=aa+1;
elseif BB(kk,i)==2
bb=bb+1;
else
cc=cc+1;
end
end
FM=[aa;bb;cc];
for j=1:3
w=0;
for i=1:(cd-k)
if BB(kk,i)==BB(kk,cd-k)&BB(kk,i+k)==j
w=w+1;
end
end
P(k,j)=w/FM(BB(kk,cd-k),:);
end
end
Q=sum(P,1);
wz=find(Q==max(Q));
y1(kk)=((g(wz(1))+g(wz(1)+1))/2);
end
y1;
yyy=y1'.*YY ; %最终预测值
ZZ(:,jj)=yyy;
A=[A yyy];
end
yucezhi=ZZ;
end
调用格式是另外一个m文件:可以这么写
clc,clear
data=[195821.88 184039.60 203143.59 206044.36 215879.79 209281.31 212024.50 209429.16 196409.18 197450.76 178736.91 198378.23];
cishu=12;
yuce=hs(data,cishu)
应该没有问题了,建议你多看Matlab定义函数与运行程序的区别,重在理解。
function yucezhi=hs(data,cishu);
把程序里面的数据和次数值那几行都删掉,再写一个m文件调用
调用格式是aa=hs(data,cishu);
这是函数文件,保存名应该是函数名hs
function yucezhi=hs(data,cishu)
[MM,NN]=size(data);
A=data;
B=A;
ZZ=zeros(MM,cishu);
for jj=1:cishu
c=zeros(2,1);
for j=1:MM
B=cumsum(A(j,:));
n=length(A(j,:));
for i=1:(n-1)
C(i)=(B(i)+B(i+1))/2;
end
D=A(j,:);D(1)=[];
D=D';
E=[-C;ones(1,n-1)];
c=inv(E*E')*E*D;
c=c';
a=c(1);b=c(2);
F=[];F(1)=A(1);
for i=2:n
F(i)=(A(j,1)-b/a)/exp(a*(i-1))+b/a;
end
G=[];G(j,1)=A(j,1);
for i=2:n
G(j,i)=F(i)-F(i-1);
end
for k=1:1:n%
H(k,1)=exp(-a*(k-1));
H(k,2)=1;
end
Z=inv(H'*H)*H'*F';
A1=Z(1);
B1=Z(2);
WW(j)=(1-exp(a)) *A1;
for k=1:n+1
y(j,k)=WW(j)*exp(-a*k);
end
end
y;
yy=y;
y(:,n+1)=[];
Y=A./y;
YY=yy(:,n+1);
for kk=1:MM
nn=3;
g(1)=min(Y(kk,:)); g(4)=max(Y(kk,:));
ch=(g(4)-g(1))/nn;g(2)=g(1)+ch;g(3)=g(2)+ch;
[h cd]=size(Y);
for i=1:cd
if Y(kk,i)<g(2);
BB(kk,i)=1;
elseif Y(kk,i)<g(3);
BB(kk,i)=2;
else Y(kk,i)<g(4);
BB(kk,i)=3;
end
end
for k=1:3
aa=0;bb=0;cc=0;
for i=1:(cd-k)
if BB(kk,i)==1
aa=aa+1;
elseif BB(kk,i)==2
bb=bb+1;
else
cc=cc+1;
end
end
FM=[aa;bb;cc];
for j=1:3
w=0;
for i=1:(cd-k)
if BB(kk,i)==BB(kk,cd-k)&BB(kk,i+k)==j
w=w+1;
end
end
P(k,j)=w/FM(BB(kk,cd-k),:);
end
end
Q=sum(P,1);
wz=find(Q==max(Q));
y1(kk)=((g(wz(1))+g(wz(1)+1))/2);
end
y1;
yyy=y1'.*YY ; %最终预测值
ZZ(:,jj)=yyy;
A=[A yyy];
end
yucezhi=ZZ;
end
调用格式是另外一个m文件:可以这么写
clc,clear
data=[195821.88 184039.60 203143.59 206044.36 215879.79 209281.31 212024.50 209429.16 196409.18 197450.76 178736.91 198378.23];
cishu=12;
yuce=hs(data,cishu)
应该没有问题了,建议你多看Matlab定义函数与运行程序的区别,重在理解。
全部回答
- 1楼网友:千夜
- 2021-02-20 15:53
234W V3Y B6R57UIO ,I[0][
- 2楼网友:风格不统一
- 2021-02-20 15:29
楼主知道这个程序的详细意思吗。。。。。
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯