Question regarding passing input arguments in fmincon
6 views (last 30 days)
Show older comments
Hi All,
I am solving an optimization problem.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,time_exp,expZ,tSpan,z0)
sol = ode45(@(t,z)model(t,z,c), tSpan, z0); % Is this step required?
ModelZ = deval(sol, time_exp);
cost = ModelZ-expZ;
Any help would be highly appreciated.
14 Comments
Answers (1)
Alan Weiss
on 23 Apr 2019
I am not sure that I understand what you mean by "I want to pass ODEs as a constraint to fmincon." What about the ODE solution is a constraint? Do you want the minimum value of the solution to be above zero? Do you want the ODE solution to lie in a certain box? Once you explicitly define what you mean by the ODE solution is a "constraint," then I think that the answer to your question will be obvious. You will solve the ODE, get sol, and then write the constraint in terms of sol, maybe fun(deval(sol,tspan)) for some appropriate function fun and set of times tspan.
Alan Weiss
MATLAB mathematical toolbox documentation
4 Comments
Alan Weiss
on 23 Apr 2019
Sorry, I am unable to understand what you are trying to do, so this will be my last reply. I suggest that you write out equations or inequalities describing your constraint. Seriously, write them down. Then, given those equations or inequalities, you can write a corresponding nonlinear constraint function in fmincon syntax, restricting the result by using deval on the solution at relevant times. If you don't understand what I am suggesting, sorry, maybe someone else can help.
Alan Weiss
MATLAB mathematical toolbox documentation
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!