Rev 51765 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% File src/library/stats/man/uniroot.Rd% Part of the R package, http://www.R-project.org% Copyright 1995-2007 R Core Development Team% Distributed under GPL 2 or later\name{uniroot}\title{One Dimensional Root (Zero) Finding}\usage{uniroot(f, interval, \dots,lower = min(interval), upper = max(interval),f.lower = f(lower, ...), f.upper = f(upper, ...),tol = .Machine$double.eps^0.25, maxiter = 1000)}\alias{uniroot}\arguments{\item{f}{the function for which the root is sought.}\item{interval}{a vector containing the end-points of the intervalto be searched for the root.}\item{\dots}{additional named or unnamed arguments to be passedto \code{f}}\item{lower, upper}{the lower and upper end points of the interval tobe searched.}\item{f.lower, f.upper}{the same as \code{f(upper)} and\code{f(lower)}, respectively. Passing these values from the callerwhere they are often known is more economical as soon as \code{f()}contains non-trivial computations.}\item{tol}{the desired accuracy (convergence tolerance).}\item{maxiter}{the maximum number of iterations.}}\description{The function \code{uniroot} searches the interval from \code{lower}to \code{upper} for a root (i.e., zero) of the function \code{f} withrespect to its first argument.}\details{Note that arguments after \code{\dots} must be matched exactly.Either \code{interval} or both \code{lower} and \code{upper} must bespecified: the upper endpoint must be strictly larger than the lowerendpoint. The function values at the endpoints must be of oppositesigns (or zero).The function uses Fortran subroutine \file{"zeroin"} (from Netlib)based on algorithms given in the reference below. They assume acontinuous function (which then is known to have at least one root inthe interval).Convergence is declared either if \code{f(x) == 0} or the change in\code{x} for one step of the algorithm is less than \code{tol} (plus anallowance for representation error in \code{x}).If the algorithm does not converge in \code{maxiter} steps, a warningis printed and the current approximation is returned.\code{f} will be called as \code{f(\var{x}, ...)} for a numeric valueof \var{x}.}\value{A list with four components: \code{root} and \code{f.root} give thelocation of the root and the value of the function evaluated at thatpoint. \code{iter} and \code{estim.prec} give the number of iterationsused and an approximate estimated precision for \code{root}. (If theroot occurs at one of the endpoints, the estimated precision is\code{NA}.)}\source{Based on \file{zeroin.c} in \url{http://www.netlib.org/c/brent.shar}.}\references{Brent, R. (1973)\emph{Algorithms for Minimization without Derivatives.}Englewood Cliffs, NJ: Prentice-Hall.}\seealso{\code{\link{polyroot}} for all complex roots of a polynomial;\code{\link{optimize}}, \code{\link{nlm}}.}\examples{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 - astr(xmin <- uniroot(f, c(0, 1), tol = 0.0001, a = 1/3))str(uniroot(function(x) x*(x^2-1) + .5, lower = -2, upper = 2,tol = 0.0001), dig = 10)str(uniroot(function(x) x*(x^2-1) + .5, lower = -2, upper = 2,tol = 1e-10 ), dig = 10)\donttest{## 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= 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}}\keyword{optimize}