fminbnd.RdFind minimum of single-variable function on fixed interval.
fminbnd(f, a, b, maxiter = 1000, maximum = FALSE,
tol = 1e-07, rel.tol = tol, abs.tol = 1e-15, ...)function whose minimum or maximum is to be found.
endpoints of the interval to be searched.
maximal number of iterations.
logical; shall maximum or minimum be found; default FALSE.
relative tolerance; left over for compatibility.
relative and absolute tolerance.
additional variables to be passed to the function.
fminbnd finds the minimum of a function of one variable within a fixed interval. It applies Brent's algorithm, based on golden section search and parabolic interpolation.
fminbnd may only give local solutions.
fminbnd never evaluates f at the endpoints.
List with
location of the minimum resp. maximum.
function value at the optimum.
number of iterations used.
estimated precision.
R. P. Brent (1973). Algorithms for Minimization Without Derivatives. Dover Publications, reprinted 2002.
fminbnd mimics the Matlab function of the same name.
## CHEBFUN example by Trefethen
f <- function(x) exp(x)*sin(3*x)*tanh(5*cos(30*x))
fminbnd(f, -1, 1) # fourth local minimum (from left)
#> $xmin
#> [1] -0.2429114
#>
#> $fmin
#> [1] -0.517464
#>
#> $niter
#> [1] 17
#>
#> $estim.prec
#> [1] 2.429114e-08
#>
g <- function(x) complexstep(f, x) # complex-step derivative
xs <- findzeros(g, -1, 1) # local minima and maxima
ys <- f(xs); n0 <- which.min(ys) # index of global minimum
fminbnd(f, xs[n0-1], xs[n0+1]) # xmin:0.7036632, fmin: -1.727377
#> $xmin
#> [1] 0.7036632
#>
#> $fmin
#> [1] -1.727377
#>
#> $niter
#> [1] 14
#>
#> $estim.prec
#> [1] 7.036632e-08
#>
if (FALSE) { # \dontrun{
ezplot(f, -1, 1, n = 1000, col = "darkblue", lwd = 2)
ezplot(function(x) g(x)/150, -1, 1, n = 1000, col = "darkred", add = TRUE)
grid()} # }