This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.


Find minimum of single-variable function on fixed interval

fminbnd is a one-dimensional minimizer that finds a minimum for a problem specified by

minxf(x) such that x1<x<x2.

x, x1, and x2 are finite 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(___)



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.


x = fminbnd(fun,x1,x2,options) minimizes with the optimization options specified in options. Use optimset to set these options.

x = fminbnd(problem) finds the minimum for problem, where problem is a structure.


[x,fval] = fminbnd(___), for any input arguments, returns the value of the objective function computed in fun at the solution x.

[x,fval,exitflag] = fminbnd(___) additionally returns a value exitflag that describes the exit condition.


[x,fval,exitflag,output] = fminbnd(___) additionally returns a structure output that contains information about the optimization.


collapse all

Find the point where the $\sin(x)$ function takes its minimum in the range $0< x< 2\pi$.

fun = @sin;
x1 = 0;
x2 = 2*pi;
x = fminbnd(fun,x1,x2)
x =


To display precision, this is the same as the correct value $x = 3\pi/2$.

ans =


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 x.

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);

Find the x that minimzes scalarobjective on the interval 1 <= x <= 3.

x = fminbnd(@scalarobjective,1,3)
x =


Minimize a function when there is an extra parameter. The function $\sin(x-a)$ has a minimum that depends on the value of the parameter $a$. Create an anonymous function of $x$ that includes the value of the parameter $a$. Minimize this function over the interval $0 < x < 2\pi$.

a = 9/7;
fun = @(x)sin(x-a);
x = fminbnd(fun,1,2*pi)
x =


This answer is correct; the theoretical value is

3*pi/2 + 9/7
ans =


For more information about including extra parameters, see Parameterizing Functions.

Monitor the steps fminbnd takes to minimize the $\sin(x)$ function for $0< x< 2\pi$.

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 =


Find the location of the minimum of $\sin(x)$ and the value of the minimum for $0< x< 2\pi$.

fun = @sin;
[x,fval] = fminbnd(fun,1,2*pi)
x =


fval =


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 =


fval =


exitflag =


output = 

  struct with fields:

    iterations: 8
     funcCount: 9
     algorithm: 'golden section search, parabolic interpolation'
       message: 'Optimization terminated:...'

Related Examples

Input Arguments

collapse all

Function to minimize, specified as a function handle or function name. fun is a function that accepts a real scalar x and returns a real scalar f (the objective function evaluated at x).

Specify fun 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

You can also specify fun as a function handle for an anonymous function:

x = fminbnd(@(x)norm(x)^2,x1,x2);

Example: fun = @(x)-x*exp(-3*x)

Data Types: char | function_handle

Lower bound, specified as a real scalar.

Example: x1 = -3

Data Types: double

Upper bound, specified as a real scalar.

Example: x2 = 5

Data Types: double

Optimization options, specified as a structure such as optimset returns. You can use optimset to set or change the values of these fields in the options structure. See Set Options for detailed information.


Level of display (see Iterative Display):

  • 'notify' (default) displays output only if the function does not converge.

  • 'off' or 'none' displays no output.

  • 'iter' displays output at each iteration.

  • 'final' displays just the final output.


Check whether objective function values are valid. The default 'off' allows fminbnd to proceed when the objective function returns a value that is complex or NaN. The 'on' setting throws an error when the objective function returns a value that is complex or NaN.


Maximum number of function evaluations allowed, a positive integer. The default is 500. See Tolerances and Stopping Criteria.


Maximum number of iterations allowed, a positive integer. The default is 500. See Tolerances and Stopping Criteria.


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 Functions.


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 ([]).

  • @optimplotx plots the current point

  • @optimplotfunccount plots the function count

  • @optimplotfval plots the function value

For information on writing a custom plot function, see Plot Functions.


Termination tolerance on x, a positive scalar. The default is 1e-4. See Tolerances and Stopping Criteria.

Example: options = optimset('Display','iter')

Data Types: struct

Problem structure, specified as a structure with the following fields.

Field NameEntry


Objective function


Left endpoint


Right endpoint




Options structure such as returned by optimset

The simplest way to obtain a problem structure is to export the problem from the Optimization app.

Data Types: struct

Output Arguments

collapse all

Solution, returned as a real scalar. Typically, x is a local solution to the problem when exitflag is positive.

Objective function value at the solution, returned as a real number. Generally, fval = fun(x).

Reason fminbnd stopped, returned as an integer.


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.

Information about the optimization process, returned as a structure with fields:


Number of iterations taken


Number of function evaluations


'golden section search, parabolic interpolation'


Exit message


  • 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.

More About

collapse all


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 [1] or [2] for details about the algorithm.


[1] Forsythe, G. E., M. A. Malcolm, and C. B. Moler. Computer Methods for Mathematical Computations. Englewood Cliffs, NJ: Prentice Hall, 1976.

[2] Brent, Richard. P. Algorithms for Minimization without Derivatives. Englewood Cliffs, NJ: Prentice-Hall, 1973.

See Also

| |

Introduced before R2006a

Was this topic helpful?