Relative tolerances for near-zero integrals

I have a question somewhat unrelated to the previous discussion.

What is a good way to specify relative tolerance in the case where the exact value of the integral is close to zero?

I’ve looked at QuadGK internals and there the relative error is calculated by dividing sum of errors over the sum of integrals over segments. In the case of almost zero-valued integral, I could think about calculating the sum of absolute values of integrals over segments and then divide total error by this new sum.

What do you think of such an approach?

In this case you want an absolute tolerance (via the atol keyword), perhaps in addition to a relative tolerance.

(In general, you should open a new topic rather than posting unrelated questions to old topics.)

2 Likes

Thank you for the splitting and sorry for the overusing the old topic.

It is good to have as few parameters as possible. So I could rephrase my question as: Is there a good heuristic to estimate desired absolute tolerance if relative tolerance is specified for near-zero integral?

The approach that I proposed, in some sense, estimates L1 norm of the function and uses it to estimate desired absolute tolerance.

I would estimate it as a relative tolerance multiplied by the integral of the absolute value of the integrand (maybe estimated to low accuracy, e.g. by a fixed-order rule), or a relative tolerance multiplied by the length of the integration interval multiplied by a typical magnitude of the integrand. (That is, you need a scale according to which you determine what is a “small” error.)

1 Like

Agreed.
But, if it is a natural way, why it is not used in QuadGK, for example, by default?

After line 11 here:

One could insert

I′ = sum(s -> nrm(s.I), segs)

And then use this I′ instead of I in line 24, where the relative tolerance check is performed.

I do not insist on doing it. Rather I am curious as to why it may be a bad idea? Or may be not…

Because integrating |f(x)| or similar is expensive just to compute an absolute error tolerance that is rarely needed.

1 Like

This is not the same thing as integrating |f(x)|, because it only sums the absolute values of the subsegment integrals, and I’m not sure how reliable it would be as a way to estimate an atol.

Actually it is not that bad. We can say exactly that I′ > |I|. At the same time I′ gives us a lower bound on the integral of |f(x)|. And the more segments we have, the more accurate this bound is: the difference with the integral of |f(x)| comes from the segments where the function changes its sign. The more segments we have, the smaller the segments are => the difference becomes less significant.

In the case where the integral has not a near-zero value, there should be no significant difference between the usage of I′ and |I| for the relative tolerance check. It is because the integrals of f(x) and of |f(x)| should be of the same order in this case.

In the situation where we encounter the integral with a near-zero value, |I′| should quickly become a good approximation of the integral of |f(x)| with the growth of the number of segments.

1 Like

That’s true. It might be reasonable to use as a default