Optimization cost function file
3 次查看(过去 30 天)
显示 更早的评论
Is it possible that optimization can be done without creating a seperate function file for the cost function and the constraint?..if yes then how can we do it....?
5 个评论
Walter Roberson
2022-8-20
There are a few example cost functions such as rosenbeck, but mostly you write your own cost function depending on what you want to optimize.
See also Problem Based Optimization
采纳的回答
Walter Roberson
2018-6-9
Each iteration of the objective function called by fmincon or ga or similar must involve the same number of variables, and must be deterministic (no random values.)
You can use different numbers of variables for different calls to the minimizer, including in a loop. That could involve creating a new anonymous function for each iteration of the loop.
An objective function which is just the sum of variables can be expressed as just @sum; for a weighted sum, @(x) sum(x.*weights) or more robustly @(x) sum(x(:).*weights(:)) to be sure you do not have row/column difficulties.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Optimization Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!