# Tag Info

### Tanh-sinh quadrature numerical integration method converging to wrong value

There are a bunch of pitfalls when it comes to tanh-sinh quadrature, one being that the integrand needs to be evaluated very closely to the interval boundaries, at distances less than machine ...
• 3,126

### Why does Matlab's integral outperform integrate.quad in Scipy?

The question has two very different subquestions. I will address the first one only. Matlab's version runs on average 24 times faster than my python equivalent! The second one is subjective. I ...
• 141

### Numerical evaluation of highly oscillatory integral

Use Plancherel's theorem to evaluate this integral. The basic idea is that for two functions $f,g$, $$I=\int_{-\infty}^{\infty} f(x) g^*(x)dx = \int_{-\infty}^{\infty} F(k) G^*(k) dk$$ where $F,G$...
• 693

### Integrating Lagrange polynomials with many nodes, round-off

You can evaluate this using the Björck-Pereyra algorithm for solving Vandermonde systems, because you are evaluating $b^\top V^{-1}$ with $b=(2,0,\frac23,0,\frac25,0,\ldots)$, and the algorithm is ...
• 11.4k
Accepted

### Numerical calculation of Integral of Si(x)/x

For large $x$, you can use the same approach as the one in the paper you cite. They define these auxiliary functions that link $\mathrm{Si},\mathrm{Ci}$ with $\sin,\cos$, and the point of why this ...
• 11.4k
Accepted

### How to estimate the error of trapezoidal rule using discrete data?

You may use the ideas of error extrapolation as one uses it to construct high-order Runge Kutta methods. Depending on the function that you interpolate, the interpolation error $I - I_h$, where $I$ ...
• 3,418
Accepted

### Numerical integration of a hypergeometric function

