fminbnd
Finds a local minimum of a function of one variable inside a fixed interval.
Category: Mathematics > Optimization
Syntax
x = fminbnd(fun, x1, x2)
Returns the point in [x1, x2] where fun reaches a local minimum.
x = fminbnd(fun, x1, x2, options)
Same, with settings created by optimset.
[x, fval, exitflag, output] = fminbnd(___)
Also returns the minimum value, a status flag and a struct with run statistics.
Description
The method combines golden section search, which always shrinks the interval by a fixed ratio, with parabolic interpolation, which converges faster when the function is smooth near the minimum. It needs no derivatives.
Only a local minimum is guaranteed, and it can lie on an end point if the function keeps decreasing toward it. To maximize, minimize the negative of the function.
Input arguments
fun- Function handle that takes a scalar and returns a scalar.
x1, x2- Finite end points of the search interval, with
x1 < x2. options- Struct from
optimset;TolX(default1e-4) andMaxIterare the options that matter.
Output arguments
x- The location of the minimum found inside the interval.
fval- Value of
funatx. exitflag1when the method converged,0when the iteration limit was reached.output- Struct with the fields
iterations,funcCount,algorithmandmessage.
Examples
Minimum of a parabola
[x, fval, flag] = fminbnd(@(x) (x-2)^2 + 1, 0, 5);
fprintf('x = %.4f, f = %.4f, flag = %d\n', x, fval, flag)
Output
x = 2.0000, f = 1.0000, flag = 1
Trough of the sine
x = fminbnd(@sin, 3, 6);
fprintf('%.4f (3*pi/2 = %.4f)\n', x, 3*pi/2)
Output
4.7124 (3*pi/2 = 4.7124)