function [znomopt,Vnomopt,lambda]=nom_opt(flag)
% Revision 28.02.03 Tomlab version
% nom_opt.m
% Input: flag
% flag=0 : No output
% flag=1 : Show the optimal inputs
% Computes the nominal inputs with the nominal disturbance as given in
% startup.m. 
% Finds the nominal optimum for the Petlyuk case.
global hessflag coldata d uset
load nomopt_nd % zopt initial vector
% Optimization configuration
%%%%%% START
Name = 'Petlyuk Nominal optimization';
lb=zeros(116,1);
ub=10*ones(116,1);
c_L = zeros(114,1); % Lower bound inequality constraints
c_U = zeros(114,1);      % Upper bound inequality constraints
c_U(112:114)=0.03;
% %HessPattern = eye(75);
load nomopt_nd
Prob = conAssign('petl_opt',[],[],[],lb,ub,Name,zopt,[],[],[],[],[],'petl_cons',[],[],[],c_L,c_U,[],[],[],[]);
Prob.PriLevOpt = 2;
Prob.PriLev=1;
Prob.Solver.Alg =4;
Prob.NumDiff =6; % Use standard numerical differences
Prob.ConsDiff=6; % Use complex variable method to estimate differences
Prob.SOL.optpar = -999*ones(62,1);
Prob.SOL.optpar(1)=111111;
Prob.SOL.PrintFile ='test_optF.pri';
Prob.SOL.optPar(39)=0;
Prob.SL.optPar([9,11,12])=1e-8;
vub=ones(116,1);vub(105:106)=10;vub(110)=1.3; % upper bound
vlb=zeros(116,1); % Lower bound

%%%%%% END
%end optimization configuration
d=coldata.d0; %Nominal disturbance
hessflag=0; % Flag to petl_cons
 % fmincon
Result_nom = tomRun('snopt',Prob);
lambda=Result_nom.v_k(117:end);
znomopt=Result_nom.x_k;
Vnomopt=Result_nom.f_k;
clear zopt
save nomopt znomopt Vnomopt Result_nom
% Display the optimal inputs
if flag==1
    unomopt=znomopt(105:113);
    L0=unomopt(1);			% Reflunomoptx rate 
    VB0=unomopt(2);			% Boilup rate 
    S0=unomopt(3);			% Sideproduct removal rate 
    Rl0=unomopt(4);			% Liquid split fraction to feed tray side 
    Rv0=unomopt(5);  		% Vapour split fraction to feed tray side 
    F0=	unomopt(6);			% Feed flow rate
    zF0=unomopt(7:8);	% Feed composition for components 1:nc-1
    qF0=unomopt(9);		% Feed liquid fraction
    disp('======================================================================')
    disp('                      Nominelt uten forstyrrelser                     ')
    disp('======================================================================')

    disp(sprintf('L %s V %s S %s Rl %s Rv %s F %s zF1 %s zF2 %s qF',9,9,9,9,9,9,9,9));
    disp(sprintf('%6.3g %6.3g %6.3g %6.3g %6.3g %6.1g %s %6.3g %6.3g',L0,VB0,S0,Rl0,Rv0,F0,9,zF0(1),zF0(2),qF0));
    disp(sprintf('xA %s xC %s xB',9,9));
    disp(sprintf('%6.3g %6.3g %6.3g',znomopt(114),znomopt(115),znomopt(116)));
 end
