Global search optimization error

조회 수: 2 (최근 30일)
Jen W
Jen W 2020년 12월 15일
편집: Matt J 2020년 12월 15일
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.

채택된 답변

Matt J
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.
  댓글 수: 8
Jen W
Jen W 2020년 12월 15일
Hi Matt, that works perfectly. One last question: how to output the variables as well as the optimized objective value. After adding the code below, I can only see the output of 65 variables. Is there a way to also output the best obj? Thank you.
gs = GlobalSearch;
opts = optimoptions(@fmincon,'Algorithm','interior-point', 'MaxFunctionEvaluations', 1e5, 'MaxIterations', 1e5);
init = [1e4;1e4;1e4;1e4;1e4;1e4;1e4;1e4;1e4;1e4;1e4;1e4;1e4;1e4;1e4;1e4;1e4;1e4;1e4;1e4;1e4;1e4;1e4;1e4;1e4; 0.2;0.085;1e-2;1e-2; 0.2757;0.1329;1e-2;0.5714; 0.37;1e-2;1e-2;0.6; 1e-2;0.47;1e-2;0.5; 1e-2;1e-2;0.75;0.22; 0.2;0.085;1e-2;1e-2; 0.2757;0.1329;1e-2;0.5714; 0.37;1e-2;1e-2;0.6; 1e-2;0.47;1e-2;0.5; 1e-2;1e-2;0.75;0.22];
prob = createOptimProblem('fmincon', 'x0', init, 'objective', obj, 'lb', lowb, 'ub', uppb, 'options', opts, 'nonlcon', nonlinfcn)
run(gs, prob)
Matt J
Matt J 2020년 12월 15일
편집: Matt J 2020년 12월 15일

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Systems of Nonlinear Equations에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by