Often it is useful to find the minimum value of a function rather than just
the zeroes where it crosses the x-axis.
fminbnd is designed for the
simpler, but very common, case of a univariate function where the interval
to search is bounded. For unbounded minimization of a function with
potentially many variables use
fminsearch. The two
functions use different internal algorithms and some knowledge of the objective
function is required. For functions which can be differentiated,
fminunc is appropriate. For functions with discontinuities, or for
which a gradient search would fail, use
See Optimization, for minimization with the presence of constraint
functions. Note that searches can be made for maxima by simply inverting the
Fto_max = -Fto_min).
Find a minimum point of a univariate function.
fun should be a function handle or name. a, b specify a
starting interval. options is a structure specifying additional
fminbnd recognizes these options:
"MaxFunEvals". For a description of these
options, see optimset.
On exit, the function returns x, the approximate minimum point and fval, the function value thereof.
info is an exit flag that can have these values:
Notes: The search for a minimum is restricted to be in the interval bound by
a and b. If you only have an initial point to begin searching
from you will need to use an unconstrained minimization algorithm such as
fminbnd internally uses a
Golden Section search strategy.
See also: fzero, fminunc, fminsearch, optimset.
Solve an unconstrained optimization problem defined by the function fcn.
fcn should accept a vector (array) defining the unknown variables, and
return the objective function value, optionally with gradient.
fminunc attempts to determine a vector x such that
fcn (x) is a local minimum.
x0 determines a starting guess. The shape of x0 is preserved in all calls to fcn, but otherwise is treated as a column vector.
options is a structure specifying additional options. Currently,
fminunc recognizes these options:
"on", it specifies that fcn, when
called with two output arguments, also returns the Jacobian matrix of
partial first derivatives at the requested point.
the termination tolerance for the unknown variables x, while
TolFun is a tolerance for the objective function value fval.
The default is
1e-7 for both options.
For a description of the other options, see
On return, x is the location of the minimum and fval contains the value of the objective function at x.
info may be one of the following values:
Converged to a solution point. Relative gradient error is less than
Last relative step size was less than
Last relative change in function value was less than
Iteration limit exceeded—either maximum number of algorithm iterations
MaxIter or maximum number of function evaluations
Algorithm terminated by
The trust region radius became excessively small.
fminunc can return a structure with convergence
statistics (output), the output gradient (grad) at the
solution x, and approximate Hessian (hess) at the solution
Application Notes: If the objective function is a single nonlinear equation
of one variable then using
fminbnd is usually a better choice.
The algorithm used by
fminunc is a gradient search which depends
on the objective function being differentiable. If the function has
discontinuities it may be better to use a derivative-free algorithm such as
See also: fminbnd, fminsearch, optimset.
Find a value of x which minimizes the function fun.
The search begins at the point x0 and iterates using the
Nelder & Mead Simplex algorithm (a derivative-free method). This
algorithm is better-suited to functions which have discontinuities or for
which a gradient-based search such as
Options for the search are provided in the parameter options using the
fminsearch accepts the options:
For a description of these options, see
Additional inputs for the function fun can be passed as the fourth
and higher arguments. To pass function arguments while using the default
options values, use
 for options.
On exit, the function returns x, the minimum point, and fval, the function value at the minimum.
The third return value exitflag is
if the algorithm converged
(size of the simplex is smaller than
the step in the function value between iterations is smaller than
if the maximum number of iterations or the maximum number of function evaluations are exceeded.
if the iteration is stopped by the
The fourth return value is a structure output with the fields,
funcCount containing the number of function calls to fun,
iterations containing the number of iteration steps,
algorithm with the name of the search algorithm (always:
"Nelder-Mead simplex direct search"), and
with the exit message.
fminsearch (@(x) (x(1)-5).^2+(x(2)-8).^4, [0;0])
See also: fminbnd, fminunc, optimset.
humps is a useful function for testing zero and
extrema finding functions.
Evaluate a function with multiple minima, maxima, and zero crossings.
The output y is the evaluation of the rational function:
1200*x^4 - 2880*x^3 + 2036*x^2 - 348*x - 88 y = - --------------------------------------------- 200*x^4 - 480*x^3 + 406*x^2 - 138*x + 17
x may be a scalar, vector or array. If x is omitted, the default range [0:0.05:1] is used.
When called with two output arguments, [x, y], x will
contain the input values, and y will contain the output from
humps has two local maxima located near x =
0.300 and 0.893, a local minimum near x = 0.637, and zeros near
x = -0.132 and 1.300.
humps is a useful function for testing
algorithms which find zeros or local minima and maxima.
demo humps to see a plot of the
See also: fzero, fminbnd, fminunc, fminsearch.