Searches the interval for a root (i.e., zero) of the function func_ with
respect to its first argument. Other arguments may be vectorial, so
multiroot
will return a vector with roots.
Usage
multiroot(
func_,
interval,
...,
tolerance = .Machine$double.eps,
maxiter = 100,
check = function(...) any(..., na.rm = TRUE)
)
Arguments
- func_
objective function for root finding.
- interval
a vector containing the end-points of the interval to be searched for all the roots.
- ...
additional named or unnamed arguments to be passed to func_, may be vectorial, and this is the difference between multiroot and uniroot.
- tolerance
the desired accuracy (convergence tolerance).
- maxiter
the maximum number of iterations.
- check
function for checking convergence in
any
orall
of the roots. Since it is bisection method, they are the same.
See also
uniroot
for R built-in one dimensional root finding.
Examples
f <- function(x, y) x - y
multiroot(f, c(-3, 10), 1:3)
#> root: 1 2 3
#> iter: 55
#> err: 0 0 0
g <- function(sigma, premium, type, spot, strike, time, rate, yield) {
bsmprice(type, spot, strike, time, rate, yield, sigma) - premium
}
multiroot(g, c(1e-8, 10), 5, "call", 30, 31, c(1, 1.1, 1.2, 1.3), 0.15, 0)
#> root: 0.2716932 0.2347013 0.1981046 0.1590767
#> iter: 100
#> err: -3.552714e-15 -3.552714e-15 -3.552714e-15 0