This is a follow up to my previous question posted here.
I am solving an optimization problem using fmincon in MATLAB. There are no equality constraints in my model. I want to pass ODEs as constraint to fmincon using, non-linear constraint, nlcon argument.
The function model contains odes
function dz = model(t, z, c)
dz(1) = ..
dz(2) = ..
I'd like to ask how the ode intergrator has to be called in the place of nlcon in fmincon(@objective,p0,A,b,Aeq,beq,lb,ub,nlcon).
%p0 = Initial Value of Parameters
A = [];
b = [];
Aeq = [];
beq = [];
nlcon = ode45(@(t,z)model(t,z,x), tSpan, z0); % Is this correct?
p = fmincon(@objective,p0,A,b,Aeq,beq,lb,ub,nlcon);
Since the ode function is already called in nlcon , is it required to call the function model again inside the objective function?
function cost = objective(c,expZ,tSpan,z0)
sol = ode45(@(t,z)model(t,z,c), tSpan, z0); % Is this step required?
ModelZ = sol(end,:)% the solutions obtained from model at end point of tSpan
cost = ModelZ-expZ; %expZ contains steady state values of z1,z2..
Any help would be highly appreciated.