Giter VIP home page Giter VIP logo

Comments (6)

stevengj avatar stevengj commented on July 25, 2024

It's not at all an "easy" integral, because the integrand has a slope discontinuity in the middle of the integration region. QuadGK, like essentially all integration algorithms, is best for smooth integrands. The discontinuity not only messes up the convergence rate, it also messes up the error estimate.

(It similarly screws up the BigFloat integral, so your error estimate is not accurate.)

from quadgk.jl.

stevengj avatar stevengj commented on July 25, 2024

An accurate way to do this integral is to break the integration interval up into the regions before and after the discontinuity:

julia> x1,e1 = QuadGK.quadgk(x -> exp(abs(x - 0.499)), 0, 1) # inaccurate
(1.297443190121581, 2.220446049250313e-16)

julia> x2,e2 = QuadGK.quadgk(x -> exp(abs(x - 0.499)), 0, 0.499, 1) # accurate
(1.2974441901216642, 1.1102230246251565e-16)

julia> x1-x2 # error
-1.0000000831844602e-6

The same procedure shows the error with 0.4999 is not 1e-17:

julia> x1,e1 = QuadGK.quadgk(x -> exp(abs(x - 0.4999)), 0, 1)
(1.297442547887469, 1.1102230246251565e-16)

julia> x2,e2 = QuadGK.quadgk(x -> exp(abs(x - 0.4999)), 0, 0.4999, 1)
(1.2974425578874689, 1.1102230246251565e-16)

julia> x1-x2
-9.99999993922529e-9

from quadgk.jl.

ikirill avatar ikirill commented on July 25, 2024

Yikes, I see, I messed that up, I thought the BigFloat version was okay.

from quadgk.jl.

ikirill avatar ikirill commented on July 25, 2024

Would you consider the incorrect error estimate a bug on its own? (I was reading https://www.research-collection.ethz.ch/bitstream/handle/20.500.11850/13300/eth-65-02.pdf and just wanted to see what QuadGK would do on some of the test functions.)

from quadgk.jl.

stevengj avatar stevengj commented on July 25, 2024

I wouldn't consider that a bug, I would consider that an inherent limitation/tradeoff of Gauss–Kronrod adaptive quadrature. It would be great to have additional quadrature schemes, of course.

from quadgk.jl.

stevengj avatar stevengj commented on July 25, 2024

Note that if you have a non-smooth integrand, you are better off with a lower-order quadrature — for this integrand, I get about the same accuracy, a better error estimate, and about half as many function evaluations if I pass order=3 to quadgk (the default is order=7).

from quadgk.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.