简体   繁体   中英

Increase number of nodes in quad

This might be a simple question, but I am trying to increase number of nodes in quad integration. I could not find relevant documentation about this.

I have a one-dimensional function (Dirac delta-like) which is mostly zero, but non-zero at a very narrow interval. So adaptive quad cannot catch that interval and returns zero. I am trying to catch that peak by sampling at more points. How do you do this? SciPy documentation does not tell much.

The position of this narrow peak changes. I don't know the exact position of the peak.

quadpy (a project of mine) does adaptive quadrature in 1D with Gauss-Kronrod. You can specify the degree of the Kronrod rules, cranking it up with increase the number of points in the domain.

Install with

pip install quadpy

and try

from numpy import sin
import quadpy

val, error_estimate = quadpy.line_segment.adaptive_integrate(
        lambda x: sin(5*x),
        [0.0, 1.0],
        1.0e-10,
        kronrod_degree=10
        )

print(val)

Crank up kronrod_degree to get more points in the domain.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM