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(fun,x1,x2,options)
minimizes
with the optimization options specified in the structure options
.
Use optimset
to set these options.
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.
[x,fval] = fminbnd(...)
returns
the value of the objective function computed in fun
at
the solution x
.
[x,fval,exitflag] = fminbnd(...)
returns
a value exitflag
that describes the exit condition
of fminbnd
.
[x,fval,exitflag,output] = fminbnd(...)
returns
a structure output
that contains information about
the optimization.
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. x = fminbnd(@myfun,x1,x2) where function f = myfun(x) f = ... % Compute function value at x.
x = fminbnd(@(x)sin(x^2),x1,x2); | |
| Options provides the function-specific details for the | |
problem |
| Objective function |
| Left endpoint | |
| Right endpoint | |
| 'fminbnd' | |
| 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 | |
| Function converged to a solution | |
| Number of iterations exceeded | |
| Stopped by an output function or plot function. | |
| The bounds are inconsistent, meaning | |
| Structure containing information about the optimization. The fields of the structure are | |
iterations | Number of iterations taken | |
funcCount | Number of function evaluations | |
algorithm |
| |
message | Exit message |
Optimization options used by fminbnd
. You
can use optimset
to set or change
the values of these fields in the options structure options
.
See Optimization Options Reference for detailed
information.
| Level of display. |
FunValCheck | Check whether objective function values are valid. |
| Maximum number of function evaluations allowed, a positive
integer. The default is |
| Maximum number of iterations allowed, a positive integer.
The default is |
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 ( |
| 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 |
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 fminbnd
. To optimize
for a specific value of a
, such as a =
1.5
.
Assign the value to a
.
a = 1.5; % define parameter first
Call fminbnd
with
a one-argument anonymous function that captures that value of a
and
calls myfun
with two arguments:
x = fminbnd(@(x) myfun(x,a),0,1) x = 0.9999
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.
[1] Forsythe, G.E., M.A. Malcolm, and C.B. Moler, Computer Methods for Mathematical Computations, Prentice Hall, 1976.
[2] Brent, Richard. P., Algorithms for Minimization without Derivatives, Prentice-Hall, Englewood Cliffs, New Jersey, 1973.
fmincon
| fminsearch
| fminunc
| optimset
| optimtool