vuniroot2 | R Documentation |
To solve a monotone function y = f(x)
for a given vector of y
values.
vuniroot2(
y,
f,
interval = stop("must provide a length-2 `interval`"),
tol = .Machine$double.eps^0.25,
maxiter = 1000L
)
y |
numeric vector of |
f |
monotone function |
interval |
length-2 numeric vector |
tol |
double scalar, desired accuracy, i.e., convergence tolerance |
maxiter |
integer scalar, maximum number of iterations |
Function vuniroot2()
, different from vuniroot, does
accept NA_real_
as element(s) of y
handle the case when the analytic root is at lower
and/or upper
return a root of
Inf
(if abs(f(lower)) >= abs(f(upper))
) or
-Inf
(if abs(f(lower)) < abs(f(upper))
),
when the function value f(lower)
and f(upper)
are not of opposite sign.
Function vuniroot2()
returns a numeric vector x
as the solution of y = f(x)
with given vector y
.
library(rstpm2)
# ?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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.