fminsearch solves for the minimum of a function using the Nelder-Mead simplex optimization algorithm.

[xmin,fmin,info,traceit] = fminsearch(f,x0,o)

  • f: function handle
  • x0: initial guess
  • o: optimization options
Options Description Values Default values
tol Tolerance on the function value positive integer 1e-6
maxit Maximum number of iterations positive integer 100
maxfc Maximum number of evaluations of f positive integer 100
lb Lower bounds double realmin/100
ub Upper bounds double realmax/100
  • xmin: minimum of f
  • fmin: function value at xmin
  • info: struct object with the following fields: x0, nit (number of iterations), nfc , tol (tolerance)
  • traceit: cell array storing all the above outputs at each iteration

Stopping criteria

fminsearch stops when it satisfies one of the following conditions:
  • number of evaluations of f is bigger than maxfc
  • number of iterations is bigger than maxit
  • the tolerance criterion has been satisfied: |f(x)| < tol


Call optimview('fminsearch',info), being info the third output of fminsearch. Some animation options can be specified appending them to the struct object info.
Options Description Values Default values
animfreq Frame frequency positive integer 1
animstart Inicial frame to start animation positive integer 1
sol Solution vector []
osol Plotting options for the solution struct struct('markerSize', 3, 'markerFill', '#404040')
os Plotting options for trace struct struct('markerSize', 3, 'markerFill', 'red')
np Number of points for meshgrid positive integer 10


Running minimization
f = @(x) 5*x(1).^2 - 10*x(1) - 25 

% function handle definition

[x,fval,~,tr] = fminsearch(f,21)
This will return x=0.999998 and fval=-30.

Step by step visualization
x = -1:0.2:3	

% x-values for plotting

y = x for i = 1:numel(x) y(i) = f(x(i))

% evaluation of x-values

end po = struct('show',false)

% chart options

po.xAxisMin = min(min(x)) po.xAxisMax = max(max(x)) po.yAxisMin = min(min(y)) po.yAxisMax = max(max(y)) po.markerFill = 'red' c = cell(numel(tr.x), 1) for i = 1:numel(tr.x) c{i} = overlay({plot(x,y,po),scatter(tr.x(i),tr.f(i),po)},po) end animate(c)

% generate animation


[1] J.A. Nelder, R. Mead, "A simplex method for function minimization", The Computer Journal, 1965.

[2] F. Gao, L. Han, "Implementing the Nelder-Mead simplex algorithm with adaptive parameters", Computational Optimization and Applications, 2010.

See also

nsga2 | lsqcurvefit