Integration

Your Progress in this Chapter

0%

0 / 4 units completed

Chapter Overview

Gauss Legendre

Section 7.2 of 723 min7 code examples

Gauss-Legendre Quadrature is a numerical integration technique designed to yield maximum algebraic precision with a minimal number of function evaluations. Unlike standard Newton-Cotes methods (such as the Trapezoidal or Simpson's rules) that use fixed, equally spaced evaluation points, Gauss-Legendre quadrature treats both the evaluation locations (nodes) and their corresponding multipliers (weights) as free variables.

Mathematical Foundation To evaluate a definite integral over a standardized interval [−1,1][-1, 1]:

∫−11f(x),dx≈∑i=1nwif(xi)\int_{-1}^{1} f(x) , dx \approx \sum_{i=1}^{n} w_i f(x_i)

The nodes xix_i are selected as the roots of the n-th degree Legendre polynomial Pn(x)P_n(x). The weights wiw_i are calculated by integrating the Lagrange interpolating polynomials over the interval:

wi=2(1−xi2)[Pn′(xi)]2w_i = \frac{2}{(1 - x_i^2) [P_n'(x_i)]^2}

An n-point Gauss-Legendre rule integrates polynomials of degree up to 2n - 1 exactly.

Domain Transformation (Mapping) For integrals over an arbitrary real interval [a, b], a linear change of variables maps the domain to [-1, 1]:

x(t)=b−a2t+a+b2x(t) = \frac{b - a}{2} t + \frac{a + b}{2}

dx=b−a2dtdx = \frac{b - a}{2} dt

The transformation yields:

∫abf(x),dx=b−a2∑i=1nwif(b−a2xi+a+b2)\int_{a}^{b} f(x) , dx = \frac{b - a}{2} \sum_{i=1}^{n} w_i f\left( \frac{b - a}{2} x_i + \frac{a + b}{2} \right)

Applied Examples (Solved via Simple Solver)

.. Admonition:: Example 1 : Exact Polynomial Integration (2-Point Rule)

Evaluate

∫02(x3−3x+2),dx\int_{0}^{2} (x^3 - 3x + 2) , dx

Example 1C#

1
2
Code is ready to run
OutputFrom the book
I = 2.0000

Exact Analytical Result:

[x44−3x22+2x]02=(4−6+4)−0=2\left[ \frac{x^4}{4} - \frac{3x^2}{2} + 2x \right]_0^2 = (4 - 6 + 4) - 0 = 2

.. Admonition:: Example 2 : Transcendental Function

∫0πsin⁡(x),dx\int_{0}^{\pi} \sin(x) , dx

Example 2C#

1
2
Code is ready to run
OutputFrom the book
I = 2.0000

Exact Analytical Result:

[−cos⁡(x)]0π=1−(−1)=2[-\cos(x)]_0^\pi = 1 - (-1) = 2

.. Admonition:: Example 3 : Infinite bound

Evaluate

∫0∞e−x2(ln⁡(x))2,dx\int_{0}^{\infty} e^{-x^2}(\ln(x))^2 , dx

Example 3C#

1
2
Code is ready to run
OutputFrom the book
I = 1.94752

Exact Analytical Result:

∫0∞e−x2(ln⁡(x))2,dx=π16(π2+2(γ+ln⁡(4))2)=1.94752\int_{0}^{\infty} e^{-x^2}(\ln(x))^2 , dx = \frac{\sqrt{\pi}}{16}\left(\pi^2 + 2(\gamma + \ln(4))^2\right) = 1.94752

Multiple Integral

SepalSolver can handle multiple integral via IntegralN. IntegralN is built on Integral running over multiply direction recursively. It is abole to compute upto 4 dimensional integrals efficiently.

.. Admonition:: Example 4 : Hypercube domain in 3 dimensions

Integrate the function f(x,y,z)=xyzf(x, y, z) = xyz over the region where xx ranges from 00 to 11, yy ranges from 11 to 22, and zz ranges from 22 to 33, which can be expressed as:

∫01∫12∫23xyz dz dy dx\int_{0}^{1} \int_{1}^{2} \int_{2}^{3} x y z \, dz \, dy \, dx

Example 4C#

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Code is ready to run
OutputFrom the book
The triple integral of x*y*z is approximately: 1.8750

.. Admonition:: Example 5 :

Integrate the function f(x,y)=xyf(x, y) = xy over the region where xx ranges from 00 to 11, yy ranges from x2x^2 to 22, which can be expressed as:

∫01∫x22xy dy dx\int_{0}^{1} \int_{x^2}^{2} x y \, dy \, dx

Example 5C#

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Code is ready to run
OutputFrom the book
The triple integral of x*y*z is approximately: 0.9167

.. Admonition:: Example 6 : Functional boundary

Integrate the function f(x,y,z)=xyzf(x, y, z) = xyz over the region where xx ranges from 00 to 11, yy ranges from x2x^2 to x\sqrt{x}, and zz ranges from 22 to 33, which can be expressed as:

∫01∫x2x∫23xyz dz dy dx\int_{0}^{1} \int_{x^2}^{\sqrt{x}} \int_{2}^{3} x y z \, dz \, dy \, dx

Example 6C#

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Code is ready to run
OutputFrom the book
The triple integral of x*y*z is approximately: 0.2083

.. Admonition:: Example 7 : Functional boundary

Integrate the function f(x,y,z)=xyzf(x, y, z) = xyz over the region where xx ranges from 00 to 11, yy ranges from x2x^2 to x\sqrt{x}, and zz ranges from xyxy to x+yx+y, which can be expressed as:

∫x1x2∫x2x∫xyx+yxyz dz dy dx\int_{x_1}^{x_2} \int_{x^2}^{\sqrt{x}} \int_{xy}^{x+y} x y z \, dz \, dy \, dx

Example 7C#

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Code is ready to run
OutputFrom the book
The triple integral of x*y*z is approximately: 0.0641