Accuracy of Integral with epsilon

10102021, 02:07 PM
Post: #21




RE: Accuracy of Integral with epsilon
(10102021 11:51 AM)Albert Chan Wrote:(10092021 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? 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 TanhSinh 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" 

10122021, 04:47 PM
Post: #22




RE: Accuracy of Integral with epsilon
(10092021 08:37 PM)robve Wrote:(10092021 02:27 AM)Paul Dale Wrote: It's neither complex nor state of the art. Going variable precision shows typically COSH()SINH() creates noise in the last 8 or 9 digits. So if your precision is 16 digits (like Excel), you end up with the 10^8 that you correctly recorded. So I guess the trick is as long as you don't ask the integration algorithm for an error smaller than the system precision less 9 digits, you'll be fine and get a nice result, with an error in the order of (precision9), regardless of the tolerance you requested. For example, I set newRPL to 120 digits and request 1E60 tolerance, and adaptive Simpson very quickly returns 40 with 112 correct digits and noise in the last 8. With the standard 32 digits I get an error of 10^23. If I request a tolerance below 10^23, the algorithm will literally "hang" in an infinite loop trying to refine the step unsuccessfully. 

10142021, 02:43 AM
Post: #23




RE: Accuracy of Integral with epsilon
(10122021 04:47 PM)Claudio L. Wrote: So I guess the trick is as long as you don't ask the integration algorithm for an error smaller than the system precision less 9 digits, you'll be fine and get a nice result, with an error in the order of (precision9), regardless of the tolerance you requested. Catastrophic cancellation errors exponentially increase towards negative infinity for this integrand. I may be going off on a tangent in this thread, but what other sources are there for noise, besides cancellation and cosh/sinh/exp roundoff/differences? Can the integration method be noisy? I'd expect that to be insignificant. It may depend on the accuracy of the weight calculations. Simple weights pose no problem, e.g. Simpson, Romberg are exact for (low order) polynomials anyway. Weights derived from tablebased methods, such as GaussKronrod may collect small errors in the weight calculations. I was curious to test this with a simple constant function \( \int_{10}^{10} 2\,dx \) to integrate with eps=10^6 tolerance (or about, what works to get comparable results w.r.t. number of evaluation points):  GaussKronrod G10K21 with IEEE 754 doubles = 40.000000000000007.  WP34S TanhSinh C version with IEEE 754 double: 39.999999999987885 (23 points)  qthsh TanhSinh with IEEE 754 double: 40.000000000000057 (29 points)  Boost Math TanhSinh with IEEE 754 double: 40.000000000001464 (25 points) TanhSinh methods may suffer "weight issues" due to their point distributions. There are also numerical differences in the implementations. WP34S and qthsh use the more efficient MichalskiMosig quadrature method. Boost Math uses the standard TakahashiMori TanhSinh quadrature method. And there are other internal differences. WP34S computes the weights as follows (see forum thread): Code: double ch = cosh(t); Whereas qthsh computes the weights as follows: Code: double u = exp(1/tt); // = exp(2*sinh(j*h)) = 1/exp(sinh(j*h))^2 The noise here is still rather insignificant compared to cancellation and diminishes with smaller given tolerances toward 10^15 with more points evaluated by TanhSinh.  Rob "I count on old friends to remain rational" 

« Next Oldest  Next Newest »

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