Univariate Optimization of a Continuous Function.

DESCRIPTION:

Approximates a local optimum of a continuous univariate function within a given interval.

USAGE:

optimize(f, interval, lower = min(interval), upper = max(interval), 
       tol = .Machine$double.eps^.25, maximum = F, keep.xy = F, ...) 

REQUIRED ARGUMENTS:

f
a real-valued S-PLUS function of the form 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.
interval
a vector of values whose maximum and minimum specify the interval over which the optimization is to take place. (Optional if both lower and upper are specified.)

OPTIONAL ARGUMENTS:

lower
left endpoint of the initial interval.
upper
right endpoint of the initial interval.
tol
desired length of the interval of uncertainty in the final result.
maximum
logical, TRUE if a maximum is sought.
keep.xy
tells whether or not to accumulate the points used by optimize and the corresponding function values as x and y components in the output.
...
additional arguments for f.

VALUE:

a list containing the following elements :
minimum, maximum
a point that is within tol of a local optimum of f in [lower,upper].
singularity
if a singularity is encountered, this is the point at which it occurs.
objective
the value of f at the computed local optimum (or else at a singularity if detected).
nf
the number of times f was evaluated.
interval
smallest subinterval known to contain a local optimum (may be used to restart the algorithm with a smaller tolerance).
message
a statement of the reason for termination.
aux
the list of attributes returned after the last function call.
call
a copy of the call to optimize.
x
the vector of points at which f is evaluated by optimize (in order). Present only if keep.xy = T.
y
the function values associated with x. Present only if keep.xy = T.

NOTE:

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.

METHOD:

Implements Brent's safeguarded polynomial interpolation procedure for univarite minimization based on the Fortran function fmin from NETLIB (Dongarra and Grosse 1987).

REFERENCES:

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.

SEE ALSO:

, .

EXAMPLES:

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)