Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quadrature results inconsistent with scipy.integrate.quad and mpmath.quad #482

Open
theDDA opened this issue Jul 11, 2024 · 3 comments
Open

Comments

@theDDA
Copy link

theDDA commented Jul 11, 2024

I have a highly oscillatory function that I'd like to integrate on an interval. The function has been omitted as it's quite complicated, but it's a single variable vectorized function.

Running

import quadpy
import mpmath as mp
from scipy.integrate import quad

print("Scipy:")
print(quad(i,0,6,limit=5000,complex_func=True))
print("Mpmath:")
print(mp.fp.quad(i,np.linspace(0,6,1500), error=True))
print("Quadpy:")
print(quadpy.quad(i,0,6, limit=5000))

returns

Scipy:
((-257085873.20190012+274878176.58262545j), (3.788039545497331+4.050770505976548j))
Mpmath:
(array([-2.57085873e+08+2.74878177e+08j]), 0.016388469075099873)
Quadpy:
(np.complex128(162736641.65176928+500993494.40351963j), np.float64(0.6246959267121839))

Scipy and mpmath agree with each other quite well, but I have pretty much no idea how to make quadpy work. I'm not even sure if it's a bug, it may well be that both scipy and mpmath are wrong. All I know is that on every subinterval they agree, while quadpy doesn't seem to be consistent with itself between different schemes.

I've tried quadpy.c1.integrate_adaptive(i,(0,6),minimum_interval_length=6/100000) and combinations of various schemes and degrees. I know that Gauss-Legendre quadrature is used for this function, so I've spent most of my time with that but to no avail.

All of the above holds if I reduce the endpoint of the interval to 6/100 or 6/1000, where the function is much less oscillatory.

I realize this isn't reproducible without the original function, but I was hoping there are some options that I'm missing.

@nschloe
Copy link
Collaborator

nschloe commented Jul 12, 2024

What version of quadpy are you using?

@theDDA
Copy link
Author

theDDA commented Jul 12, 2024

It's the conda package, 0.16.10.

FWIW it fails even for intervals where the function appears to be well-behaved.

image

@nschloe
Copy link
Collaborator

nschloe commented Jul 12, 2024

The current version is 0.17.21, your issue might be fixed there. We'll have to see about getting conda on track again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants