%%Three Product Petlyuk Column
%Constant Relative Voltality
% Initializes the model and runs
%%
clear all; close all; clc;
global coldata dyndata hydraulic termodata UU alfa tend NI i
%% COLUMN DATA %%

% Number of stages
coldata.Nt = [12 12 12 12 12 12];
% Initial holdup stages
coldata.M0 = [1 1 1 1 1 1 1 1 1 1 1 1];
%Boiling point of ethanol, propanol and n-butanol
coldata.Tboil = [78.37 97 117.4];
termodata.P = 1.0;
hydraulic.k1 = 1/0.063;
%% THERMODYNAMIC DATA %%
alfa=[4.215374389	2.102194688	1] %ethanol propanol butanol

%% load nominal x u
load Init.mat
UU=[];
i=0;%to initiate CS make change in CS by i+1
indmat_Yes_S1
dyndata.x_nom = x_nom; %for feedu_nom(6)=u_nom(6)*1.2
%u_nom(6)=u_nom(6)*0.98;
%u_nom(7)=u_nom(7)*0.3994;
%u_nom(8)=u_nom(8)*1.6006;
dyndata.u_nom=u_nom;
%%
NI=8; % Number of integerators
options = odeset('MaxStep',10);
tend=20000;
[t,x]=ode15s(@CS1,[0 tend],[zeros(NI,1);dyndata.x_nom],options);
%%
xf=x(end,NI+1:end)';
u_nom=UU(end,2:12)';
dxdt = norm(Petlyuk_dxdt(0,[u_nom; xf]))
Plot_Profiles
