# Documentation

### This is machine translation

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

# fminbnd

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.

## Syntax

• x = fminbnd(fun,x1,x2)
example
• x = fminbnd(fun,x1,x2,options)
example
• x = fminbnd(problem)
• [x,fval] = fminbnd(___)
example
• [x,fval,exitflag] = fminbnd(___)
• [x,fval,exitflag,output] = fminbnd(___)
example

## Description

example

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.

example

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.

example

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

example

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

## Examples

collapse all

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 .

3*pi/2
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 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);
end

Find the 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 function for .

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:...'

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

 Display 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. FunValCheck 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. MaxFunEvals Maximum number of function evaluations allowed, a positive integer. The default is 500. See Tolerances and Stopping Criteria. MaxIter Maximum number of iterations allowed, a positive integer. The default is 500. See Tolerances and Stopping Criteria. OutputFcn 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. PlotFcns 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 valueFor information on writing a custom plot function, see Plot Functions. TolX 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

Objective function

x1

Left endpoint

x2

Right endpoint

solver

'fminbnd'

options

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.

 1 Function converged to a solution x. 0 Number of iterations exceeded options.MaxIter or number of function evaluations exceeded options.MaxFunEvals. -1 Stopped by an output function or plot function. -2 The bounds are inconsistent, meaning x1 > x2.

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

 iterations Number of iterations taken funcCount Number of function evaluations algorithm 'golden section search, parabolic interpolation' message Exit message

## Limitations

• 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

### Algorithms

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.

## References

[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?

Watch now