mroot: Multi-dimensional Root (Zero) Finding

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/mroot.R

Description

For a given multi-dimensional function with both a vector of lower bounds and upper bounds, mroot finds a vector such that each component of the function is zero.

Usage

1
2
mroot(f, lower, upper, ..., f.lower = f(lower, ...), f.upper = f(upper, ...),
      tol = .Machine$double.eps^0.25, maxiter = 5000) 

Arguments

f

the function for which the root is sought

lower

a vector of lower end points

upper

a vector of upper end points

...

additional arguments to be passed to f

f.lower, f.upper

the same as f(lower) and f(upper)

tol

the convergence tolerance

maxiter

the maximum number of iterations

Details

The function f is from R^{n} to R^{n} with f(x_1,…,x_n) = (f_1(x_1),…,f_n(x_n)).

A root x = (x_1,…,x_n) of f satisfies f_k(x_k) = 0 for each component k.

lower = (l_1,…,l_n) and upper = (u_1,…,u_n) are both n-dimensional vectors such that, for each k, f_k changes sign over the interval [l_k, u_k].

Value

a vector giving the estimated root of the function

Author(s)

Nicholas Henderson

See Also

uniroot

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
ff <- function(x,a) {
    ans <- qnorm(x) - a
    return(ans)
}
n <- 10000
a <- rnorm(n)
low <- rep(0,n)
up <- rep(1,n)

## Find the roots of ff, first using mroot and
## then by using uniroot inside a loop.

system.time(mr <- mroot(ff, lower = low, upper = up, a = a))

ur <- rep(0,n)
system.time({
for(i in 1:n) {
   ur[i] <- uniroot(ff, lower = 0, upper = 1, a = a[i])$root    
}
})

rvalues documentation built on March 11, 2021, 9:05 a.m.

Related to mroot in rvalues...