rvalues (version 0.6.3)

mroot: Multi-dimensional Root (Zero) Finding

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

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

Value

a vector giving the estimated root of the function

Details

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

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

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

See Also

uniroot

Examples

Run this code
# NOT RUN {
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    
}
})

# }

Run the code above in your browser using DataCamp Workspace