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 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(fun,x0)
x0
and finds a local minimum x
of the function described in fun
. x0
can be a scalar, vector, or matrix.
minimizes with the optimization parameters specified in the structure x =
fminsearch(fun,x0,options)
options
. You can define these parameters using the optimset
function. fminsearch
uses these options
structure fields:
passes the problem-dependent parameters x =
fminsearch(fun,x0,options,P1,P2,...)
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:
>0 | Indicates that the function converged to a solution x. |
0 | Indicates that the maximum number of function evaluations was exceeded. |
<0 | Indicates that the function did not converge to a solution. |
[x,fval,exitflag,output] = fminsearch(...)
returns a structure output
that contains information about the optimization:
output.algorithm | The algorithm used |
output.funcCount | The number of function evaluations |
output.iterations | The number of iterations taken |
Arguments
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.
where myfun
is a MATLAB function such as
fun
can also be an inline object.
Other arguments are described in the syntax descriptions above.
Examples
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 M-file banana.m
defines the function.
This indicates that the minimizer was found to at least four decimal places with a value near zero.
Move the location of the minimum to the point [a,a^2]
by adding a second parameter to banana.m
.
sets the new parameter to sqrt(2)
and seeks the minimum to an accuracy higher than the default on x
.
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, 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.
No comments:
Post a Comment