vuniroot2 {TukeyGH77} | R Documentation |
Vectorised One Dimensional Root (Zero) Finding
Description
To solve a monotone function y = f(x)
for a given vector of y
values.
Usage
vuniroot2(
y,
f,
interval = stop("must provide a length-2 `interval`"),
tol = .Machine$double.eps^0.25,
maxiter = 1000L
)
Arguments
y |
|
f |
monotone function |
interval |
|
tol |
double scalar, desired accuracy, i.e., convergence tolerance |
maxiter |
integer scalar, maximum number of iterations |
Details
Function vuniroot2, different from vuniroot, does
accept
NA_real_
as element(s) ofy
handle the case when the analytic root is at
lower
and/orupper
return a root of
Inf
(ifabs(f(lower)) >= abs(f(upper))
) or-Inf
(ifabs(f(lower)) < abs(f(upper))
), when the function valuef(lower)
andf(upper)
are not of opposite sign.
Value
Function vuniroot2 returns a numeric vector x
as the solution of y = f(x)
with given vector y
.
Examples
library(rstpm2)
stopifnot(packageDate('rstpm2') == as.Date('2023-12-03')) # not base::identical
# ?rstpm2::vuniroot does not accept NA \eqn{y}
tryCatch(vuniroot(function(x) x^2 - c(NA, 2:9), lower = 1, upper = 3), error = identity)
# ?rstpm2::vuniroot not good when the analytic root is at `lower` or `upper`
f <- function(x) x^2 - 1:9
vuniroot(f, lower = .99, upper = 3.001) # good
tryCatch(vuniroot(f, lower = 1, upper = 3, extendInt = 'no'), warning = identity)
tryCatch(vuniroot(f, lower = 1, upper = 3, extendInt = 'yes'), warning = identity)
tryCatch(vuniroot(f, lower = 1, upper = 3, extendInt = 'downX'), error = identity)
tryCatch(vuniroot(f, lower = 1, upper = 3, extendInt = 'upX'), warning = identity)
vuniroot2(c(NA, 1:9), f = function(x) x^2, interval = c(1, 3)) # all good
[Package TukeyGH77 version 0.1.2 Index]