Accuracy of Integral with epsilon
10-10-2021, 02:07 PM
Post: #21
 robve Senior Member Posts: 458 Joined: Sep 2020
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"
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 to remain rational"
 « Next Oldest | Next Newest »

 Messages In This Thread Accuracy of Integral with epsilon - lrdheat - 10-08-2021, 09:57 PM RE: Accuracy of Integral with epsilon - toml_12953 - 10-08-2021, 10:17 PM RE: Accuracy of Integral with epsilon - Thomas Okken - 10-08-2021, 10:18 PM RE: Accuracy of Integral with epsilon - toml_12953 - 10-08-2021, 10:28 PM RE: Accuracy of Integral with epsilon - lrdheat - 10-08-2021, 11:28 PM RE: Accuracy of Integral with epsilon - toml_12953 - 10-09-2021, 12:47 AM RE: Accuracy of Integral with epsilon - robve - 10-09-2021, 01:41 AM RE: Accuracy of Integral with epsilon - Valentin Albillo - 10-09-2021, 02:22 AM RE: Accuracy of Integral with epsilon - Paul Dale - 10-09-2021, 02:27 AM RE: Accuracy of Integral with epsilon - Thomas Okken - 10-09-2021, 08:47 AM RE: Accuracy of Integral with epsilon - John Keith - 10-09-2021, 05:40 PM RE: Accuracy of Integral with epsilon - robve - 10-09-2021, 08:37 PM RE: Accuracy of Integral with epsilon - Claudio L. - 10-12-2021, 04:47 PM RE: Accuracy of Integral with epsilon - robve - 10-14-2021, 02:43 AM RE: Accuracy of Integral with epsilon - robve - 10-09-2021, 09:50 PM RE: Accuracy of Integral with epsilon - Albert Chan - 10-10-2021, 11:51 AM RE: Accuracy of Integral with epsilon - robve - 10-10-2021 02:07 PM RE: Accuracy of Integral with epsilon - robve - 10-09-2021, 02:01 PM RE: Accuracy of Integral with epsilon - lrdheat - 10-09-2021, 03:13 AM RE: Accuracy of Integral with epsilon - toml_12953 - 10-09-2021, 05:44 AM RE: Accuracy of Integral with epsilon - toml_12953 - 10-09-2021, 11:26 AM RE: Accuracy of Integral with epsilon - lrdheat - 10-09-2021, 05:16 AM RE: Accuracy of Integral with epsilon - lrdheat - 10-09-2021, 03:25 PM

User(s) browsing this thread: