optimize(f, interval, lower = min(interval), upper = max(interval), tol = .Machine$double.eps^.25, maximum = F, keep.xy = F, ...)
f(x,<additional arguments>)
, where
x
is the variable over which the optimization is to take place. Users can
accumulate information through attributes of the function value. If the
attributes include any additional arguments of
f
, the next call to
f
will
use the new values of those arguments.
lower
and
upper
are specified.)
TRUE
if a maximum is sought.
optimize
and the
corresponding function values as
x
and
y
components in the output.
f
.
tol
of a local optimum of
f
in
[lower,upper]
.
f
at the computed local optimum (or else at a singularity
if detected).
f
was evaluated.
optimize
.
f
is evaluated by
optimize
(in order).
Present only if
keep.xy = T
.
x
.
Present only if
keep.xy = T
.
The optimum produced by
optimize
may not be a global optimum of
f
over
[lower,upper]
unless
f
happens to be unimodal on
[lower,upper]
.
Function values should be computed in C or Fortran within
the outer S-PLUS function for greater efficiency.
For multivariate minimization, see
nlminb
.
The
optimize
function may not be called
recursively, that is,
f
may not include a
call to
optimize
. Recursive calls would
overwrite information that is stored internally.
Implements Brent's safeguarded polynomial interpolation procedure for univarite minimization based on the Fortran function fmin from NETLIB (Dongarra and Grosse 1987).
Brent, R. (1973).
Algorithms for minimization without derivatives.
Prentice-Hall, Englewood Cliffs, NJ, USA.
Dongarra, J. J., and Grosse, E. (1987).
Distribution of mathematical software via electronic mail,
Communications of the ACM
30
, pp. 403-407.
quadratic <- function( x, c2, c1, c0) {c0 + x*(c1 + x*c2)} optimize(quadratic, interval = c(1,3), max = T, keep.xy = T, c2 = -1, c1 = 4, c0 = 0) quadratic <- function( x, c2, c1, c0, nf = 0, all = list( x = NULL, y = NULL)) {value <- c0 + x*(c1 + x*c2) attributes(value) <- list( nf = nf + length(x), all = list( x = c(all$x, x), y = c(all$y, value))) value} optimize(quadratic, lower = 1, upper = 3, max = T, c2 = -1, c1 = 4, c0 = 0)