Comments (6)
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.
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.
Yikes, I see, I messed that up, I thought the BigFloat version was okay.
from quadgk.jl.
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.
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.
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)
- confusion in kronrod() documentation? HOT 1
- Documentation suggestion
- TagBot trigger issue HOT 13
- AD compatibility HOT 1
- How to cite QuadGK HOT 1
- Compatibility with CUDA.jl HOT 2
- Possible regression using quadgk function and Unitful limits HOT 9
- unitful infinite bounds
- order=1 seems børked HOT 1
- contour integration HOT 1
- documentation build is failing HOT 4
- Autodiff of `quadgk` HOT 2
- Can not catch a JuliaError caused by function blowing up to infinity HOT 2
- misleading error estimate for non-convergent integral (maxevals=10^7 reached) HOT 5
- QuadGK evaluates function at upper bound HOT 4
- No cachedrule for DynamicQuantities types HOT 4
- Regression with [email protected] HOT 6
- spurious underflow in kronrod for large n HOT 1
- infinite limits with units and segbuf broken
- quadgk with identical lower and upper bound is broken HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from quadgk.jl.