Find Minimum of Unconstrained Multivariable Function Using Derivative-Free Method - MATLAB Fminsearch
Find Minimum of Unconstrained Multivariable Function Using Derivative-Free Method - MATLAB Fminsearch
Find minimum of unconstrained multivariable function using derivative-free method - MATLAB fminsearch
fminsearch
Find minimum of unconstrained multivariable function using derivative-free method
Equation
Finds the minimum of a problem specified by
min f (x)
x
Syntax
x = fminsearch(fun,x0)
x = fminsearch(fun,x0,options)
x = fminsearch(problem)
[x,fval] = fminsearch(...)
[x,fval,exitflag] = fminsearch(...)
[x,fval,exitflag,output] = fminsearch(...)
Description
fminsearch attempts to find a minimum of a scalar function of several variables, starting at an initial
vector, or matrix.
x = fminsearch(fun,x0,options) minimizes with the optimization options specified in the structure options.
Use optimset to set these options.
x = fminsearch(problem) finds the minimum for problem, where problem is a structure described in Input
Arguments.
Create the structure problem by exporting a problem from Optimization app, as described in Exporting Your
Work.
[x,fval] = fminsearch(...) returns in fval the value of the objective function fun at the solution x.
[x,fval,exitflag] = fminsearch(...) returns a value exitflag that describes the exit condition of
fminsearch.
[x,fval,exitflag,output] = fminsearch(...) returns a structure output that contains information about
the optimization.
Input Arguments
Function Arguments contains general descriptions of arguments passed into fminsearch. This section
http://www.mathworks.com/help/optim/ug/fminsearch.html
1/5
11/2/2015
Find minimum of unconstrained multivariable function using derivative-free method - MATLAB fminsearch
The function to be minimized. fun is a function handle for a function that accepts a vector x
and returns a scalar f, the objective function evaluated at x. The function fun can be
specified as a function handle for a file:
x = fminsearch(@myfun,x0)
where myfun is a MATLAB function such as
function f = myfun(x)
f = ...
% Compute function value at x
fun can also be a function handle for an anonymous function, such as
x = fminsearch(@(x)norm(x)^2,x0,A,b);
options
problem
objective
Objective function
x0
solver
'fminsearch'
options
Output Arguments
Function Arguments contains general descriptions of arguments returned by fminsearch. This section
provides function-specific details for exitflag and output:
exitflag
output
Integer identifying the reason the algorithm terminated. The following lists the
values of exitflag and the corresponding reasons the algorithm terminated.
1
-1
Structure containing information about the optimization. The fields of the structure
are
iterations
Number of iterations
funcCount
algorithm
message
Exit message
Options
http://www.mathworks.com/help/optim/ug/fminsearch.html
2/5
11/2/2015
Find minimum of unconstrained multivariable function using derivative-free method - MATLAB fminsearch
Optimization options used by fminsearch. You can use optimset to set or change the values of these fields
in the options structure options. See Optimization Options Reference for detailed information.
Display
Level of display:
'off' or 'none' displays no output.
'iter' displays output at each iteration.
'notify' displays output only if the function does not converge.
'final' (default) displays just the final output.
FunValCheck
Check whether objective function values are valid. 'on' displays an error
when the objective function returns a value that is complex, Inf, or NaN.
The default 'off' displays no error.
MaxFunEvals
MaxIter
OutputFcn
PlotFcns
TolX
Examples
Example 1: Minimizing Rosenbrock's Function with fminsearch
A classic test example for multidimensional minimization is the Rosenbrock banana function:
(
)2
2
f (x) = 100 x2 x1 + (1 x1)2.
The minimum is at (1,1) and has the value 0. The traditional starting point is (-1.2,1). The anonymous
function shown here defines the function and returns a function handle called banana:
banana = @(x)100*(x(2)-x(1)^2)^2+(1-x(1))^2;
Pass the function handle to fminsearch:
http://www.mathworks.com/help/optim/ug/fminsearch.html
3/5
11/2/2015
Find minimum of unconstrained multivariable function using derivative-free method - MATLAB fminsearch
x =
1.0000
1.0000
fval =
8.1777e-010
exitflag =
1
This indicates that the minimizer was found at [1 1] with a value near zero.
Example 2
You can modify the first example by adding a parameter a to the second term of the banana function:
(
)2
2
f (x) = 100 x2 x1 + (a x1)2.
This changes the location of the minimum to the point [a,a^2]. To minimize this function for a specific value
of a, for example a = sqrt(2), create a one-argument anonymous function that captures the value of a.
a = sqrt(2);
banana = @(x)100*(x(2)-x(1)^2)^2+(a-x(1))^2;
Then the statement
x =
1.4142
2.0000
fval =
4.2065e-018
exitflag =
1
Limitations
fminsearch solves nondifferentiable problems and can often handle discontinuity, particularly if it does not
occur near the solution. fminsearch might only give local solutions.
fminsearch only minimizes over the real numbers, that is, x must only consist of real numbers and f(x) must
only return real numbers. When x has complex variables, they must be split into real and imaginary parts.
http://www.mathworks.com/help/optim/ug/fminsearch.html
4/5
11/2/2015
Find minimum of unconstrained multivariable function using derivative-free method - MATLAB fminsearch
Notes
fminsearch is not the preferred choice for solving problems that are sums of squares, that is, of the form
(
)
2
2
2
2
Instead use the lsqnonlin function, which has been optimized for problems of this form.
More About
collapse
all
Algorithms
fminsearch uses the simplex search method of [1]. This is a direct search method that does not use
function_handle
Anonymous Functions
References
[1] Lagarias, J. C., J. A. Reeds, M. H. Wright, and P. E. Wright, "Convergence Properties of the NelderMead Simplex Method in Low Dimensions," SIAM Journal of Optimization, Vol. 9, Number 1, pp. 112147,
1998.
See Also
fminbnd | fminunc | optimset | optimtool
http://www.mathworks.com/help/optim/ug/fminsearch.html
5/5