Gauss-Legendre Quadrature
Source inspiration: (Mathew 2000-2019).
Description
Gauss-Legendre quadrature approximates \(\int_a^b f(x)\,dx\) by evaluating \(f\) at optimally chosen interior nodes and weighting those values. For the transformed interval \([-1,1]\), the \(n\)-point rule has the form \[ \int_{-1}^{1} g(t)\,dt \approx \sum_{i=1}^{n} w_i\,g(t_i), \] where \(t_i\) are roots of the Legendre polynomial \(P_n(t)\) and \(w_i\) are associated weights.
For a general interval \([a,b]\) with \(x=\tfrac{a+b}{2}+\tfrac{b-a}{2}t\), \[ \int_a^b f(x)\,dx \approx \frac{b-a}{2}\sum_{i=1}^{n} w_i\,f\!\left(\frac{a+b}{2}+\frac{b-a}{2}t_i\right). \] The rule is exact for polynomials up to degree \(2n-1\).
Animations
Each animation below shows the Gauss-Legendre sampling geometry for \(f(x)=1+e^{-x}\sin(8x^{2/3})\) on \([0,2]\). Each frame increases the quadrature order \(n\) and recomputes nodes and weights across the full interval.
Julia source scripts that generated these animations are linked under each case.
Case 1 — Increasing-Order Gauss-Legendre Rule, \(f(x)=1+e^{-x}\sin(8x^{2/3})\) on \([0,2]\)
Behavior: The shaded bars visualize weighted sample contributions built from Gauss-Legendre nodes. As \(n\) grows, the node distribution becomes denser and the weighted estimate stabilizes rapidly.

This page follows the archived module equation and compares \(I_n=\sum_{i=1}^n w_i f(x_i)\) against a high-resolution numerical reference for \(f(x)=1+e^{-x}\sin\!\left(8x^{2/3}\right)\) on \([0,2]\).