On Thu, Nov 8, 2012 at 3:05 PM, ivo welch <ivo.we...@gmail.com> 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 exceed the domain. implied volatilities in various Black-Scholes > formulas and variant formulas are like this, too.) > > except I don't need 1 root, but a few million. to get so many roots, > I can use a for loop, or an lapply or mclapply. alternatively, > because f is a vectorized function in both x and a, evaluations for a > few million values will be cheap. so, one could probably write a > clever bisection search here. > > does a "vectorized" uniroot exist already?
Not to my knowledge, but I think you're on track for a nice quick-and-dirty if your function is cheap like the above. Make a 2D grid of results with outer() and interpolate to find roots as needed. For smooth objective functions, it will likely be cheaper to increase precision than to loop over optimization routines written in R. Cheers, Michael ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.