uniroot(f, interval,
lower = min(interval), upper = max(interval),
tol = .Machine$double.eps^.25, keep.xy = F,
f.lower = NA, f.upper = NA, ...)
f(x,<additional arguments>), where
x is the variable in question. Users can accumulate information through
attributes of the function value. If the attributes includes additional
arguments of
f, the next function call will use the new values of those
arguments.
lower and
upper are specified.)
uniroot and the
corresponding function values as
x and
y components in the output.
f at the left endpoint of the initial interval.
f at the right endpoint of the initial interval.
f.
tol of a root or zero of
f in
[lower,upper].
f at
root.
f was evaluated.
root for which the sign of
f is known to be
negative/positive.
May be used as interval endpoints when restarting the algorithm with a smaller
value of tolerance.
f at
neg and
pos, respectively.
uniroot.
f is evaluated by
uniroot (in order).
Present only if
keep.xy = T.
x.
Present only if
keep.xy = T.
The function
f must have opposite signs at the initial endpoints
lower
and
upper, in order to ensure that
f actually has a root within
[lower,upper]
.
Function values should be computed in C or Fortran within
the outer S-PLUS function for greater efficiency.
The
uniroot function may not be called
recursively, that is,
f may not call
uniroot
. Recursive calls would overwrite
information that is stored internally.
Implements Brent's safeguarded polynomial interpolation procedure for solving a univariate nonlinear equation, based on the Fortran function zeroin 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.
solveNonlinear
function.
cubic <- function(x, c2, c1, c0) {(x - c2) *
(x - c1) * (x - c0)}
uniroot(cubic, c(1,3), keep.xy=T, c2=-2, c1=0, c0=2)
cubic <- function(x, c2, c1, c0, nf=0,
all=list(x=NULL, y=NULL)) {
value <- (x - 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 }
uniroot(cubic, lower=1, upper=3, c2=-2, c1=0, c0=2)