mroot | R Documentation |
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.
mroot(f, lower, upper, ..., f.lower = f(lower, ...), f.upper = f(upper, ...), tol = .Machine$double.eps^0.25, maxiter = 5000)
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.lower, f.upper |
the same as |
tol |
the convergence tolerance |
maxiter |
the maximum number of iterations |
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].
a vector giving the estimated root of the function
Nicholas Henderson
uniroot
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 } })
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.