I am glad, Greg, you did this. Peter is one of the backbones behind R, and has made enormous contributions to it. He deserves to be treated with respect.
More to the point, Peter's comments are perfectly reasonable. People are motivated by different factors to go to extra lengths to help someone else for no tangible benefit. In this particular case, it is just that I had never actually written a bisection code in R, and thought that this would be as good an excuse as any to do so. In fact, I also wrote a secant method root-finder just a month ago for exactly the same reason! Best, Ravi. From: Gregory Gentlemen [mailto:gregory_gentle...@yahoo.ca] Sent: Monday, September 20, 2010 12:52 PM To: peter dalgaard Cc: Ravi Varadhan; r-help@r-project.org Subject: Re: [R] Is there a bisection method in R? Fair enough. I didn't intend to offend anyone. Please accept my apologies. Greg --- On Mon, 9/20/10, peter dalgaard <pda...@gmail.com> wrote: From: peter dalgaard <pda...@gmail.com> Subject: Re: [R] Is there a bisection method in R? To: "Gregory Gentlemen" <gregory_gentle...@yahoo.ca> Cc: "Ravi Varadhan" <rvarad...@jhmi.edu>, r-help@r-project.org Received: Monday, September 20, 2010, 12:46 PM On Sep 20, 2010, at 18:15 , Gregory Gentlemen wrote: > Now that is a more useful reply than "Why do you assume there is one?". Thanks a lot Ravi! > Well, maybe, but you can NOT expect that someone will go out of THEIR way to solve YOUR problem every time. Sometimes they will and sometimes they won't. Complaining about having it pointed out that something might not actually exist just because you need it is downright offensive! > > > --- On Fri, 9/17/10, Ravi Varadhan <rvarad...@jhmi.edu> wrote: > > From: Ravi Varadhan <rvarad...@jhmi.edu> > Subject: RE: [R] Is there a bisection method in R? > To: "'Peter Dalgaard'" <pda...@gmail.com>, "'Gregory Gentlemen'" <gregory_gentle...@yahoo.ca> > Cc: r-help@r-project.org > Received: Friday, September 17, 2010, 5:44 PM > > Here is something simple (does not have any checks for bad input), yet > should be adequate: > > bisect <- function(fn, lower, upper, tol=1.e-07, ...) { > f.lo <- fn(lower, ...) > f.hi <- fn(upper, ...) > feval <- 2 > > if (f.lo * f.hi > 0) stop("Root is not bracketed in the specified interval > \n") > chg <- upper - lower > > while (abs(chg) > tol) { > x.new <- (lower + upper) / 2 > f.new <- fn(x.new, ...) > if (abs(f.new) <= tol) break > if (f.lo * f.new < 0) upper <- x.new > if (f.hi * f.new < 0) lower <- x.new > chg <- upper - lower > feval <- feval + 1 > } > list(x = x.new, value = f.new, fevals=feval) > } > > # An example > fn1 <- function(x, a) { > exp(-x) - a*x > } > > bisect(fn1, 0, 2, a=1) > > bisect(fn1, 0, 2, a=2) > > > Ravi. > > -----Original Message----- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf Of Peter Dalgaard > Sent: Friday, September 17, 2010 4:16 PM > To: Gregory Gentlemen > Cc: r-help@r-project.org > Subject: Re: [R] Is there a bisection method in R? > > On 09/17/2010 09:28 PM, Gregory Gentlemen wrote: > > If uniroot is not a bisection method, then what function in R does use > bisection? > > > > Why do you assume that there is one? uniroot contains a better algorithm > for finding bracketed roots. > > It shouldn't be too hard to roll your own if you need one for > pedagogical purposes. > > -- > Peter Dalgaard > Center for Statistics, Copenhagen Business School > Phone: (+45)38153501 > Email: pd....@cbs.dk Priv: pda...@gmail.com > > ______________________________________________ > 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. > > -- Peter Dalgaard Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd....@cbs.dk Priv: pda...@gmail.com [[alternative HTML version deleted]] ______________________________________________ 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.