%---- Gain scheduling

clc
clf
clear all

%-----------------  Tuninng parameters  ---------------------------
load Parameters
k=k_merket_all;
clear I P T_s1 k_merket_all
delay=[2, 2.67, 4, 2.81, 2.82, 2.81, 2.17, 2.07, 1.96, 1.94];


%------- Values of Feed rate and feed composition  ----------------
F=[1, 0.75, 0.5, 0.5, 0.5, 0.5, 1, 1, 1, 1, 1];
zF(1:6)=0.5;
zF(7:10)=[0.3, 0.4, 0.6, 0.7];



%---------------------  PLOTS  ------------------------------------
figure (1)
plot(F(1:3),k(1:3), '-ro', 'MarkerFaceColor', [1 0 0])
hold on
plot(F(4),k(4), 'bs', 'MarkerFaceColor', [0 0 0.8])
hold on
plot(F(5),k(5), 'bs', 'MarkerFaceColor', [0 0.8 0.8])
hold on
plot(F(6),k(6), 'bs', 'MarkerFaceColor', [0.8 0 0.8])
grid on
legend_t=legend('Without constraint on minimum refluks value',...
    'With constraint on minimum refluks value, operation point 4a',...
    'With constraint on minimum refluks value, operation point 4b',...
    'With constraint on minimum refluks value, operation point 4c');
set(legend_t, 'Fontsize', 8)
xlabel('Feed rate (normalized)')
ylabel('Tuning parameter: k´')

figure(2)
plot2_1=[zF(7:8), zF(1), zF(9:10)];
plot2_2=[k(7:8), k(1), k(9:10)];
plot(plot2_1,plot2_2, '-ro', 'MarkerFaceColor', [1 0 0])
grid on
xlabel('Fraction of light component in the feed')
ylabel('Tuning parameter: k`')

figure(3)
plot(F(1:3),delay(1:3), '-ro', 'MarkerFaceColor', [1 0 0])
hold on
plot(F(4),delay(4), 'bs', 'MarkerFaceColor', [0 0 0.8])
hold on
plot(F(5),delay(5), 'bs', 'MarkerFaceColor', [0 0.8 0.8])
hold on
plot(F(6),delay(6), 'bs', 'MarkerFaceColor', [0.8 0 0.8])
grid on
legend_t=legend('Without constraint on minimum refluks value',...
    'With constraint on minimum refluks value, operation point 4a',...
    'With constraint on minimum refluks value, operation point 4b',...
    'With constraint on minimum refluks value, operation point 4c');
set(legend_t, 'Fontsize', 8)
xlabel('Feed rate (normalized)')
ylabel('Tuning parameter: \Theta')

figure(4)
plot2_1=[zF(7:8), zF(1), zF(9:10)];
plot2_2=[delay(7:8), delay(1), delay(9:10)];
plot(plot2_1,plot2_2, '-ro', 'MarkerFaceColor', [1 0 0])
grid on
xlabel('Fraction of light component in the feed')
ylabel('Tuning parameter: \Theta')


figure(5)
plot(F(1:3),k(1:3).*delay(1:3), '-ro', 'MarkerFaceColor', [1 0 0])
hold on
plot(F(4),k(4)*delay(4), 'bs', 'MarkerFaceColor', [0 0 0.8])
hold on
plot(F(5),k(5)*delay(5), 'bs', 'MarkerFaceColor', [0 0.8 0.8])
hold on
plot(F(6),k(6)*delay(6), 'bs', 'MarkerFaceColor', [0.8 0 0.8])
grid on
hold on
% Regression  
[p S]=polyfit([F(1:2), F(4)],[k(1:2).*delay(1:2), k(4).*delay(4)], 1);
p_val=polyval (p, [0.5:0.01:1]);
plot([0.5:0.01:1],p_val, '-.', 'color', [0.6 0.6 0.9])

legend_t=legend('Without constraint on minimum reflux value',...
    'Operation point 4a (active constraint on minimum reflux value)',...
    'Operation point 4b (active constraint on minimum reflux value)',...
    'Operation point 4c (active constraint on minimum reflux value)',...
    'Fitted regression line: y=-5.42x+7.32');
set(legend_t, 'Fontsize', 8)
xlabel('Feed rate (normalized)')
ylabel('Tuning parameter: \Theta*k')


figure(6)
plot2_1=[zF(7:8), zF(1), zF(9:10)];
plot2_2=[k(7:8).*delay(7:8), k(1)*delay(1), k(9:10).*delay(9:10)];
plot(plot2_1,plot2_2, '-ro', 'MarkerFaceColor', [1 0 0])
grid on
xlabel('Fraction of light component in the feed')
ylabel('Tuning parameter: \Theta*k')



%plot([F(1:2), F(4)],[k(1:2).*delay(1:2), k(4).*delay(4)], '-ro', 'MarkerFaceColor', [1 0 0])

