Optimization: solving ODE in objective function, how to pass solution to nonlinear constraint function?
显示 更早的评论
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
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!