|MATLAB Function Reference|
Minimize a function of several variables
fminsearch finds the minimum of a scalar function of several variables, starting at an initial estimate. This is generally referred to as unconstrained nonlinear optimization.
starts at the point
x = fminsearch
x0 and finds a local minimum
x of the function described in
x0 can be a scalar, vector, or matrix.
fun is a function handle. See Function Handles in the MATLAB Programming documentation for more information.
Parameterizing Functions Called by Function Functions, in the MATLAB mathematics documentation, explains how to provide additional parameters to the function
fun, if necessary.
minimizes with the optimization parameters specified in the structure
x = fminsearch
options. You can define these parameters using the
fminsearch uses these
options structure fields:
||Level of display.
||Check whether objective function values are valid.
||Maximum number of function evaluations allowed
||Maximum number of iterations allowed
||Specify a user-defined function that the optimization function calls at each iteration.
||Termination tolerance on the function value
||Termination tolerance on
[x,fval] = fminsearch(...)
fval the value of the objective function
fun at the solution
[x,fval,exitflag] = fminsearch(...)
returns a value
exitflag that describes the exit condition of fminsearch:
||Maximum number of function evaluations or iterations was reached.
||Algorithm was terminated by the output function.
[x,fval,exitflag,output] = fminsearch(...)
returns a structure
output that contains information about the optimization:
||Number of function evaluations
||Number of iterations
fun is the function to be minimized. It accepts an input
x and returns a scalar
f, the objective function evaluated at
x. The function
fun can be specified as a function handle for an M-file function
myfun is an M-file function such as
or as a function handle for an anonymous function, such as
Other arguments are described in the syntax descriptions above.
Example 1. A classic test example for multidimensional minimization is the Rosenbrock banana function
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
Pass the function handle to
This indicates that the minimizer was found to at least four decimal places with a value near zero.
Example 2. If
fun is parameterized, you can use anonymous functions to capture the problem-dependent parameters. For example, suppose you want to minimize the objective function
myfun defined by the following M-file function.
myfun has an extra parameter
a, so you cannot pass it directly to
fminsearch. To optimize for a specific value of
a, such as
a = 1.5.
fminsearchwith a one-argument anonymous function that captures that value of
myfunwith two arguments:
Example 3. You can modify the first example by adding a parameter a to the second term of the banana function:
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
Then the statement
seeks the minimum
[sqrt(2), 2] to an accuracy higher than the default on
fminsearch uses the simplex search method of . This is a direct search method that does not use numerical or analytic gradients.
n is the length of
x, a simplex in
n-dimensional space is characterized by the
n+1 distinct vectors that are its vertices. In two-space, a simplex is a triangle; in three-space, it is a pyramid. At each step of the search, a new point in or near the current simplex is generated. The function value at the new point is compared with the function's values at the vertices of the simplex and, usually, one of the vertices is replaced by the new point, giving a new simplex. This step is repeated until the diameter of the simplex is less than the specified tolerance.
fminsearch can often handle discontinuity, particularly if it does not occur near the solution. fminsearch may only give local solutions.
fminsearch only minimizes over the real numbers, that is, must only consist of real numbers and must only return real numbers. When has complex variables, they must be split into real and imaginary parts.
function_handle (@), anonymous functions
 Lagarias, J.C., J. A. Reeds, M. H. Wright, and P. E. Wright, "Convergence Properties of the Nelder-Mead Simplex Method in Low Dimensions," SIAM Journal of Optimization, Vol. 9 Number 1, pp. 112-147, 1998.
© 1994-2005 The MathWorks, Inc.