Skip to main content
15 votes

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 ...
Nico Schlömer's user avatar
14 votes

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 ...
kostyfisik's user avatar
12 votes

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$...
smh's user avatar
  • 693
10 votes

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 ...
Kirill's user avatar
  • 11.4k
8 votes
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 ...
Kirill's user avatar
  • 11.4k
7 votes
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$ ...
Jan's user avatar
  • 3,418
7 votes
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)...
GertVdE's user avatar
  • 6,159
7 votes
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 ...
Bill Greene's user avatar
  • 6,144
7 votes

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 ...
David Saykin's user avatar
7 votes

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 ...
Federico Poloni's user avatar
6 votes

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 ...
Anton Menshov's user avatar
  • 8,692
6 votes

In C++, how do you calculate the analytical value of $\int_a^b \left|\sin x \right|\,dx$?

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) + \...
SassyQuatch's user avatar
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 ...
cdalitz's user avatar
  • 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 ...
Christian Clason's user avatar
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 $...
davidhigh's user avatar
  • 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 ...
user14717's user avatar
  • 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 ...
davidhigh's user avatar
  • 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 ...
davidhigh's user avatar
  • 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 ...
GertVdE's user avatar
  • 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 ...
Reid.Atcheson's user avatar
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 ...
GertVdE's user avatar
  • 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 ...
Juan M. Bello-Rivas's user avatar
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 ...
Maxim Umansky's user avatar
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 ...
Wolfgang Bangerth's user avatar
4 votes

Plot integral function with scipy and matplotlib

...
YakovK's user avatar
  • 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 ...
56th's user avatar
  • 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-...
Henri Menke's user avatar
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\...
Nico Schlömer's user avatar
4 votes

Evaluating an indefinite integral that has no closed form

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. ...
cdalitz's user avatar
  • 481
4 votes

How to implement Simpson's rule for double integral (without numeric limits of first integral)

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(...
cfdlab's user avatar
  • 3,028

Only top scored, non community-wiki answers of a minimum length are eligible