Optimization Toolbox | ![]() ![]() |
Find a minimum of an unconstrained multivariable function
where x is a vector and f(x) is a function that returns a scalar.
Syntax
x = fminsearch(fun,x0) x = fminsearch(fun,x0,options) x = fminsearch(fun,x0,options,P1,P2,...) [x,fval] = fminsearch(...) [x,fval,exitflag] = fminsearch(...) [x,fval,exitflag,output] = fminsearch(...)
Description
fminsearch finds a minimum of a scalar function of several variables, starting at an initial estimate. This is generally referred to as unconstrained nonlinear optimization.
x = fminsearch(fun,x0)
starts at the point x0
and finds a local minimum x
of the function described in fun
. x0
can be a scalar, vector, or matrix.
x = fminsearch(fun,x0,options)
minimizes with the optimization parameters specified in the structure options
. Use optimset
to set these parameters.
x = fminsearch(fun,x0,options,P1,P2,...)
passes the problem-dependent parameters P1
, P2
, etc., directly to the function fun
. Use options = []
as a placeholder if no options are set.
[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 in to fminsearch
. This section provides function-specific details for fun
and options
:
fun |
The function to be minimized. fun is 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.where myfun is a MATLAB function such asfun can also be an inline object. |
options |
Options provides the function-specific details for the options parameters. |
Output Arguments
Function Arguments contains general descriptions of arguments returned by fminsearch
. This section provides function-specific details for exitflag
and output
:
Options
Optimization options parameters used by fminsearch
. You can use optimset
to set or change the values of these fields in the parameters structure, options
. See Optimization Parameters, for detailed information:
Examples
Minimize the one-dimensional function f(x) = sin(x) + 3
.
To use an M-file, i.e., fun = 'myfun'
, create a file myfun.m
.
Then call fminsearch
to find a minimum of fun
near 2
.
To minimize the function f(x) = sin(x) + 3
using an inline object
Algorithms
fminsearch uses the simplex search method of [1]. This is a direct search method that does not use numerical or analytic gradients as in fminunc
.
If 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 is generally less efficient than fminunc
for problems of order greater than two. However, when the problem is highly discontinuous, fminsearch
may be more robust.
Limitations
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, 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.
Note
fminsearch is not the preferred choice for solving problems that are sums-of-squares, that is, of the form ![]() lsqnonlin function, which has been optimized for problems of this form.
|
See Also
@
(function_handle
), fminbnd
, fminunc
, inline
, optimset
References
[1] 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.
![]() | fminimax | fminunc | ![]() |