# Comparison of three quadrature rules

Sometimes, in science and engineering, we need to calculate some definite integrals of the type:

It is equivalent to evaluating the area enclosed between the function graph and x-axis, within the interval [a, b]. There are some integrals (like elliptical, Fresnel, etc.) that cannot be expressed in analytical form. In such cases, we have to use numerical methods, also called quadrature rules. They approximate the integral by a finite sum like follows:

where xi are the abscissas of the nodes, where the function is calculated, and wi are the respective weights. Most quadrature rules use the same formula, but with different values for abscissas and weights.

Probably, most engineers are already familiar with Newton’s or Gauss formulas for numerical integration. However, there are other contemporary methods that can be more efficient for this purpose.

In this post, we will compare three quadrature rules for numerical integration. They will be applied to the same function, and with the same number of nodes. The calculations will be performed with Calcpad, as follows:

Test function (half-circle):

Theoretical value of the integral:

Number of nodes: n = 5

## Boole’s rule

This is one of the Newton-Cotes‘ family of quadrature formulas, with order of n = 4. Nodes are located at equal spacing h, and weights are calculated by approximating the function with Lagrange polynomials.

Spacing – h = 0.5

Integral:

Error:

Scheme:

## Gauss-Legendre’s formula

This is the most simple Gaussian quadrature formula. The function is approximated by Legendre polynomials in the interval of [-1; 1]. Abscissas are determined as the roots of the respective polynomials, so the nodes are not equally spaced.

Abscissas and weights are calculated by the following equations:

Integral:

IG = 2·w1·y1 + 2·w2·y2 + w3·y3 = 2·0.23693·0.42289 + 2·0.47863·0.84265 + 0.56889·1
IG = 1.5759

Error:

Scheme:

This is one of the double exponential integration formulas, proposed by Takahasi and Mori (1974).

Boundary of the interval – ta = 1

Step:

Parameter – tk = –ta + (k – 1) ·h

Formula for calculation of abscissas:

Formula for calculation of weights:

Integral:

Value:

IDE = 2·w1·y1 + 2·w2·y2 + w3·y3 = 2·0.11501·0.30806 + 2·0.48299·0.73848 + 0.7854·1
IDE = 1.5696

Error:

Scheme:

## Summary of the results

The relative errors, from the above three quadrature rules are presented in the following chart:

We can see that the Gaussian quadrature rule is much more precise than the Newton-Cotes’ one of the same order, which is expected. However, Tanh-Sinh quadrature shows the best results from all three. And this is not by chance. According to Wikipedia, this is probably the most efficient numerical integration rule ever known.

That is why, it’s adaptive version is implemented in Calcpad as the main numerical integration method (\$Integral command). Alternatively, you can use the adaptive Gauss-Lobatto quadrature (\$Area command). It is much slower, but unlike the Tanh-Sinh one, it works for functions that are not smooth and continuous.

For the above example, both of them provides extremely high accuracy, that is comparable to the floating point precision of the double (float64) data type: