%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Steady-state optimization

clear all
global Y g

%if 1==0
%cd /home/msg/Matlab
%startup
%cd /home/msg/Matlab/larsson2002/caseC
cd d:\mlokal\matlab\larsson\caseC\
pwd
%end

%Options
options=optimset;
options.DerivativeCheck='off';
options.Diagnostics='on';
options.Display='iter';
options.GradConstr='on';
options.GradObj='on';
options.LargeScale='off';pwd
%options.TolCon=1e-9;
%options.TolFun=1e-9;
%options.TolX=1e-9;

%Disturbances
F0max=490; 
Vmax =1400;

%Initial values
load results/opt0
p=p0; p(1)=Vmax; p(20)=F0max;
ux=ux0;

%Optimization
tcpu=cputime;
[ux,fval,exitflag,output,lambda,grad,hessian]=fmincon('fun',ux,[],[],[],[],[],[],'nonlcon',options,p);
[ux,fval,exitflag,output,lambda,grad,hessian]=fmincon('fun',ux,[],[],[],[],[],[],'nonlcon',options,p);
VBmax=p(1); F0max=p(20); Mr=Y(7); xb=Y(12); V=Y(2); F0=Y(6);
disp(sprintf('VBmax=%4.2f F0max=%4.2f Mr=%6.4f xb=%6.4f V=%6.4f F0=%6.4f exitflag=%d max(g)=%6.4f',VBmax,F0max,Mr,xb,V,F0,exitflag,max(g(3:8))));   
cputime-tcpu






