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

# ?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]