Python+Scipy+Integration: dealing with precision errors in functions with spikes <p>I am trying to use scipy.integrate.quad to integrate a function over a very large range (0..10,000). The function is zero over most of its range but has a spike in a very small range (e.g. 1,602..1,618).</p> <p>When integrating, I would expect the output to be positive, but I guess that somehow quad's guessing algorithm is getting confused and outputting zero. What I would like to know is, is there a way to overcome this (e.g. by using a different algorithm, some other parameter, etc.)? I don't usually know where the spike is going to be, so I can't just split the integration range and sum the parts (unless somebody has a good idea on how to do that).</p> <p>Thanks!</p> <p>Sample output:</p> <pre><code>&gt;&gt;&gt;scipy.integrate.quad(weighted_ftag_2, 0, 10000) (0.0, 0.0) &gt;&gt;&gt;scipy.integrate.quad(weighted_ftag_2, 0, 1602) (0.0, 0.0) &gt;&gt;&gt;scipy.integrate.quad(weighted_ftag_2, 1602, 1618) (3.2710994652983256, 3.6297354011338712e-014) &gt;&gt;&gt;scipy.integrate.quad(weighted_ftag_2, 1618, 10000) (0.0, 0.0) </code></pre>