Optimization: solving ODE in objective function, how to pass solution to nonlinear constraint function?
Mostrar comentarios más antiguos
Dear all,
More specifically, I have a model struct with all model parameters and a handle on the derivative function. I created "wrappers" that pass this struct in addition to the parameters for optimization to both the objective function and the constraint function:
wrapper = @(x) objfunc( x, model ) ;
wrapperConstraint = @(x) constrfunc( x, model ) ;
x0 = ...
lb = ...
ub = ...
... = fmincon( wrapper, x0, [], [], [], [], lb, ub, wrapperConstraint, ... ) ;
when the objective function is called, it solves a system of ODEs, but there is no direct way to pass it to the constraint function. The only two options that I see are
- Using a global variable for storing the solution.
- OOP: e.g. defining model not as a struct but as a handle class, and storing the solution in a property. This way both the objective function and the constraint function would access the same object.
Is there a better/cleaner option? What is the "correct/usual" way of doing this?
Thank you,
Karin
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Ordinary Differential Equations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!