% clear all; close all; clc;

global coldata dyndata hydraulic termodata

%% COLUMN DATA %%%
% Number of stages
coldata.Nt = [7 10 4 4 4 5 4];

% Height of each section
coldata.sech = [1.33 1.33 0.89 0.89 0.89 0.89 0.89];
% Column diameter
coldata.diameter = 0.1;
% Initial holdup in reboiler and condenser
coldata.M0 = [0.5 0.5 1 0.5 0.5 1 0.5];

%% THERMODYNAMIC DATA %%%

% Universal gas constant [cal/molK]
termodata.R = 1.98721;
% Antoine coefficients
termodata.A = [
    8.08097  1582.271  239.726
    8.11220  1592.864  226.184
    8.37895  1788.020  227.438
    7.36366  1305.198  173.427
    ];
% Molar volumes of pure components
termodata.V = [40.73  58.68  75.14  91.97];
% Wilson parameters
termodata.W = [
    0           507.3868    71.4631     -121.3194
    -452.5062   0           102.6706    -8.3924
    154.6476    -40.8745    0           -316.7718
    9543.2503   122.8635    547.4636    0
    ];
% Pressure (atm)
termodata.P = 1.0;
% Heat transfer coefficient (W/m^2 K)
termodata.U = 0;
% Molar enthalpy of vapourisation (J/mol)
termodata.deltaH = 45000;
% Temperature outside column (K)
termodata.T0 = 293;


termodata.alpha = [0 0 0 0 0.0 0 0.0]*1;

%% HYDRAULIC DATA %%

hydraulic.k1 = 1/0.063;

load Nominal
dyndata.x_nom = x_nom;
dyndata.u_nom = u_nom;
options = optimset('fmincon');
options = optimset(options,'TolFun',1e-10,'TolCon',1e-12,'MaxFunEvals',500000,'Display','iter');
% ,'Algorithm','interior-point'


Specs
[x_nom1,fval,exitflag] = fmincon(@(x) Objective(x),[u_nom;x_nom],Ain,bin,As,bs,[],[],@(x) Kaibel_nonlv_dist(x),options);
x=x_nom1(13+[1:end-13]);u=x_nom1(1:13);
dxdt=Kaibel_dxdt(0,[u;x]);
NORM_dxdt=norm(dxdt)

CheckSum