Find minimum of single-variable function on fixed interval
x = fminbnd(fun,x1,x2)
x = fminbnd(fun,x1,x2,options)
x = fminbnd(problem)
[x,fval] = fminbnd(...)
[x,fval,exitflag] = fminbnd(...)
[x,fval,exitflag,output] = fminbnd(...)
fminbnd finds the minimum of a function
of one variable within a fixed interval.
x = fminbnd(fun,x1,x2) returns
x that is a local minimizer of the function
that is described in
fun in the interval
< x < x2.
fun is a
Parameterizing Functions in the MATLAB® Mathematics
documentation, explains how to pass additional parameters to your
x = fminbnd(fun,x1,x2,options) minimizes
with the optimization parameters specified in the structure
You can define these parameters using the
options structure fields:
Level of display.
Check whether objective function values are valid.
Maximum number of function evaluations allowed.
Maximum number of iterations allowed.
User-defined function that is called at each iteration. See Output Functions in MATLAB Mathematics for more information.
Plots various measures of progress while the algorithm
executes, select from predefined plots or write your own. Pass a function
handle or a cell array of function handles. The default is none (
See Plot Functions in MATLAB Mathematics for more information.
Termination tolerance on
x = fminbnd(problem) finds the minimum
a structure with the following fields:
|Options structure created using |
[x,fval] = fminbnd(...) returns
the value of the objective function computed in
[x,fval,exitflag] = fminbnd(...) returns
exitflag that describes the exit condition
Maximum number of function evaluations or iterations was reached.
Algorithm was terminated by the output function.
Bounds are inconsistent (
[x,fval,exitflag,output] = fminbnd(...) returns
output that contains information about
the optimization in the following fields:
Number of function evaluations
Number of iterations
fun is the function to be minimized.
x and returns a scalar
the objective function evaluated at
x. The function
be specified as a function handle for a function file
x = fminbnd(@myfun,x1,x2);
myfun.m is a function file such as
function f = myfun(x) f = ... % Compute function value at x.
or as a function handle for an anonymous function:
x = fminbnd(@(x) sin(x*x),x1,x2);
Other arguments are described in the syntax descriptions above.
x = fminbnd(@cos,3,4) computes π to
a few decimal places and gives a message on termination.
[x,fval,exitflag] = ... fminbnd(@cos,3,4,optimset('TolX',1e-12,'Display','off'))
computes π to about 12 decimal places,
suppresses output, returns the function value at
and returns an
exitflag of 1.
fun can also be a function handle
for an anonymous function. For example, to find the minimum of the
function f(x) = x3 – 2x – 5 on the interval
create an anonymous function
f = @(x)x.^3-2*x-5;
x = fminbnd(f, 0, 2)
The result is
x = 0.8165
The value of the function at the minimum is
y = f(x) y = -6.0887
fun is parameterized, you can use anonymous
functions to capture the problem-dependent parameters. For example,
suppose you want to minimize the objective function
by the following function file:
function f = myfun(x,a) f = (x - a)^2;
myfun has an extra parameter
so you cannot pass it directly to
fminbnd. To optimize
for a specific value of
a, such as
Assign the value to
a = 1.5; % define parameter first
a one-argument anonymous function that captures that value of
myfun with two arguments:
x = fminbnd(@(x) myfun(x,a),0,1)
The function to be minimized must be continuous.
only give local solutions.
fminbnd often exhibits slow convergence
when the solution is on a boundary of the interval.
fminbnd only handles real variables.
fminbnd is a function file. Its algorithm
is based on golden section search and parabolic interpolation. Unless
the left endpoint x1 is
very close to the right endpoint x2,
fun at the endpoints, so
only be defined for x in the interval x1 < x < x2.
If the minimum actually occurs at x1 or x2,
x in the interior of the interval (x1,x2)
that is close to the minimizer. In this case, the distance of
the minimizer is no more than 2*
(TolX + 3*abs(x)*sqrt(eps)). See  or  for details about the algorithm.
 Forsythe, G. E., M. A. Malcolm, and C. B. Moler, Computer Methods for Mathematical Computations, Prentice-Hall, 1976.
 Brent, Richard. P., Algorithms for Minimization without Derivatives, Prentice-Hall, Englewood Cliffs, New Jersey, 1973