[R] vectorized uni-root?

2012-11-10 Thread U30A J C Nash
58:55 + From: Ravi Varadhan To: "'ivo.we...@gmail.com'" Cc: "r-help@r-project.org" Subject: Re: [R] vectorized uni-root? Message-ID: <2f9ea67ef9ae1c48a147cb41be2e15c32e8...@dom-eb-mail1.win.ad.jhu.edu> Content-Type: text/plain Hi Ivo, The only proble

Re: [R] vectorized uni-root?

2012-11-09 Thread Ravi Varadhan
Hi Ivo, The only problem is that uniroot() actually uses Brent's algorithm, and is based on the C code from netlib (there is also Fortran code available - zeroin.f). Brent's algorithm is more sophisticated than a simple bisection approach that you have vectorized. It combines bisection and se

Re: [R] vectorized uni-root?

2012-11-08 Thread ivo welch
hi michael---this can be done better than with outer(). A vectorized bisection search that works with an arbitrary number of arguments is bisection <- function(f, lower, upper, ..., numiter =100, tolerance = .Machine$double.eps^0.25 ) { stopifnot(length(lower) == length(upper)) flower <- f(l

Re: [R] vectorized uni-root?

2012-11-08 Thread R. Michael Weylandt
On Thu, Nov 8, 2012 at 3:05 PM, ivo welch wrote: > dear R experts--- I have (many) unidimensional root problems. think > > loc.of.root <- uniroot( f= function(x,a) log( exp(a) + a) + a, > c(.,9e10), a=rnorm(1) ) $root > > (for some coefficients a, there won't be a solution; for others, it > may