Global search optimization error
3 次查看(过去 30 天)
显示 更早的评论
Hello community,
I am trying to debug a global optimization problem with objective function having multiple inputs. The code is here:
gs = GlobalSearch;
opts = optimoptions(@fmincon,'Algorithm','interior-point');
sixmin = @(x, y)(4*x.^2 - 2.1*x.^4 + x.^6/3 ...
+ x.*y - 4*y.^2 + 4*y.^4);
problem = createOptimProblem('fmincon','x0',[-1,2],...
'objective',sixmin,'lb',[-3,-3],'ub',[3,3],...
'options',opts);
run(gs,problem)
This code is adapted from https://www.mathworks.com/help/gads/run-the-solver.html , "Example of run with GlobalSearch" to illustrate my point. The only difference is the variable in the objective function handle here is (x, y) instead of a single (x). The error message is of this code is:

I am wondering why I cannot use (x,y) in the function handle, and how I can correct it if I have to use multiple inputs due to the large number of inputs in the real problem I am solving. Thank you.
0 个评论
采纳的回答
Matt J
2020-12-15
编辑:Matt J
2020-12-15
The fix, for your posted example, is to do,
problem = createOptimProblem('fmincon','x0',[-1,2],...
'objective',@(p) sixmin(p(1),p(2)),'lb',[-3,-3],'ub',[3,3],...
'options',opts);
I am wondering why I cannot use (x,y) in the function handle, and how I can correct it if I have to use multiple inputs due to the large number of inputs in the real problem I am solving.
If you have many unknowns, it makes more sense that both the function arguments and the expressions within the function be written in terms of vector variables rather than scalar variables. It is much easier and more compact to pass a 100x1 vector to a function, than to write a function call with 100 separate input arguments. This is, in any case, the syntax that the solver expects, as you will see in the documentation.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surrogate Optimization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!