%plot loss for null space method and exact local method
clear all; close all; clc;

%Null space emthod
% Plotting the losses due to disturbance in Feed flow rate for null space
% method

load cost_nullspaceF
load cost_Fopt
LossF_nullspace =[ ( cost_nullspaceF-cost_Fopt)./cost_Fopt]*100;
F=0.9:0.025:1.1;
figure (1)
xx=F;
yy=spline(F,LossF_nullspace,xx);
plot(xx,yy,'r','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 using null space method for disturbance (feed,F)','FontSize',12,'FontWeight','bold')
hold off


% Plotting the losses due to disturbance in vapor flow rate

load cost_nullspaceV
load cost_Vopt
LossV_nullspace =[ ( cost_nullspaceV-cost_Vopt)./cost_Vopt]*100;

Vmax =1.73186;
V=0.9*Vmax:0.025*Vmax:1.1*Vmax;
figure (2)
xx=V;
yy=spline(V,LossV_nullspace,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 using null space method for disturbance (boilup, V)','FontSize',12,'FontWeight','bold')
hold off


%Exact local method
% Plotting the losses due to disturbance in Feed flow rate for exact local
% method
%Null space method is only valid for very small change therefore the range
%of feed disturbances reduced to 0.9 to 1.05

load cost_ELF
load cost_Fop
LossF_EL =[ ( cost_ELF-cost_Fop)./cost_Fop]*100;
F=0.9:0.025:1.05;
figure (3)
xx=F;
yy=spline(F,LossF_EL,xx);
plot(xx,yy,'r','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 using exact local method method for disturbance (feed,F)','FontSize',12,'FontWeight','bold')
hold off

