fminbnd

Find the minimum of a univariate real function within an interval.

Syntax

x = fminbnd(@func,interval)

x = fminbnd(@func,interval,options)

[x,fval,info,output] = fminbnd(...)

Inputs

func
The function to minimize.
interval
A two-element vector containing the interval on which to minimize.
Type: double
Dimension: vector
options
A struct containing option settings.
See optimset for details.

Outputs

x
The location of the function minimum.
fval
The minimum of the function.
info
The convergence status flag.
info = 1
Function value converged to within tolX.
info = 0
Reached maximum number of iterations or function calls.
output
A struct containing iteration details. The members are as follows:
iterations
The number of iterations.
nfev
The number of function evaluations.
xiter
The function values of the interval end points at each iteration.
fvaliter
The interval end points at each iteration.

Examples

Minimize the following function:
function y = func(x)
    y = -log(x) / x;
end

interval = [1, 6];
[x,fval] = fminbnd(@func, interval)
x = 2.71828183
fval = -0.367879441
Modify the previous example to pass an extra parameter to the function using a function handle:
function y = func(x, offset)
    y = -log(x) / x + offset;
end

handle = @(x) func(x, 2);
[x,fval] = fminbnd(handle, interval)
x = 2.71828183
fval = 1.63212056

Comments

fminbnd implements Brent's method for minimization without derivatives.

Options for convergence tolerance controls are specified with optimset.

To pass additional parameters to a function argument, use an anonymous function.

The optimset options and defaults are as follows:
  • MaxIter: 400
  • MaxFunEvals: 1,000,000
  • TolX: 1.0e-7