Date: Mon, 11 Dec 2006 23:35:03
From: S Bond
Subject: Re: Review Question: Ch.1 #19
Jonathan William Ray wrote: > Which is most accurate: 1/x - 1/(x+1) or 1/(x(x+1)) ? When x =~ 0 or x > =~ -1 ? How about for |x| larger than 1 / epsmach ? > > When x is between 0 and emach, 1/x - 1/(x+1) = 1/x - 1/1 = (1/x) in > floating point arithmetic. > > And 1/(x(x+1)) = 1/(x*1) = 1/x in floating point arithmetic. > > So they're equally accurate unless I made a mistake. But the question > is asking which one is more accurate, which presumes that there exists > one that is more accurate, so my answer is suspect. Seems reasonable, presuming that there is no overflow, in which case they will both overflow. > When x = -1 - emach, the first formula gives 1/emach, and the second > formula gives something slightly smaller which is closer to the actual > solution, but the relative difference is tiny. Sure. The point here is that for x near 0 and -1, the exact answer is diverging, so there isn't any rearrangement which will fix that. > For x larger than 1/emach, x+1 = x, so 1/(x(x+1)) = 1/(x^2) > but 1/x - 1/(x+1) = 1/x - 1/x = 0, so 1/(x(x+1)) is more accurate, right? Yes. Here we do find an improvement from rearrangement. Questions of this form are almost always about cancellation.
|
HTML 4.01 Updated: Mon, 11 Dec 2006 23:35:03 | Powered by Perl Net::NNTP |