surrogateopt: output function

How do we create a customize output function for the 'surrogateopt' that will show the solution at every iteration. I need am example for better understanding. Thank you.

 Respuesta aceptada

Alan Weiss
Alan Weiss el 9 de Ag. de 2022
Try this.
lb = [-3 -3];
ub = -lb;
opts = optimoptions('surrogateopt','OutputFcn',@listout);
obj = @(x)100*(x(2) - x(1)^2)^2 + (1 - x(1))^2;
[sol,fval] = surrogateopt(obj,lb,ub,opts)
function stop = listout(x,optimValues,state)
stop = false;
switch state
case 'iter'
nval = optimValues.funccount;
y = optimValues.currentX;
fprintf("Number of fevals = %g, x = [%g,%g]\n",nval,y(1),y(2))
end
end
Alan Weiss
MATLAB mathematical toolbox documentation

3 comentarios

Geopaul
Geopaul el 9 de Ag. de 2022
Thank you so much, it works.
Geopaul
Geopaul el 11 de Ag. de 2022
How do I save these outputs( e.g nval and y) at every iterations?
Alan Weiss
Alan Weiss el 11 de Ag. de 2022
Alan Weiss
MATLAB mathematical toolbox documentation

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Productos

Versión

R2021a

Preguntada:

el 9 de Ag. de 2022

Comentada:

el 11 de Ag. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by