Post Reply 
Accuracy of Integral with epsilon
10-10-2021, 02:07 PM
Post: #21
RE: Accuracy of Integral with epsilon
(10-10-2021 11:51 AM)Albert Chan Wrote:  
(10-09-2021 09:50 PM)robve Wrote:  You do realize that it is a fallacy to assume exp(x) and cosh(x)+sinh(x) equate numerically, in addition to algebraically?

It is interesting that my MAPM implementation of raw_exp() actually use above "identity" Big Grin
Of course, |x| is limited to tiny value, below 1E-4, so catastrophic cancellation is not an issue.

sinh(x) converge with half as many terms, compared with exp(x)

exp(x) = x + x^2/2! + x^3/3! + ...
sinh(x) = x + x^3/3! + x^5/5! + ...

You're right. To summarize:

1. cosh(x)+sinh(x) suffers from catastrophic cancellation for negative x, with ~|x| digits lost, e.g. cosh(-10)+sinh(-10)-exp(-10) = -0.000000099 and it is worse when taking exp(-10)/(cosh(-10)+sinh(-10)) = 1.0022 (depending on the calculator's precision)
2. sinh(x) implementations may use sinh(x) = (z+z/(z+1))/2 with z=expm1(x), which improves the accuracy of sinh(x) for x<0 whereas cosh(x) is unaffected, as another example when algebraic identities may not hold numerically.
3. floating point noise not contributed by the above.

This integrand is a really bad one to compare numerical integration on calculators. The results are not all that meaningful. Picking eps=10^-4 does not necessarily help to prevent issues, see point 1. I might wager that a less sophisticated calculator may produce a more "accurate" result close to 40.

As a funny consequence of playing around with this for a bit, I found a bug in Boost Tanh-Sinh that produces 20 as the answer to the integral \( \int_{-10}^{10} 2\,dx \). I could not believe it at first, but it is a specific problem.

- Rob

"I count on old friends" -- HP 71B,Prime|Ti VOY200,Nspire CXII CAS|Casio fx-CG50...|Sharp PC-G850,E500,2500,1500,14xx,13xx,12xx...
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Accuracy of Integral with epsilon - robve - 10-10-2021 02:07 PM



User(s) browsing this thread: 1 Guest(s)