Global search optimization error
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Jen W
el 15 de Dic. de 2020
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 comentarios
Respuesta aceptada
Matt J
el 15 de Dic. de 2020
Editada: Matt J
el 15 de Dic. de 2020
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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Surrogate Optimization en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!