Section 31.2 How fminbnd
works
Matlab has a built-in command fminbnd
for minimizing a function \(f\) on a given interval \([a, b]\text{.}\) Its format is x = fminbnd(f, a, b)
. We can get additional information about its work from the option optimset('Display', 'iter')
which displays every step of the algorithm.
f = @(x) sin(x)+sin(4*x); a = -4; b = 5; x = fminbnd(f, a, b, optimset('Display', 'iter')); t = linspace(a, b, 1000); plot(t, f(t), 'b', x, f(x), 'r*')
The log shows that fminbnd
uses the combination of parabolic interpolation (fast but fails often) with golden section (fallback method, reliable but slow). Toward the end, when the search arrives in a neighborhood of a minimum, parabolic interpolation takes over. In general, the minimum will be a local one.
Try the above code with the function f = @(x) cos(x/3)
instead. There is not a single use of parabolic interpolation anymore. Why?
There are three ways to learn more about Matlab functions such as this one.
-
help fminbnd
shows a brief plain-text description, focused on the syntax and examples of use -
doc fminbnd
opens a new window with more information, including an outline of the algorithm used and its limitations -
open fminbnd
shows the code of the function if it is itself written in Matlab (for example,fzero
,fminbnd
andfminsearch
are butfft
is not)
The source code shows that fminbnd
tries parabolic interpolation first and falls back on golden section when the parabola is considered unacceptable.