fminsearch

Finds a local minimum of a function of several variables without using derivatives.

Category: Mathematics > Optimization

Syntax

x = fminsearch(fun, x0)

Starts at x0 and returns the point where fun reaches a local minimum.

x = fminsearch(fun, x0, options)

Same, with settings created by optimset.

[x, fval, exitflag, output] = fminsearch(___)

Also returns the minimum value, a status flag and run statistics.

Description

fminsearch runs the Nelder-Mead simplex method: it keeps n+1 trial points, and at each step replaces the worst one by reflecting, expanding or contracting it through the others. The simplex crawls downhill and shrinks around a minimum.

It is robust for rough or non-smooth functions but slow for many variables, and it can stall at a point that is not a minimum. Different starting points may give different answers.

Input arguments

fun
Function handle that takes one array argument (the whole vector of unknowns) and returns a scalar.
x0
Initial guess. Its size is the size of x.
options
Struct from optimset. TolX, TolFun, MaxIter and MaxFunEvals control stopping.

Output arguments

x
The point found, with the same shape as x0.
fval
Value of fun at x.
exitflag
1 on convergence, 0 if a limit on iterations or function evaluations stopped the search.
output
Struct with iterations, funcCount, algorithm and message.

Example

Rosenbrock banana function

banana = @(p) 100*(p(2) - p(1)^2)^2 + (1 - p(1))^2;
[p, fval] = fminsearch(banana, [-1.2 1]);
fprintf('p = (%.3f, %.3f), f = %.1e\n', p, fval)
Output
p = (1.000, 1.000), f = 8.2e-10

See also

fminbnd fzero optimset optimget