Previous: Solvers, Up: Nonlinear Equations [Contents][Index]

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 `fminunc`

or `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 `fminsearch`

. See Optimization, for
minimization with the presence of constraint functions. Note that searches
can be made for maxima by simply inverting the objective function
(`Fto_max = -Fto_min`

).

- Function File:
*[*`x`,`fval`,`info`,`output`] =**fminbnd***(*`fun`,`a`,`b`,`options`) 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 options. Currently,`fminbnd`

recognizes these options:`"FunValCheck"`

,`"OutputFcn"`

,`"TolX"`

,`"MaxIter"`

,`"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:- 1 The algorithm converged to a solution.
- 0 Maximum number of iterations or function evaluations has been exhausted.
- -1 The algorithm has been terminated from user output function.

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`fminunc`

or`fminsearch`

.`fminbnd`

internally uses a Golden Section search strategy.**See also:**fzero, fminunc, fminsearch, optimset.

- Function File:
**fminunc***(*`fcn`,`x0`) - Function File:
**fminunc***(*`fcn`,`x0`,`options`) - Function File:
*[*`x`,`fvec`,`info`,`output`,`grad`,`hess`] =**fminunc***(*`fcn`, …) Solve an unconstrained optimization problem defined by the function

`fcn`.`fcn`should accepts a vector (array) defining the unknown variables, and return the objective function value, optionally with gradient. In other words, this function attempts to determine a vector`x`such that

is a local minimum.`fcn`(`x`)`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:`"FunValCheck"`

,`"OutputFcn"`

,`"TolX"`

,`"TolFun"`

,`"MaxIter"`

,`"MaxFunEvals"`

,`"GradObj"`

,`"FinDiffType"`

,`"TypicalX"`

,`"AutoScaling"`

.If

`"GradObj"`

is`"on"`

, it specifies that`fcn`, called with 2 output arguments, also returns the Jacobian matrix of right-hand sides at the requested point.`"TolX"`

specifies the termination tolerance in the unknown variables, while`"TolFun"`

is a tolerance for equations. Default is`1e-7`

for both`"TolX"`

and`"TolFun"`

.For description of the other options, see

`optimset`

.On return,

`fval`contains the value of the function`fcn`evaluated at`x`, and`info`may be one of the following values:- 1
Converged to a solution point. Relative gradient error is less than specified by TolFun.

- 2
Last relative step size was less that TolX.

- 3
Last relative decrease in function value was less than TolF.

- 0
Iteration limit exceeded.

- -3
The trust region radius became excessively small.

Optionally, fminunc can also yield a structure with convergence statistics (

`output`), the output gradient (`grad`) and approximate Hessian (`hess`).Notes: If you only have a single nonlinear equation of one variable then using

`fminbnd`

is usually a much better idea. The algorithm used 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`fminsearch`

.**See also:**fminbnd, fminsearch, optimset.

- Function File:
`x`=**fminsearch***(*`fun`,`x0`) - Function File:
`x`=**fminsearch***(*`fun`,`x0`,`options`) - Function File:
*[*`x`,`fval`] =**fminsearch***(…)* -
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`fminunc`

fails.Options for the search are provided in the parameter

`options`using the function`optimset`

. Currently,`fminsearch`

accepts the options:`"TolX"`

,`"MaxFunEvals"`

,`"MaxIter"`

,`"Display"`

. For a description of these options, see`optimset`

.On exit, the function returns

`x`, the minimum point, and`fval`, the function value thereof.Example usages:

fminsearch (@(x) (x(1)-5).^2+(x(2)-8).^4, [0;0]) fminsearch (inline ("(x(1)-5).^2+(x(2)-8).^4", "x"), [0;0])

Previous: Solvers, Up: Nonlinear Equations [Contents][Index]