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!