% Plot loss from brute force method 
% These plots are for first five ranks in Tbale 6-7 (Master Thesis 2013,
% Ambari Khanam)
clear all; close all; clc;

% Plotting the losses due to disturbance in Feed flow rate
figure (1)
load cost_MSVrank1            % [T10 T38 T59] , cost by keeping these temperatures constant and variation in feed from the optimal
load cost_Fopt                        % optimal cost for variation in feed from the optimal
LossF_MSVrank1 =[ ( cost_MSVrank1-cost_Fopt)./cost_Fopt]*100;
F=0.9:0.025:1.1;
figure (1)
xx=F;
yy=spline(F,LossF_MSVrank1,xx);
plot(xx,yy,'b','LineWidth',2.5)
xlim([0.9 1.1])
ylim([0 10])
set(gca,'XTick',0.9:0.025:1.1);
set(gca,'YTick',0:2:10);
xlabel('F [kmol/min]','FontSize',12,'FontWeight','bold')
ylabel('Loss [%]','FontSize',12,'FontWeight','bold')
title('Loss by keeping three temperatures constant','FontSize',12,'FontWeight','bold')
hold on
% loss with second set of best temperatures T9,T 38,T60
load cost_MSVrank2               % [T9 T38 T60], cost by keeping these temperatures constant and variation in feed from the optimal
LossF_MSVrank2 =[ ( cost_MSVrank2-cost_Fopt)./cost_Fopt]*100;
yy=spline(F,LossF_MSVrank2,xx);
plot(xx,yy,'r','LineWidth',2.5)
hold on
load cost_MSVrank3                  %[T10 T38 T60], cost by keeping these temperatures constant and variation in feed from the optimal
LossF_MSVrank3 =[ ( cost_MSVrank3-cost_Fopt)./cost_Fopt]*100;
yy=spline(F,LossF_MSVrank3,xx);
plot(xx,yy,'g','LineWidth',2.5)
hold on
load cost_MSVrank4                  %[T10  T38 T63], cost by keeping these temperatures constant and variation in feed from the optimal
LossF_MSVrank4 =[ ( cost_MSVrank4-cost_Fopt)./cost_Fopt]*100;
yy=spline(F,LossF_MSVrank4,xx);
plot(xx,yy,'m','LineWidth',2.5)

load cost_MSVrank5                   %[ T11    T38    T60], cost by keeping these temperatures constant and variation in feed from the optimal
LossF_MSVrank5 =[ ( cost_MSVrank5-cost_Fopt)./cost_Fopt]*100;
yy=spline(F,LossF_MSVrank5,xx);
plot(xx,yy,'c','LineWidth',2.5)
legend('rank-1-[T10 T38 T59]','rank2-[T9 T38 T60]','rank3-[T10 T38 T60]','rank4-[T10 T38 T63]','rank5-[T11 T38 T60]')



% Plotting the losses due to disturbance in boilup, V
load cost_Vrank1            % [T10 T38 T59] , cost by keeping these temperatures constant and variation in feed from the optimal
load cost_Vopt                        % optimal cost for variation in feed from the optimal
Loss_Vrank1 =[ ( cost_Vrank1-cost_Vopt)./cost_Vopt]*100;
%Vmax =1.73186;
Vmax=1;
V=0.9*Vmax:0.025*Vmax:1.1*Vmax;
figure (2)
xx=V;
yy=spline(V,Loss_Vrank1,xx);
plot(xx,yy,'b','LineWidth',2.5)
xlim([0.9 1.1])
ylim([0 10])
set(gca,'XTick',0.9:0.025:1.1);
set(gca,'YTick',0:2:10);
xlabel('V [kmol/min]','FontSize',12,'FontWeight','bold')
ylabel('Loss [%]','FontSize',12,'FontWeight','bold')
title('Loss by keeping three temperatures constant','FontSize',12,'FontWeight','bold')
hold on
% loss with second set of best temperatures T9,T 38,T60
load cost_Vrank2               % [T9 T38 T60], cost by keeping these temperatures constant and variation in feed from the optimal
Loss_Vrank2 =[ ( cost_Vrank2-cost_Vopt)./cost_Vopt]*100;
yy=spline(V,Loss_Vrank2,xx);
plot(xx,yy,'r','LineWidth',2.5)
hold on
load cost_Vrank3                  %[T10 T38 T60], cost by keeping these temperatures constant and variation in feed from the optimal
Loss_Vrank3 =[ ( cost_Vrank3-cost_Vopt)./cost_Vopt]*100;
yy=spline(V,Loss_Vrank3,xx);
plot(xx,yy,'g','LineWidth',2.5)
hold on
load cost_Vrank4                  %[T10  T38 T63], cost by keeping these temperatures constant and variation in feed from the optimal
Loss_Vrank4 =[ ( cost_Vrank4-cost_Vopt)./cost_Vopt]*100;
yy=spline(V,Loss_Vrank4,xx);
plot(xx,yy,'m','LineWidth',2.5)

load cost_Vrank5                   %[ T11    T38    T60], cost by keeping these temperatures constant and variation in feed from the optimal
Loss_Vrank5 =[ ( cost_Vrank5-cost_Vopt)./cost_Vopt]*100;
yy=spline(V,Loss_Vrank5,xx);
plot(xx,yy,'c','LineWidth',2.5)
legend('rank-1-[T10 T38 T59]','rank2-[T9 T38 T60]','rank3-[T10 T38 T60]','rank4-[T10 T38 T63]','rank5-[T11 T38 T60]')
hold off