% Main Optimization file
clear all; close all; clc;

global coldata dyndata hydraulic termodata UU alfa
% COLUMN DATA %%

% Number of stages
coldata.Nt = [20 20 20 20 20 20];
% Initial holdup in reboiler and condenser
coldata.M0 = [1 1 1 1 1 1 1 1 1 1 1 1];

hydraulic.k1 = 1/0.063;

% THERMODYNAMIC DATA %%

load Nominal.mat

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

Specs

alfa=[4.215374389 2.102194688 1]

% 
[x_nom1,fval,exitflag,output,lambda,grad,hessian] = fmincon(@(x) Objective(x),[u_nom;x_nom],Ain,bin,As,bs,[],[],@(x) Petlyuk_dist(x),options);

x_nom=x_nom1(12:end);u_nom=x_nom1(1:11);

dxdt = norm(Petlyuk_dxdt(0,[u_nom; x_nom]))


[[x_nom([im_xt()]); 1-sum(x_nom([im_xt()]))] [x_nom([im_xS1()]); 1-sum(x_nom([im_xS1()]))] [x_nom([im_xr()]); 1-sum(x_nom([im_xr()]))]]
xf=x_nom;
Plot_Profiles



