Find minimum of single-variable function on fixed interval
fminbnd is a one-dimensional minimizer
that finds a minimum for a problem specified by
x, x1, and x2 are finite scalars, and f(x) is a function that returns a scalar.
Find the point where the function takes its minimum in the range .
fun = @sin; x1 = 0; x2 = 2*pi; x = fminbnd(fun,x1,x2)
x = 4.7124
To display precision, this is the same as the correct value .
ans = 4.7124
Minimize a function that is specified by a separate function file. A function accepts a point
x and returns a real scalar representing the value of the objective function at
Write the following function as a file, and save the file as
scalarobjective.m on your MATLAB® path.
function f = scalarobjective(x) f = 0; for k = -10:10 f = f + (k+1)^2*cos(k*x)*exp(-k^2/2); end
x that minimzes
scalarobjective on the interval 1 <=
x <= 3.
x = fminbnd(@scalarobjective,1,3)
x = 2.0061
Minimize a function when there is an extra parameter. The function has a minimum that depends on the value of the parameter . Create an anonymous function of that includes the value of the parameter . Minimize this function over the interval .
a = 9/7; fun = @(x)sin(x-a); x = fminbnd(fun,1,2*pi)
x = 5.9981
This answer is correct; the theoretical value is
3*pi/2 + 9/7
ans = 5.9981
For more information about including extra parameters, see Parameterizing Functions.
Monitor the steps
fminbnd takes to minimize the
fun = @sin; x1 = 0; x2 = 2*pi; options = optimset('Display','iter'); x = fminbnd(fun,x1,x2,options)
Func-count x f(x) Procedure 1 2.39996 0.67549 initial 2 3.88322 -0.67549 golden 3 4.79993 -0.996171 golden 4 5.08984 -0.929607 parabolic 5 4.70582 -0.999978 parabolic 6 4.7118 -1 parabolic 7 4.71239 -1 parabolic 8 4.71236 -1 parabolic 9 4.71242 -1 parabolic Optimization terminated: the current x satisfies the termination criteria using OPTIONS.TolX of 1.000000e-04 x = 4.7124
Find the location of the minimum of and the value of the minimum for .
fun = @sin; [x,fval] = fminbnd(fun,1,2*pi)
x = 4.7124 fval = -1.0000
Return all information about the
fminbnd solution process by requesting all outputs. Also, monitor the solution process using a plot function.
fun = @sin; x1 = 0; x2 = 2*pi; options = optimset('PlotFcns',@optimplotfval); [x,fval,exitflag,output] = fminbnd(fun,x1,x2,options)
x = 4.7124 fval = -1.0000 exitflag = 1 output = struct with fields: iterations: 8 funcCount: 9 algorithm: 'golden section search, parabolic interpolation' message: 'Optimization terminated:...'
fun— Function to minimize
Function to minimize, specified as a function handle or function
fun is a function that accepts a real scalar
returns a real scalar
f (the objective function
fun as a function handle for a file:
x = fminbnd(@myfun,x1,x2)
myfun is a MATLAB® function such
function f = myfun(x) f = ... % Compute function value at x
You can also specify
fun as a function handle
for an anonymous function:
x = fminbnd(@(x)norm(x)^2,x1,x2);
fun = @(x)-x*exp(-3*x)
x1— Lower bound
Lower bound, specified as a real scalar.
x1 = -3
x2— Upper bound
Upper bound, specified as a real scalar.
x2 = 5
options— Optimization options
Optimization options, specified as a structure such as
You can use
optimset to set
or change the values of these fields in the options structure. See Set Options for
Level of display (see Iterative Display):
Check whether objective function values are valid. The
Maximum number of function evaluations allowed, a positive
integer. The default is
Maximum number of iterations allowed, a positive integer.
The default is
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 (
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
options = optimset('Display','iter')
problem— Problem structure
Problem structure, specified as a structure with the following fields.
|Options structure such as returned by |
The simplest way to obtain a
is to export the problem from the Optimization app.
Solution, returned as a real scalar. Typically,
a local solution to the problem when
fval— Objective function value at solution
Objective function value at the solution, returned as a real
fminbnd stopped, returned as an integer.
Function converged to a solution
Number of iterations exceeded
Stopped by an output function or plot function.
The bounds are inconsistent, meaning
output— Information about the optimization process
Information about the optimization process, returned as a structure with fields:
Number of iterations taken
Number of function evaluations
The function to be minimized must be continuous.
fminbnd might only give local solutions.
fminbnd can exhibit slow convergence
when the solution is on a boundary of the interval.
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,
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. Englewood Cliffs, NJ: Prentice Hall, 1976.
 Brent, Richard. P. Algorithms for Minimization without Derivatives. Englewood Cliffs, NJ: Prentice-Hall, 1973.