uniroot(f, interval, ..., lower = min(interval), upper = max(interval), f.lower = f(lower, ...), f.upper = f(upper, ...), extendInt = c("no", "yes", "downX", "upX"), check.conv = FALSE, tol = .Machine$double.eps^0.25, maxiter = 1000, trace = 0)
f | a real-valued function of one or more arguments. The first argument, no matter what its name, is varied in the search for a root. The other arguments should be supplied as the ... argument to uniroot. | ||||||
interval | a vector of 2 numeric values whose maximum and minimum values specify the interval over which the minimization is be determined. Not required if you specify both lower and upper. | ||||||
... | additional arguments for f. | ||||||
lower | n numeric value that specifies the lower endpoint of the initial interval to search. | ||||||
upper | a numeric value that specifies the upper endpoint of the initial interval to search. Should be greater than lower. | ||||||
f.lower | the numeric value of f at the lower endpoint of the initial interval. Its default value is f(lower,...) so it is almost never required. Try it if f has value NaN at lower, but you know the limiting value there. | ||||||
f.upper | the numeric value of f at the upper endpoint of the initial interval. | ||||||
extendInt | One of the character strings "no" (the default), "yes", "downX", or "upX", determining how to extend the interval if the function does not cross zero in the given interval. See Details for their descriptions. | ||||||
check.conv | a logical value. If FALSE (the default), just warn if the root could not be found to to desired accuracy. If TRUE, give an error in that case. | ||||||
tol | a numeric value indicating the desired accuracy in the final result. | ||||||
maxiter | an integer that specifies the maximum number of iterations. | ||||||
trace |
a non-negative integer specifying the trace level while extending
the initial interval.
Can be one of the following.
|
root | a numeric value that is within the accuracy value specified in tol of a zero of f in the range [lower,upper](maybe the modified). |
f.root | value of f at root. |
iter | the number of iterations required to find the root. This value includes the iterations required to extend the interval. |
init.it | an integer value specifying the number of steps required to extend the the interval so that f crossed zero in this expanded interval. NA if the interval did not need to be expanded. |
estim.prec | a numeric value that shows the approximate estimated precision for root. |
cubic <- function(x, c2, c1, c0) {(x - c2) * (x - c1) * (x - c0)} uniroot(cubic, c(1,3), c2=-2, c1=-0.5, c0=2) # root at 2 uniroot(cubic, c(-1,1), c2=-2, c1=-0.5, c0=2) # root at -0.5try(uniroot(cubic, c(3,5), c2=-2, c1=-0.5, c0=2)) uniroot(cubic, c(3,5), c2=-2, c1=-0.5, c0=2, extendInt = "yes", trace=2)
# convergence checking try(uniroot(cubic, c(1,5), c2=-2, c1=-0.5, c0=2, maxiter=3, check.conv=TRUE)) # Error stop uniroot(cubic, c(1,5), c2=-2, c1=-0.5, c0=2, maxiter=3) # just warning.