function [f,df]=fun(ux,p)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function [f,df]=fun3(ux,p)
% Reactor/separator process with recycle and inert
% Nominal optimization - objective function 
%
%
% Written by :  msg20000914 
% Modified by:
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

u=ux(1:6);
x=ux(7:size(ux,1));

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Input
LT=u(1);
VB=u(2);
R =u(3);
B =u(4);
F =u(5);
F0=u(6);

%Parameter
VBmax=p(1);
x0   =p(2:4);
k    =p(5);
qv   =p(6);
nc   =p(6);
nt   =p(7);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Objective function + analytic gradient

%alt 1: J=-F0
%J=-F0; f=J;
%df   =zeros(2*nt+8,1); 
%df(6)=-1;

%alt 2: J=F0-alpha*V
%alpha=0.1;
%J=F0-alpha*VB; f=-J;
%df   =zeros(2*nt+8,1);
%df(6)=-1; df(2)=alpha;


%alt 3: J  = F0 - 0.1 D - 0.01 V
f=-F0+0.1*R+0.01*VB; 
df   =zeros(2*nt+8,1);
df(2)=0.01;df(3)=0.1; df(6)=-1; 


