Post Reply 
(PC-12xx~14xx) qthsh Tanh-Sinh quadrature
04-02-2021, 07:12 PM
Post: #14
RE: (PC-12xx~14xx) qthsh Tanh-Sinh quadrature
(03-29-2021 07:42 PM)robve Wrote:  sqrt(x / (1 - x * x))

This an example of an integral that has all its area close to a non-zero endpoint, the problem here is that the function being integrated returns "garbage" values for x very close to 1. We can easily fix this issue by passing a 2 argument functor to the integrator: the second argument gives the distance to the nearest endpoint, and we can use that information to return accurate values, and thus fix the integral calculation.

Can you explain what that meant ? Perhaps an example ?

To avoid garbage of x close to 1, I would have rewrite the integrand, with infinity at x=0.
(y=1-x², dy = -2x dx, would solved it exactly. But, no cheating ...)

∫(x/√(1-x²), x=0..1) = ∫((1-x)/√(x*(2-x)), x=0..1)

With infinity moved, at x=0, we can add many, many more points.

Since e^x grow faster than x^n, we have e^-x shrink faster then x^-n, for finite n.

∫(f(x), x=0 .. 1) = ∫f(e^-y)*(e^-y), y=0 .. inf)

Code:
def e_transform(f, exp=exp):    # interval [0,1] -> [0,inf]
    def ef(z):
        try: return f(z)*z
        except: return 0
    return lambda y: ef(exp(-y))

>>> f = lambda x: (1-x)/sqrt(x*(2-x))
>>> ef = e_transform(f)
>>> quadts(f, [0, 1])
0.999999999624821
>>> quadts(ef, [0, inf])
1.0

Similar results, with Gauss-Legendre quadrature:

>>> quadgl(f, [0, 1])
0.993619917982059
>>> quadgl(ef, [0, inf])
1.0
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: (PC-12xx~14xx) qthsh Tanh-Sinh quadrature - Albert Chan - 04-02-2021 07:12 PM



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