load('new_everything_noise_n_2d4')

ylimout=[0.05 0.075];
ylimin=[0.45 0.82];
ylimcost=[0.995 1.0006];


%========plot responses=============
itervec=1:Nite;

%worst case loss
% Jnomworstloss=max((Joptvec-Jnomvec)./Joptvec)*100
%

Jnomavg=mean(Jnomvec);
Joptavg=mean(Joptvec);
Jnecavg=mean(Jnecvec);
Jmaryavg=mean(Jmaryvec);

%Normalize cost with respect to the optimal
Jnomvec=Jnomvec./Joptvec;
Jnecvec=Jnecvec./Joptvec;
Jmaryvec=Jmaryvec./Joptvec;
J1termvec=J1termvec./Joptvec;
J2termsvec=J2termsvec./Joptvec;
Jsocvec=Jsocvec./Joptvec;
Jncovec=Jncovec./Joptvec;
Joptvec=Joptvec./Joptvec;
 



 
Lossavg_nom=sum(1-Jnomvec)
Lossavg_nec=sum(1-Jnecvec)
Lossavg_mary=sum(1-Jmaryvec)

aux.lossnom=Lossavg_nom;
aux.lossnec=Lossavg_nec;
aux.lossmary=Lossavg_mary;
structname=strcat('struct',filename);
save(structname,'aux')



% outputs for case 4 using nominal and optimal inputs
ynom=[0.0688
    0.0570
    0.7715];
ynommatrix=repmat(ynom,1,1000);

yopt =[
    0.0676
    0.0562
    0.7724];


yoptmatrix=repmat(yopt,1,1000);

ynm=repmat(yn,1,1000);
figure(1)
subplot(311)
plot(itervec,ymaryvec(1:2,:),'g','LineWidth',2)
hold on
plot(itervec,ynecvec(1:2,:),'r','LineWidth',2)
hold on
plot(itervec,ynommatrix(1:2,:),'k--','LineWidth',2)
hold on
plot(itervec,yoptmatrix(1:2,:),'b-.','LineWidth',2)

set(gca,'FontSize',16)
% xlabel('Iteration')
ylabel('$c_A$ $and$ $c_B, [mol,l]$','interpreter','latex')
 xlim([0 100])
 ylim(ylimout)
% 
 subplot(312)
usig1v=usig1(:,1:end-1);
usig2v=usig2(:,1:end-1);
umaryv=umary(:,1:end-1);
unecv=unec(:,1:end-1);
unomvec=repmat(un,1,Nite);
uoptvec=repmat(uopt,1,Nite);
usocv=usoc(:,1:end-1);
uncov=unco(:,1:end-1);
% 
plot(itervec,unomvec,'k--','LineWidth',2)
hold on
plot(itervec,uoptvec,'b-.','LineWidth',2)
 hold on

% hold on
plot(itervec,umaryv,'g','LineWidth',2)
hold on
plot(itervec,unecv,'r','LineWidth',2)
hold on

hold on
set(gca,'FontSize',16)
% xlabel('Iteration')
ylabel('$u, [l/min]$','interpreter','latex')
ylim(ylimin)
 xlim([0 100])


subplot(313)
plot([0 1000],[1 1],'b-.','LineWidth',2)
hold on
plot(itervec,Jmaryvec,'g','LineWidth',2)
hold on
plot(itervec,Jnecvec,'r','LineWidth',2)
hold on
plot(itervec,Jnomvec,'k--','LineWidth',2)
set(gca,'FontSize',16)
xlabel('Iteration \#','interpreter','latex')
ylabel('$Normalized$ $J$','interpreter','latex')
% set(gca,'YTick',[0.998771795635371 1.000])

 xlim([0 100])
%  ylim([0.998 1.0006])
ylim(ylimcost)

  print -depsc medium_noise_case4
