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

numeric vector of y values

f

monotone function f(x) whose roots are to be solved

interval

length-2 numeric vector

tol

double scalar, desired accuracy, i.e., convergence tolerance

maxiter

integer scalar, maximum number of iterations

Details

Function vuniroot2, different from vuniroot, does

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
lwr = rep(1, times = 9L); upr = rep(3, times = 9L)

# ?rstpm2::vuniroot does not accept NA \eqn{y}
tryCatch(vuniroot(function(x) x^2 - c(NA, 1:8), lower = lwr, upper = upr), error = identity)

# ?rstpm2::vuniroot not good when the analytic root is at `lower` or `upper`
f <- function(x) x^2 - 1:9
tryCatch(vuniroot(f, lower = lwr, upper = upr, extendInt = 'no'), warning = identity)
tryCatch(vuniroot(f, lower = lwr, upper = upr, extendInt = 'yes'), warning = identity)
tryCatch(vuniroot(f, lower = lwr, upper = upr, extendInt = 'downX'), error = identity)
tryCatch(vuniroot(f, lower = lwr, upper = upr, 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.1 Index]