Quad is a scipy package which is used for 1D integration in Python
Questions tagged [quad]
135 questions
7
votes
1 answer
Integrating a function with singularities using scipy's quad routine
I am using the quad function from scipy.integrate v0.19.1 to integrate functions with a square-root like singularity at each end of the integration interval such as for example
In [1]: quad(lambda x: 1/sqrt(1-x**2), -1, 1)
(I use the sqrt function…

TMueller83
- 412
- 3
- 11
7
votes
3 answers
NumPy vectorization with integration
I have a vector and wish to make another vector of the same length whose k-th component is
The question is: how can we vectorize this for speed? NumPy vectorize() is actually a for loop, so it doesn't count.
Veedrac pointed out that "There is no…

visitor
- 672
- 6
- 17
6
votes
2 answers
How to use dblquad for double integration?
The following example is provided on Scipy's reference page for integration.
from scipy import integrate
N = 5
def f(t, x):
return np.exp(-x*t) / t**N
integrate.nquad(f, [[1, np.inf],[0, np.inf]])
The following is the error I get from my…

Shashank Sawant
- 1,111
- 5
- 22
- 40
5
votes
1 answer
scipy.integrate.quad gives wrong result on large ranges
I am trying to integrate over the sum of two 'half' normal distributions. scipy.integrate.quad works fine when I try to integrate over a small range but returns 0 when I do it for large ranges. Here's the code:
mu1 = 0
mu2 = 0
std1 = 1
std2 = 1
def…

Ankur Ankan
- 2,953
- 2
- 23
- 38
4
votes
1 answer
Is there a performance gain of dblquad over twice quad?
From scipy reference manual, dblquad is mathematically equivalent to repeated quad twice. Initially, I thought dblquad must have performance advantage over twice quad (besides the convenience of the method). To my surprise, it seems dblquad…

sunheng
- 43
- 4
3
votes
1 answer
Draw quad (interleaved) in three.js
I'm trying to draw a quad in three.js, but three.js keeps complaining that 'tex' is not a 'WebGLTexture' and refuse to run, what's going on here? thank you.
// z= depth, tex is texture
function drawQuad(z, tex)
{
var verts = [
-1.0, …

21k
- 391
- 5
- 16
3
votes
1 answer
How do I numerically integrate a function thats a product of a lorentzian and a cosinus in Python?
I am new to stackoverflow and also quite new to Python. So, I hope to ask my question in an appropriate manner.
I am running a Python code similar to this minimal example with an example function that is a product of a lorentzian with a cosinus that…

Frederik
- 35
- 4
3
votes
1 answer
Is there a way to use scipy.optimize.fsolve with jit_integrand_function and scipy.integrate.quad?
Based on the explanation provided here 1, I am trying to use the same idea to speed up the following integral:
import scipy.integrate as si
from scipy.optimize import root, fsolve
import numba
from numba import cfunc
from numba.types import intc,…

duartedias
- 31
- 1
3
votes
1 answer
How do I use parameter epsabs in scipy.integrate.quad in Python?
I am trying to compute the integrals more precise by specifying the parameter epsabs for scipy.integrate.quad, say we are integrating the function sin(x) / x^2 from 1e-16 to 1.0
from scipy.integrate import quad
import numpy
integrand = lambda x:…

zyy
- 1,271
- 15
- 25
3
votes
1 answer
python quad integration seems inaccurate
I'm a bit of a newbie to python and am trying to numerically integrate a function. Everything seems to work, but the results I'm getting vary significantly from what I get in Mathematica (which I know to be correct). Can someone help me figure out…

DJElectric
- 349
- 1
- 4
- 18
3
votes
2 answers
Python: Plotting an Integral
I know there are some similar questions around here but none of them seems to really get to my problem.
My code looks like this:
import numpy
import matplotlib.pyplot as plt
from scipy import integrate as integrate
def H(z , omega_m , H_0 =…

user7248647
- 67
- 1
- 2
- 9
3
votes
1 answer
Python vs. MATLAB computing an integral to infinity with different results, alternative (i.e. expand Gauss-Legendre quadrature to -x-> Infinity)?
I am getting inconsistent results between MATLAB's quadgk and Python's quad routine for an integral from (-x or 0) -> infinity. I believe the MATLAB version is correct (based on a sense check of switching the flag parameter from 1 to -1) whereas…

Matt
- 2,602
- 13
- 36
3
votes
1 answer
Sudden drop when integrating a gaussian with quad
I am trying to integrate u -> exp(-u²/2) from -infinity to x. When I plot the function, there is a sudden drop around 21 and it goes down to 0 around 36 whereas it should be roughly constant to 2.5. How do you explain it?
import numpy as np
from…

hokkaidi
- 858
- 6
- 19
3
votes
1 answer
How to know integration technique used by quadpack
I have been learning about QUADPACK and I used scipy.integrate.quad to calculate an integral from 0 to infinite. It gave a very good result, but now I want to know which integration method (QAGI, QAWF,etc.) the software has applied. Is there any way…

davidsaezsan
- 133
- 4
3
votes
2 answers
How can I isolate the result of scipy.integrate.quad function, rather than having the result and the error of the calculation?
I'm trying to create an array of integral values that will be used further in calculations. The problem is that integrate.quad returns (answer, error). I can't use that in other calculations because it isn't a float; it is a set of two numbers.

user2565770
- 385
- 1
- 4
- 8