Find minimum of single-variable function on fixed interval
Finds a minimum for a problem specified by
x, x1, and x2 are scalars and f(x) is a function that returns a scalar.
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 attempts to find a minimum of a function of one variable within a fixed interval.
Note: Passing Extra Parameters explains how to pass extra parameters to the objective function, if necessary.
x = fminbnd(fun,x1,x2) returns a value x that is a local minimizer of the scalar valued function that is described in fun in the interval x1 < x < x2. fun is either a function handle to a file or is an anonymous function.
x = fminbnd(problem) finds the minimum for problem, where problem is a structure described in Input Arguments.
Create the structure problem by exporting a problem from Optimization app, as described in Exporting Your Work.
Function Arguments contains general descriptions of arguments passed into fminbnd. This section provides function-specific details for fun, options, and problem:
The function to be minimized. fun is a function handle for a function that accepts a scalar x and returns a scalar f, the objective function evaluated at x. The function fun can be specified as a function handle for a file:
x = fminbnd(@myfun,x1,x2)
where myfun is a MATLAB® function such as
function f = myfun(x) f = ... % Compute function value at x.
fun can also be a function handle for an anonymous function.
x = fminbnd(@(x)sin(x^2),x1,x2);
Options provides the function-specific details for the options values.
|Options structure created using optimset|
Function Arguments contains general descriptions of arguments returned by fminbnd. This section provides function-specific details for exitflag and output:
Integer identifying the reason the algorithm terminated. The following lists the values of exitflag and the corresponding reasons the algorithm terminated.
Function converged to a solution x.
Number of iterations exceeded options.MaxIter or number of function evaluations exceeded options.MaxFunEvals.
Stopped by an output function or plot function.
The bounds are inconsistent, meaning x1 > x2.
Structure containing information about the optimization. The fields of the structure are
Number of iterations taken
Number of function evaluations
'golden section search, parabolic interpolation'
Level of display. 'off' or 'none' displays no output; 'iter' displays output at each iteration; 'final' displays just the final output; 'notify' (default) displays output only if the function does not converge.
Check whether objective function values are valid. 'on' displays an error when the objective function returns a value that is complex, Inf, or NaN. The default 'off' displays no error.
Maximum number of function evaluations allowed, a positive integer. The default is 500.
Maximum number of iterations allowed, a positive integer. The default is 500.
Specify one or more user-defined functions that an optimization function calls at each iteration, either as a function handle or as a cell array of function handles. The default is none (). See Output Function.
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 ().
For information on writing a custom plot function, see Plot Functions.
Termination tolerance on x, a positive scalar. The default is 1e-4.
A minimum of sin(x) occurs at
x = fminbnd(@sin,0,2*pi) x = 4.7124
The value of the function at the minimum is
y = sin(x) y = -1.0000
To find the minimum of the function
f(x) = (x – 3)2 – 1,
on the interval (0,5), first write a function file.
function f = myfun(x) f = (x-3)^2 - 1;
Next, call an optimization routine.
x = fminbnd(@myfun,0,5)
This generates the solution
x = 3
The value at the minimum is
y = myfun(x) y = -1
If fun is parameterized, you can use anonymous functions to capture the problem-dependent parameters. For example, suppose you want to minimize the objective function myfun defined by the following function file:
function f = myfun(x,a) f = (x - a)^2;
Note that myfun has an extra parameter a, so you cannot pass it directly to fminbind. To optimize for a specific value of a, such as a = 1.5.
The function to be minimized must be continuous. fminbnd might only give local solutions.
fminbnd often exhibits slow convergence when the solution is on a boundary of the interval. In such a case, fmincon often gives faster and more accurate solutions.
fminbnd only handles real variables.
fminbnd is a function file. The algorithm is based on golden section search and parabolic interpolation. Unless the left endpoint x1 is very close to the right endpoint x2, fminbnd never evaluates fun at the endpoints, so fun need only be defined for x in the interval x1 < x < x2.
If the minimum actually occurs at x1 or x2, fminbnd returns a point x in the interior of the interval (x1,x2) that is close to the minimizer. In this case, the distance of x from 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.