uniroot searches the interval from
upper for a root (i.e., zero) of the function
f with respect to its first argument.
uniroot(f, interval, ..., lower = min(interval), upper = max(interval), f.lower = f(lower, ...), f.upper = f(upper, ...), tol = .Machine$double.eps^0.25, maxiter = 1000)
- the function for which the root is sought.
- a vector containing the end-points of the interval to be searched for the root.
- additional named or unnamed arguments to be passed to
- lower, upper
- the lower and upper end points of the interval to be searched.
- f.lower, f.upper
- the same as
f(lower), respectively. Passing these values from the caller where they are often known is more economical as soon as
f()contains non-trivial computations.
- the desired accuracy (convergence tolerance).
- the maximum number of iterations.
Note that arguments after
... must be matched exactly.
interval or both
upper must be specified: the upper endpoint must be strictly larger than the lower endpoint. The function values at the endpoints must be of opposite signs (or zero).
The function uses Fortran subroutine ‘"zeroin"’ (from Netlib) based on algorithms given in the reference below. They assume a continuous function (which then is known to have at least one root in the interval).
Convergence is declared either if
f(x) == 0 or the change in
x for one step of the algorithm is less than
tol (plus an allowance for representation error in
If the algorithm does not converge in
maxiter steps, a warning is printed and the current approximation is returned.
f will be called as
f(<var>x</var>, ...) for a numeric value of x.
The argument passed to
f has special semantics and used to be shared between calls. The function should not copy it.
A list with at least four components:
f.root give the location of the root and the value of the function evaluated at that point.
estim.prec give the number of iterations used and an approximate estimated precision for
root. (If the root occurs at one of the endpoints, the estimated precision is
Further components may be added in future.
Brent, R. (1973) Algorithms for Minimization without Derivatives. Englewood Cliffs, NJ: Prentice-Hall.
require(utils) # for str ## some platforms hit zero exactly on the first step: ## if so the estimated precision is 2/3. f <- function (x, a) x - a str(xmin <- uniroot(f, c(0, 1), tol = 0.0001, a = 1/3)) ## handheld calculator example: fixed point of cos(.): uniroot(function(x) cos(x) - x, lower = -pi, upper = pi, tol = 1e-9)$root str(uniroot(function(x) x*(x^2-1) + .5, lower = -2, upper = 2, tol = 0.0001)) str(uniroot(function(x) x*(x^2-1) + .5, lower = -2, upper = 2, tol = 1e-10)) ## Find the smallest value x for which exp(x) > 0 (numerically): r <- uniroot(function(x) 1e80*exp(x) - 1e-300, c(-1000, 0), tol = 1e-15) str(r, digits.d = 15) # around -745, depending on the platform. exp(r$root) # = 0, but not for r$root * 0.999... minexp <- r$root * (1 - 10*.Machine$double.eps) exp(minexp) # typically denormalized
Documentation reproduced from R 3.0.2. License: GPL-2.