First of all, from the first paragraph of your attempts at a solution, I assume that the $z_j$ are non-negative? In that case, the integrand has no real problematic points (it's monotonous, decreasing)...
• 6,159
Accepted

### How do I integrate a function defined over an arbitrary area?

Instead of directly integrating over the area, it is often more convenient to use the divergence theorem to replace the area integral with an integral over the boundary edges. The divergence theorem ...
• 6,144

### Numerical evaluation of highly oscillatory integral

The key to the evaluation of oscillatory integrals is to truncate integral at the right point. For this example you need to choose upper limit of the form $$\pi\mathbb{N}+\frac{\pi}{2}$$ Before ...

### Numerical integration giving incorrect sign

This might be an accuracy problem in computing the second term, because of those large exponentials when $x \gg 1$. I would first work on that term: gather $e^x$ out from numerator and denominator and ...
• 11.6k

### Radial integration of expensive function with Bessel weights

For the Hankel transform, one can classify the methods into four major groups: Numerical quadrature-based. Fourier-based ones. Asymptotic expansion of Bessel into sines and cosines. Projection-slice ...
• 8,692

You could just go for the direct final answer of the integral: $$\int_{a}^{b}\vert {\sin(x)}\vert dx = 2\left(\left\lfloor\frac{b}{\pi}\right\rfloor - \left\lfloor\frac{a}{\pi}\right\rfloor\right) + \... 6 votes Accepted ### Numerical computation of two-sided (bilateral) Laplace transform With the substitution y=x+t, the t-dependency can be factored out:$$I(t)=\int_{-\infty}^\infty e^{-(y-t)}F(y)\;dy = e^t \int_{-\infty}^\infty e^{-y}F(y)\;dy = C\cdot e^t$$This still leaves ... • 481 6 votes Accepted ### Gaussian Numerical Differentiation Yes. As you may know, numerical differentiation and integration is closely related to (polynomial) interpolation: The idea to approximately differentiate or integrate a given function is to ... • 12.3k 6 votes Accepted ### Evaluating an integral numerically at many points The point of @WolfgangBangerth is exactly what I mentionend in my comment, so I'd always try this first. In the best case, with millions of partitions [a_{i},a_{i+1}]_{i\in \{0,\ldots,N-1\}} (where ... • 3,177 6 votes ### Numerical evaluation of highly oscillatory integral Ooura's method for Fourier sine integrals works here, see: Ooura, Takuya, and Masatake Mori, A robust double exponential formula for Fourier-type integrals. Journal of computational and applied ... • 2,155 6 votes Accepted ### Gauss-Lobatto quadrature and nodal points for FEM Ok, here comes the answer promised in the comment section. Let's start the other way round, going from a general grid to Gaussian grids and further constructions such as spectral elements. In grid ... • 3,177 5 votes Accepted ### Integrating Lagrange polynomials with many nodes, round-off The calculation of$$ \int_{-1}^{1} L_k(x)\,\text{d} x $$for the Lagrange polynomials L_k defined on an arbitrary grid x_k, k=0,\ldots,n can be performed by the following two steps: Calculate ... • 3,177 5 votes Accepted ### Numerical evaluation of gaussian-like integral expressible as a recurrence relation Step 1: analyze the recurrence I implemented the recurrence in Python, using basic numpy and scipy.special for the erf function. Why? Because it is simple and ... • 6,159 5 votes ### Building Gaussian-type quadrature schemes with Zernike polynomials Unfortunately the 1D reasoning will not directly carry into 2D and beyond. Depending on the domain for your integral, you will have considerable latitude in the node choice - but of course the ... • 3,283 5 votes ### Building Gaussian-type quadrature schemes with Zernike polynomials Yes, one can extend the Gaussian quadrature (in one dimension) to multiple dimensions. Often this is called cubature. Much work on this has been done by Ronald Cools and collaborators (see his ... • 6,159 5 votes ### What is the best numerical method for a six dimensional spherical integral? The Genz-Malik algorithm [1], as implemented in the cubature library, works well for computing 6-dimensional integrals. [1] A. C. Genz and A. A. Malik, “Remarks on algorithm 006: An adaptive ... • 3,994 5 votes Accepted ### Quadrature of rational functions Choose four collocation points in the interval [a,b], e.g.,  x_0=a\\ x_1=a + (1/3)(b-a)\\ x_2=a + (2/3)(b-a)\\ x_3=b  and form a matrix M \begin{bmatrix} 1 & x_0 & x_0^2 & x_0^3 \\ 1 ... • 2,575 5 votes ### Which way is the right way to compute the integrals in finite element methods? Quadrature and replacing the integrand by a polynomial are identical. That is how quadrature rules are derived. To see why this is true remember that quadrature evaluates the integrand at only a ... • 55.8k 4 votes ### Plot integral function with scipy and matplotlib ... • 141 4 votes Accepted ### Line integral along the edge of an isoparametrically mapped triangle Interestingly enough, you are using quadrature rule for a master triangle in order to integrate over a segment. You should use quadrature rule for a master segment (e.g. [-1, 1]) instead. You should ... • 901 4 votes ### 2D numerical integration with infinite limit (C++) There is a standard way to deal with infinite limits in integrals. This is explained nicely in the README of the cubature package (which you should use for low-but-... • 465 4 votes ### Numerical evaluation of a Gaussian Integral in Python? No need for quadrature; your integral can be computed analytically. For this, you'll have to do the variable transformation y = (x-\mu) / \sqrt{2} \sigma:$$ \int\limits_{-\infty}^{\infty} k\exp\...
• 3,126
This integral has a closed analytic solution. The trick is to write $$\frac{1}{x^3+ ax + 2a} = \frac{A}{x-x_1} + \frac{B}{x-x_2} + \frac{C}{x-x_3}$$ by a method called partial fraction decomposition. ...
Your integral can be written as $$\int_a^b f(z)^2 h(z) dz \approx \sum_q f(z_q)^2 h(z_q) w_q$$ where I wrote some quadrature approximation. Now do another quadrature for $f(z)$  f(z) = \int_0^z g(...