MATLAB: Passing variable through pattern search iterations

Global Optimization Toolboxobjective-functionpattern search

Hi everyone!
I'm using pattern search to solve a minmax problem. I know that pattern search:
1) Starts witha a polling phase where it polls the points in the current mesh by computing their objective function values,
2) it groups all the values of the objective functions and it select the mesh case with highest objective function value,
3) it moves the mesh in the last successful poll point (or it leaves the central mesh point as before) and starts again from 1),
4) this continues untill convergence is reached (possibly).
My question is: Is it possible to pass a variable from the best objective function (point 2) to the next polling phase (point 3)?
Many thanks!

Best Answer

Following code shows how to get the information from each iteration of patternsearch
global x_iterations y_iterations
x_iterations = [];
y_iterations = [];
obj_fun = @(x) sum(x.^2.*exp(x.^2).*abs(log(x+1)));
opts = optimoptions('patternsearch', 'OutputFcn', @myOutFcn);
[x_final, f_final] = patternsearch(obj_fun, rand(1,10), [], [], [], [], [], [], [], opts);
function [stop, options, optchanged] = myOutFcn(optimvalues, options, flag)
global x_iterations y_iterations
x_iterations = [x_iterations; optimvalues.x];
y_iterations = [y_iterations; optimvalues.fval];
stop = false;
optchanged = false;
This page show how to define the outputFcn to get more detail for each iteration of the optimization algorithm: