4.8.17Numerical Methods

Gaussian quadrature — Gauss-Legendre

1,594 words7 min readdifficulty · medium2 backlinks

WHAT we are trying to do

Why the interval [1,1][-1,1]? Because the magic happens with Legendre polynomials, which are orthogonal on [1,1][-1,1]. Any real integral ab\int_a^b is converted to [1,1][-1,1] by a linear change of variable (shown below).


HOW: derive the 2-point rule from scratch

We want 11f(x)dxw1f(x1)+w2f(x2),\int_{-1}^{1} f(x)\,dx \approx w_1 f(x_1) + w_2 f(x_2), exact for degree 2n1=3\le 2n-1 = 3. Four unknowns (w1,w2,x1,x2)(w_1,w_2,x_1,x_2), so impose exactness on the basis 1,x,x2,x31, x, x^2, x^3:

f=1:w1+w2=111dx=2f=x:w1x1+w2x2=11xdx=0f=x2:w1x12+w2x22=11x2dx=23f=x3:w1x13+w2x23=11x3dx=0\begin{aligned} f=1:&\quad w_1 + w_2 = \int_{-1}^1 1\,dx = 2\\ f=x:&\quad w_1 x_1 + w_2 x_2 = \int_{-1}^1 x\,dx = 0\\ f=x^2:&\quad w_1 x_1^2 + w_2 x_2^2 = \int_{-1}^1 x^2\,dx = \tfrac23\\ f=x^3:&\quad w_1 x_1^3 + w_2 x_2^3 = \int_{-1}^1 x^3\,dx = 0 \end{aligned}

Why these equations? If the rule integrates every monomial exactly, by linearity it integrates every polynomial of degree 3\le 3 exactly.

By symmetry guess x2=x1x_2 = -x_1, w1=w2=ww_1 = w_2 = w.

  • From f=1f=1: 2w=2w=12w = 2 \Rightarrow w = 1. (Why? both weights equal, sum to 2.)
  • f=xf=x and f=x3f=x^3 auto-satisfied by the odd symmetry. (Why? odd function over symmetric nodes cancels.)
  • From f=x2f=x^2: x12+x22=2x12=23x1=13x_1^2 + x_2^2 = 2x_1^2 = \tfrac23 \Rightarrow x_1 = \tfrac{1}{\sqrt3}.

11fdxf ⁣(13)+f ⁣(13)\boxed{\int_{-1}^{1} f\,dx \approx f\!\left(-\tfrac{1}{\sqrt3}\right) + f\!\left(\tfrac{1}{\sqrt3}\right)}

Indeed P2(x)=12(3x21)P_2(x)=\tfrac12(3x^2-1) has roots ±1/3\pm 1/\sqrt3 — matching our derivation.


The weight formula (WHY it works)

The weights are the integrals of the Lagrange basis at the nodes: wi=11jixxjxixjdx,w_i = \int_{-1}^1 \prod_{j\ne i}\frac{x-x_j}{x_i-x_j}\,dx, which guarantees exactness for degree n1\le n-1; orthogonality boosts it to 2n12n-1. A closed form: wi=2(1xi2)[Pn(xi)]2.w_i = \frac{2}{(1-x_i^2)\,[P_n'(x_i)]^2}.


Change of interval ([a,b][1,1][a,b]\to[-1,1])

Figure — Gaussian quadrature — Gauss-Legendre

Worked examples


Common mistakes


Recall Feynman: explain to a 12-year-old

Imagine weighing a wiggly snake to find its area. Old rulers make you measure at fixed, equally-spaced spots. Gauss says: "Let me pick the smartest spots myself and decide how much each spot counts." With the same number of measurements he can be perfectly correct for much wigglier snakes (curves). The secret spots he picks are special points called the zeros of Legendre polynomials — points that are arranged so the leftover error cancels out completely.


Active recall

Why can an nn-point Gauss rule be exact to degree 2n12n-1?
It has 2n2n free parameters (nn nodes + nn weights), enough to match 2n2n moment conditions xk\int x^k for k=0..2n1k=0..2n-1.
Where are the nodes of Gauss–Legendre placed?
At the roots of the Legendre polynomial Pn(x)P_n(x) on [1,1][-1,1].
What are the 2-point Gauss–Legendre nodes and weights?
x=±13x=\pm\frac{1}{\sqrt3}, w1=w2=1w_1=w_2=1.
Why do roots of PnP_n give the extra accuracy?
PnP_n is orthogonal to all lower-degree polynomials, so the high-degree remainder qPnqP_n integrates to 0 and vanishes at the nodes.
What change of variable maps [a,b][a,b] to [1,1][-1,1]?
x=ba2t+a+b2x=\frac{b-a}{2}t+\frac{a+b}{2}, with extra factor ba2\frac{b-a}{2}.
Closed-form weight formula?
wi=2(1xi2)[Pn(xi)]2w_i=\frac{2}{(1-x_i^2)[P_n'(x_i)]^2}.
Does Gauss–Legendre include the endpoints ±1\pm1?
No (that's Gauss–Lobatto). Standard Gauss–Legendre nodes are strictly interior.
Sanity check that you scaled correctly on [a,b][a,b]?
Integrating f=1f=1 must return bab-a.

Connections

  • Legendre polynomials — source of the nodes (orthogonality)
  • Orthogonal polynomials — general recipe for Gauss-type rules
  • Newton-Cotes formulas — fixed-node cousins (trapezoid, Simpson)
  • Gauss-Lobatto quadrature — variant including endpoints
  • Polynomial interpolation — Lagrange basis behind the weights
  • Numerical integration error analysis — error f(2n)(ξ)\propto f^{(2n)}(\xi)

Concept Map

enables

defines

roots give

used in

property of

boosts degree to 2n-1

solved to find

for n=2 gives

Lagrange integrals

orthogonal on

works on

maps a b to

2n free numbers nodes plus weights

Integrate polynomials up to degree 2n-1 exactly

Gauss-Legendre rule sum wi f xi

Legendre polynomial Pn

Nodes xi = roots of Pn

Pn orthogonal to lower degrees

Weights wi

Exactness on monomials 1 x x2 x3

2-point rule f at plus-minus 1 over root3

Interval -1 to 1

Linear change of variable

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, Gaussian quadrature ka core idea bahut simple hai. Trapezoid ya Simpson rule me hum points fix kar dete hain (equally spaced) aur sirf weights choose karte hain. Gauss ne bola — bhai, agar mujhe points aur weights dono choose karne ki freedom hai, toh main double accuracy le sakta hoon. nn points matlab 2n2n free numbers, isliye degree 2n12n-1 tak ke polynomials bilkul exactly integrate ho jaate hain. Yeh "power doubles" wala fayda hi poori kahani hai.

Ab sawaal: points kahan rakhein? Answer — Legendre polynomial Pn(x)P_n(x) ke roots par. Reason yeh hai ki PnP_n har chhote degree ke polynomial ke orthogonal hota hai, toh jab tum kisi function ko f=qPn+rf = q\,P_n + r likhte ho, toh qPnqP_n ka integral 0 ho jaata hai aur nodes par bhi Pn=0P_n=0 hone se woh term gayab. Bas rr bachta hai jo low-degree hai — easy. Isiliye non-uniform, andar ki taraf wale points hi extra accuracy dete hain.

2-point rule yaad rakho: nodes ±13\pm\frac{1}{\sqrt3}, weights dono =1=1. Agar interval [1,1][-1,1] nahi hai, toh change of variable x=ba2t+a+b2x=\frac{b-a}{2}t+\frac{a+b}{2} lagao aur saamne ba2\frac{b-a}{2} ka factor mat bhoolna (yeh Jacobian hai, width ko adjust karta hai). Quick check: f=1f=1 daalo, answer bab-a aana chahiye.

Practically, 01ex\int_0^1 e^x sirf do points se itni accurate aati hai ki error 10510^{-5} ke aas-paas — Simpson se kahin behtar same number of evaluations me. Isiliye numerical integration me, jab function smooth ho, Gauss–Legendre best value-for-money rule hai.

Test yourself — Numerical Methods

Connections