Documentation |
Find minimum of single-variable function on fixed interval
Finds a minimum for a problem specified by
$$\underset{x}{\mathrm{min}}f(x)\text{suchthat}{x}_{1}x{x}_{2}.$$
x, x_{1}, and x_{2} 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:
fun | 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 | Options provides the function-specific details for the options values. | |
problem | objective | Objective function |
x1 | Left endpoint | |
x2 | Right endpoint | |
solver | 'fminbnd' | |
options | 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:
exitflag | Integer identifying the reason the algorithm terminated. The following lists the values of exitflag and the corresponding reasons the algorithm terminated. | |
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. | |
output | Structure containing information about the optimization. The fields of the structure are | |
iterations | Number of iterations taken | |
funcCount | Number of function evaluations | |
algorithm | 'golden section search, parabolic interpolation' | |
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.
Display | 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. |
FunValCheck | 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. |
MaxFunEvals | Maximum number of function evaluations allowed, a positive integer. The default is 500. |
MaxIter | Maximum number of iterations allowed, a positive integer. The default is 500. |
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 Function. |
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 ([]).
For information on writing a custom plot function, see Plot Functions. |
TolX | 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.
[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