%load trule
%clc;clear all;
load inv_NET
global percent1 percent2
global r
percent1=0.15;
percent2=-0.05;
n=24;ff=13;landa=30001.1;alfa=2.317; %操作条件
UA=9803*3.6;
Ps=0.1013;
F=100;
%Zf=0.5;
flag=1;
beta=0.75;
options=odeset('RelTol',1e-6,'AbsTol',1e-9);
X0=[0.89135 0.87175 0.84764 0.81825 0.78294 0.74141 0.69391 0.64145 0.58582 0.52937 0.47458 0.42354 0.37765 0.3323 0.28676 0.2429 0.20245 0.16661 0.13599 0.11057 0.08992 0.073403 0.060311 0.049978 0.5 0.3195];
[t,X2]=ode15s('m_dync2a',0:0.01:8.02,X0,options);%step change
Xt=X2(:,1);%save the change data of the top level of ITCDIC
Xb=X2(:,n);%save the change data of the bottom level of ITCDIC
%figure(1)
%plot(t,Xt);
%figure(2)
%plot(t,Xb,'r');
for k=150:1:length(X2)
X2(k,n+2)=0.3195*(1+percent2);
end
Pr=X2(:,n+2);
for k=150:1:length(X2)
X2(k,n+1)=0.5*(1+percent1);
end
q=X2(:,n+1);
figure(11)
plot(t,Pr,'g',t,q,'k');
Y0(1)=alfa*X0(1)/((alfa-1)*X0(1)+1);
output(:,1)=[Y0(1);X0(n)];
y(:,1)=output(:,1);%+rand(1)*10^-4;
for a=2:1:800
u(:,a+1)=[Pr(a+1);q(a+1)];%预测的输出
if a==2
X=X0;
end
if a==2
Yt(a-1)=alfa*Xt(a-1)/((alfa-1)*Xt(a-1)+1);
P_output(:,a-1)=[Yt(a-1);Xb(a-1)];
g(:,a-1)=P_output(:,a-1);
end
u(:,a)=[Pr(a);q(a)];
X(n+1)=u(2,a);
X(n+2)=u(1,a);
if a==2
[t3,X3]=ode15s('tmodel',[0,0.01*(a-1)],X,options);
else
[t3,X3]=ode15s('tmodel',[0.01*(a-2),0.01*(a-1)],X,options);
end
X=X3(length(t3),:);
Y(1)=alfa*X(1)/((alfa-1)*X(1)+1);
output(:,a)=[Y(1);X(n)];
y(:,a)=output(:,a);%+rand(1)*10^-4;
%[t,X2]=ode15s('tmodel',0.01*a:0.01:0.01*(a+1),X,options);
%X=X2(length(t),:);
%output(:,a)=[X(1);X(n)];
%y(:,a)=output(:,a)+rand(1)*10^-4;
load NET
%load datan
inputf(:,a)=[Pr(a-1);q(a-1);u(1,a);u(2,a);output(1,a-1);output(2,a-1);output(1,a);output(2,a);abs(output(1,a-1)-P_output(1,a-1));abs(output(2,a-1)-P_output(2,a-1));abs(y(1,a-1)-r(1));abs(y(2,a-1)-r(2))]; %series structure
%inputn_test=mapminmax('apply',inputf(:,a),inputps);
%an=sim(net,inputn_test);
an=sim(net,inputf(:,a));
%P_output(:,a)=mapminmax('reverse',an,outputps);
P_output(:,a)=an;
%P_output(:,a+1)=[0;0];
g(:,a)=g(:,a-1)+(1-beta)*[r(:)-y(:,a)];
input(:,a)=[Pr(a);q(a);y(1,a-1);y(2,a-1);y(1,a);y(2,a);r(1);r(2);g(1,a);g(2,a)];
end
%for a=3:1:800
%output(:,a)=[Pr(a);q(a)];
%P_output(:,a)=[0;0];
%%r(:,a)=[0.98;0.02];
%r=[0.98;0.02];
%y(:,a)=output(:,a);
%input(:,a-1)=[Pr(a);q(a);Xt(a-1);Xb(a-1);Xt(a);Xb(a);r(1);r(2);r(1)-(y(1,a)-P_output(1,a));r(2)-(y(2,a)-P_output(2,a))];
%end
inputdata=input(:,2:a);
outputdata=u(:,3:a+1);
input_train=inputdata;
output_train=outputdata;
input_test=inputdata;
output_test=outputdata;
%[inputn,inputpsb]=mapminmax(input_train);
%[outputn,outputpsb]=mapminmax(output_train);
%inputn_test=mapminmax('apply',input_test,inputpsb);
%an=sim(invnet,inputn_test);
bn=sim(invnet,inputdata);
%P_output=mapminmax('reverse',an,outputpsb);
P_output1=bn;
error=abs(P_output1-output_test);
figure(7)
plot(P_output1(1,:),'.-r','Linewidth',2)
hold on
plot(output_test(1,:),'Linewidth',2)
hold off
figure(8)
plot(P_output1(2,:),'.-g','Linewidth',2)
hold on
plot(output_test(2,:),'Linewidth',2)
hold off
figure(9)
plot(error(1,:))
figure(10)
plot(error(2,:))