quad

Using scipy.quad with iε trick: Bad results

眉间皱痕 提交于 2019-12-06 07:35:48
In order to circumvent the cauchy principle value, I tried to integrate an integral using a small shift iε into the complex plane to evade the pole. However, as can be inferred from the figure below, the result is pretty bad. The code for this result is shown below. Do you have ideas how to improve this method? Why is it not working? I already tried changing ε or the limit in the integral. Edit: I included the method "cauchy" with the principle value, which seems not to work at all. import matplotlib.pyplot as plt from scipy.integrate import quad import numpy as np def cquad(func, a, b, *

Using scipy.integrate.quad to perform 3D integral

两盒软妹~` 提交于 2019-12-04 05:03:35
问题 Motivation for the question I'm trying to integrate a function f(x,y,z) over all space. I have tried using scipy.integrate.tplquad & scipy.integrate.nquad for the integration, but both methods return the integral as 0 (when the integral should be finite). This is because, as the volume of integration increases, the region where the integrand is non-zero gets sampled less and less. The integral 'misses' this region of space. However, scipy.integrate.quad does seem to be able to cope with

How to use Gcc 4.6.0 libquadmath and __float128 on x86 and x86_64

☆樱花仙子☆ 提交于 2019-12-02 19:33:17
I have medium size C99 program which uses long double type (80bit) for floating-point computation. I want to improve precision with new GCC 4.6 extension __float128 . As I get, it is a software-emulated 128-bit precision math. How should I convert my program from classic long double of 80-bit to quad floats of 128 bit with software emulation of full precision? What need I change? Compiler flags, sources? My program have reading of full precision values with strtod , doing a lot of different operations on them (like +-*/ sin, cos, exp and other from <math.h> ) and printf -ing of them. PS:

Using scipy.integrate.quad to perform 3D integral

点点圈 提交于 2019-12-02 06:25:32
Motivation for the question I'm trying to integrate a function f(x,y,z) over all space. I have tried using scipy.integrate.tplquad & scipy.integrate.nquad for the integration, but both methods return the integral as 0 (when the integral should be finite). This is because, as the volume of integration increases, the region where the integrand is non-zero gets sampled less and less. The integral 'misses' this region of space. However, scipy.integrate.quad does seem to be able to cope with integrals from [-infinity, infinity] by performing a change of variables... Question Is it possible to use

scipy quad uses only 1 subdivision and gives wrong result

不羁岁月 提交于 2019-12-02 02:23:29
I want to use quad to get the mean of a Gaussian distribution. My first try and 2nd try gets different result. And the 2nd try of quad uses only 1 subdivision. mu =1 sigma =2 import scipy as sp import scipy.integrate as si import scipy.stats as ss f = lambda x: x * ss.norm(loc=mu, scale=sigma).pdf(x) a = si.quad(f, -999., 1001., full_output=True) print a[0] #print sum(a[2]["rlist"][:a[2]["last"]]) print a[2]["last"] b = si.quad(f, -1001., 1001., full_output=True) print b[0] #print sum(b[2]["rlist"][:b[2]["last"]]) print b[2]["last"] print sorted(a[2]["alist"][:a[2]["last"]]) print sorted(b[2][

How to know integration technique used by quadpack [closed]

你说的曾经没有我的故事 提交于 2019-12-02 00:26:24
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . 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 for printing the technique?

How to know integration technique used by quadpack [closed]

◇◆丶佛笑我妖孽 提交于 2019-12-01 22:14:36
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 for printing the technique? Does the software apply some decision tree? Thanks in advance for your time. Regards. As scipy is open source, you can actually read the code for integrate.quad , which says: For finite integration limits, the integration is performed using a Clenshaw-Curtis method which uses Chebyshev moments. ... If one of the

sizeof long double and precision not matching?

大城市里の小女人 提交于 2019-11-29 10:23:29
Consider the following C code: #include <stdio.h> int main(int argc, char* argv[]) { const long double ld = 0.12345678901234567890123456789012345L; printf("%lu %.36Lf\n", sizeof(ld), ld); return 0; } Compiled with gcc 4.8.1 under Ubuntu x64 13.04 , it prints: 16 0.123456789012345678901321800735590983 Which tells me that a long double weights 16 bytes but the decimals seems to be ok only to the 20th place. How is it possible? 16 bytes corresponds to a quad, and a quad would give me between 33 and 36 decimals. The long double format in your C implementation uses an Intel format with a one-bit

scipy.integrate.quad gives wrong result on large ranges

梦想与她 提交于 2019-11-28 13:54:39
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 integral_fun(x): nor1 = 0.5 * ((1 / (np.sqrt(2 * np.pi) * std1)) * (np.e ** ((-(x-mu1) ** 2) / (2 * std1 **2)))) nor2 = 0.5 * ((1 / (np.sqrt(2 * np.pi) * std2)) * (np.e ** ((-(x-mu2) ** 2) / (2 * std2 **2)))) return nor1 + nor2 integrate.quad(integral_fun, -5, 5) Out[54]: (0.9999994266968564, 8.668320228277793e-10) integrate.quad(integral_fun, -10,

NumPy vectorization with integration

坚强是说给别人听的谎言 提交于 2019-11-28 01:19:52
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 way to apply a pure Python function to every element of a NumPy array without calling it that many times ". Since I'm using NumPy functions rather than "pure Python" ones, I suppose it's possible to vectorize, but I don't know how. import numpy as np from scipy.integrate import quad ws = 2 * np.random.random(10) - 1 n = len(ws) integrals = np.empty(n)