Intuition The big idea (WHY)
Normal quadrature rules (trapezoid, Simpson) fix the points (evenly spaced) and only choose the weights . Gauss said: why throw away half my freedom? If I'm allowed to choose both the n n n nodes x i x_i x i and the n n n weights w i w_i w i , I have 2 n 2n 2 n free numbers — so I should be able to integrate polynomials up to degree 2 n − 1 2n-1 2 n − 1 exactly , instead of just degree n − 1 n-1 n − 1 .
That's the whole game: spend your 2 n 2n 2 n degrees of freedom to kill the highest-degree error you possibly can.
Definition Gauss–Legendre quadrature
We approximate
∫ − 1 1 f ( x ) d x ≈ ∑ i = 1 n w i f ( x i ) \int_{-1}^{1} f(x)\,dx \;\approx\; \sum_{i=1}^{n} w_i\, f(x_i) ∫ − 1 1 f ( x ) d x ≈ ∑ i = 1 n w i f ( x i )
where the nodes x i x_i x i are the ==roots of the Legendre polynomial P n ( x ) P_n(x) P n ( x ) == and the weights w i w_i w i are chosen so the rule is exact for all polynomials of degree ≤ 2 n − 1 \le 2n-1 ≤ 2 n − 1 .
Why the interval [ − 1 , 1 ] [-1,1] [ − 1 , 1 ] ? Because the magic happens with Legendre polynomials , which are orthogonal on [ − 1 , 1 ] [-1,1] [ − 1 , 1 ] . Any real integral ∫ a b \int_a^b ∫ a b is converted to [ − 1 , 1 ] [-1,1] [ − 1 , 1 ] by a linear change of variable (shown below).
We want
∫ − 1 1 f ( x ) d x ≈ w 1 f ( x 1 ) + w 2 f ( x 2 ) , \int_{-1}^{1} f(x)\,dx \approx w_1 f(x_1) + w_2 f(x_2), ∫ − 1 1 f ( x ) d x ≈ w 1 f ( x 1 ) + w 2 f ( x 2 ) ,
exact for degree ≤ 2 n − 1 = 3 \le 2n-1 = 3 ≤ 2 n − 1 = 3 . Four unknowns ( w 1 , w 2 , x 1 , x 2 ) (w_1,w_2,x_1,x_2) ( w 1 , w 2 , x 1 , x 2 ) , so impose exactness on the basis 1 , x , x 2 , x 3 1, x, x^2, x^3 1 , x , x 2 , x 3 :
f = 1 : w 1 + w 2 = ∫ − 1 1 1 d x = 2 f = x : w 1 x 1 + w 2 x 2 = ∫ − 1 1 x d x = 0 f = x 2 : w 1 x 1 2 + w 2 x 2 2 = ∫ − 1 1 x 2 d x = 2 3 f = x 3 : w 1 x 1 3 + w 2 x 2 3 = ∫ − 1 1 x 3 d x = 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} f = 1 : f = x : f = x 2 : f = x 3 : w 1 + w 2 = ∫ − 1 1 1 d x = 2 w 1 x 1 + w 2 x 2 = ∫ − 1 1 x d x = 0 w 1 x 1 2 + w 2 x 2 2 = ∫ − 1 1 x 2 d x = 3 2 w 1 x 1 3 + w 2 x 2 3 = ∫ − 1 1 x 3 d x = 0
Why these equations? If the rule integrates every monomial exactly, by linearity it integrates every polynomial of degree ≤ 3 \le 3 ≤ 3 exactly.
By symmetry guess x 2 = − x 1 x_2 = -x_1 x 2 = − x 1 , w 1 = w 2 = w w_1 = w_2 = w w 1 = w 2 = w .
From f = 1 f=1 f = 1 : 2 w = 2 ⇒ w = 1 2w = 2 \Rightarrow w = 1 2 w = 2 ⇒ w = 1 . (Why? both weights equal, sum to 2.)
f = x f=x f = x and f = x 3 f=x^3 f = x 3 auto-satisfied by the odd symmetry. (Why? odd function over symmetric nodes cancels.)
From f = x 2 f=x^2 f = x 2 : x 1 2 + x 2 2 = 2 x 1 2 = 2 3 ⇒ x 1 = 1 3 x_1^2 + x_2^2 = 2x_1^2 = \tfrac23 \Rightarrow x_1 = \tfrac{1}{\sqrt3} x 1 2 + x 2 2 = 2 x 1 2 = 3 2 ⇒ x 1 = 3 1 .
∫ − 1 1 f d x ≈ f ( − 1 3 ) + f ( 1 3 ) \boxed{\int_{-1}^{1} f\,dx \approx f\!\left(-\tfrac{1}{\sqrt3}\right) + f\!\left(\tfrac{1}{\sqrt3}\right)} ∫ − 1 1 f d x ≈ f ( − 3 1 ) + f ( 3 1 )
P n P_n P n specifically?
Write f = q ( x ) P n ( x ) + r ( x ) f = q(x)P_n(x) + r(x) f = q ( x ) P n ( x ) + r ( x ) where deg q , deg r ≤ n − 1 \deg q,\deg r \le n-1 deg q , deg r ≤ n − 1 (polynomial division). Then ∫ − 1 1 f = ∫ q P n + ∫ r \int_{-1}^1 f = \int q P_n + \int r ∫ − 1 1 f = ∫ q P n + ∫ r . The first integral is 0 0 0 because P n P_n P n is orthogonal to every lower-degree polynomial q q q . The quadrature sum on q P n qP_n q P n is also 0 0 0 if we place nodes at the roots of P n P_n P n (since P n ( x i ) = 0 P_n(x_i)=0 P n ( x i ) = 0 ). So both sides only "see" r r r , degree ≤ n − 1 \le n-1 ≤ n − 1 — which any interpolatory rule handles exactly. That's why nodes = roots of P n P_n P n buys you degree 2 n − 1 2n-1 2 n − 1 .
Indeed P 2 ( x ) = 1 2 ( 3 x 2 − 1 ) P_2(x)=\tfrac12(3x^2-1) P 2 ( x ) = 2 1 ( 3 x 2 − 1 ) has roots ± 1 / 3 \pm 1/\sqrt3 ± 1/ 3 — matching our derivation.
The weights are the integrals of the Lagrange basis at the nodes:
w i = ∫ − 1 1 ∏ j ≠ i x − x j x i − x j d x , w_i = \int_{-1}^1 \prod_{j\ne i}\frac{x-x_j}{x_i-x_j}\,dx, w i = ∫ − 1 1 ∏ j = i x i − x j x − x j d x ,
which guarantees exactness for degree ≤ n − 1 \le n-1 ≤ n − 1 ; orthogonality boosts it to 2 n − 1 2n-1 2 n − 1 . A closed form:
w i = 2 ( 1 − x i 2 ) [ P n ′ ( x i ) ] 2 . w_i = \frac{2}{(1-x_i^2)\,[P_n'(x_i)]^2}. w i = ( 1 − x i 2 ) [ P n ′ ( x i ) ] 2 2 .
Worked example 1. Exact case:
∫ − 1 1 ( 3 x 3 − x 2 + 2 ) d x \int_{-1}^1 (3x^3 - x^2 + 2)\,dx ∫ − 1 1 ( 3 x 3 − x 2 + 2 ) d x with 2-point rule
Nodes ± 1 / 3 \pm1/\sqrt3 ± 1/ 3 , weights 1 , 1 1,1 1 , 1 .
f ( 1 / 3 ) = 3 ( 1 3 3 ) − 1 3 + 2 = 1 3 + 5 3 f(1/\sqrt3) = 3(\tfrac{1}{3\sqrt3}) - \tfrac13 + 2 = \tfrac{1}{\sqrt3} + \tfrac53 f ( 1/ 3 ) = 3 ( 3 3 1 ) − 3 1 + 2 = 3 1 + 3 5 .
f ( − 1 / 3 ) = − 1 3 + 5 3 f(-1/\sqrt3) = -\tfrac{1}{\sqrt3} + \tfrac53 f ( − 1/ 3 ) = − 3 1 + 3 5 .
Sum = 10 3 = \tfrac{10}{3} = 3 10 .
Why exact? Degree 3 ≤ 2 n − 1 = 3 3 \le 2n-1=3 3 ≤ 2 n − 1 = 3 . True value: ∫ − 1 1 ( 3 x 3 − x 2 + 2 ) = 0 − 2 3 + 4 = 10 3 \int_{-1}^1(3x^3-x^2+2) = 0 - \tfrac23 + 4 = \tfrac{10}{3} ∫ − 1 1 ( 3 x 3 − x 2 + 2 ) = 0 − 3 2 + 4 = 3 10 . ✓
∫ 0 1 e x d x \int_0^1 e^x\,dx ∫ 0 1 e x d x with 2-point rule
Map: x = 1 2 t + 1 2 x = \tfrac12 t + \tfrac12 x = 2 1 t + 2 1 , factor b − a 2 = 1 2 \tfrac{b-a}{2}=\tfrac12 2 b − a = 2 1 .
Nodes t = ± 1 / 3 ⇒ x = 0.21132 , 0.78868 t=\pm1/\sqrt3 \Rightarrow x = 0.21132,\ 0.78868 t = ± 1/ 3 ⇒ x = 0.21132 , 0.78868 (Why? plug t t t into the map.)
1 2 ( e 0.21132 + e 0.78868 ) = 1 2 ( 1.2353 + 2.2005 ) = 1.7179 \tfrac12\big(e^{0.21132}+e^{0.78868}\big) = \tfrac12(1.2353 + 2.2005) = 1.7179 2 1 ( e 0.21132 + e 0.78868 ) = 2 1 ( 1.2353 + 2.2005 ) = 1.7179 .
Exact = e − 1 = 1.71828 = e-1 = 1.71828 = e − 1 = 1.71828 . Error ≈ 4 × 10 − 5 \approx 4\times10^{-5} ≈ 4 × 1 0 − 5 from just two evaluations — Simpson with 2 intervals is far worse.
Worked example 3. Forecast-then-Verify
Forecast: will the 2-point rule be exact for ∫ − 1 1 x 4 d x \int_{-1}^1 x^4\,dx ∫ − 1 1 x 4 d x ? Degree 4 > 3 > 3 > 3 , so no .
Verify: rule gives ( 1 / 3 ) 4 + ( − 1 / 3 ) 4 = 2 ⋅ 1 9 = 2 9 ≈ 0.222 (1/\sqrt3)^4 + (-1/\sqrt3)^4 = 2\cdot\tfrac19 = \tfrac29 \approx 0.222 ( 1/ 3 ) 4 + ( − 1/ 3 ) 4 = 2 ⋅ 9 1 = 9 2 ≈ 0.222 . True value = 2 5 = 0.4 =\tfrac25=0.4 = 5 2 = 0.4 . Not exact — confirms the degree limit. (Why this matters: it tells you exactly when to add more nodes.)
Common mistake "Gauss nodes are evenly spaced like Simpson's."
Why it feels right: every rule you learned before (trapezoid, Simpson) uses equal spacing, so you assume Gauss does too.
Fix: Gauss nodes are the roots of P n P_n P n — clustered toward the interior/ends asymmetrically , never including the endpoints ± 1 \pm1 ± 1 . The non-uniform placement is exactly what buys the extra accuracy.
Common mistake "Forgetting the
b − a 2 \frac{b-a}{2} 2 b − a scale factor."
Why it feels right: on [ − 1 , 1 ] [-1,1] [ − 1 , 1 ] you never needed it, so it's easy to drop.
Fix: Whenever b − a ≠ 2 b-a\ne 2 b − a = 2 , both the weight sum and the node remap must be scaled. Quick sanity check: integrate f = 1 f=1 f = 1 ; the rule must return b − a b-a b − a , not 2 2 2 .
n n n -point rule is exact up to degree n n n ."
Why it feels right: n n n points → degree n n n polynomial fitting (interpolation intuition).
Fix: It's exact to degree = = 2 n − 1 = = ==2n-1== == 2 n − 1 == , because you also tuned the nodes. That doubling is the entire payoff of Gauss.
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.
Mnemonic Remember the magic
"Pick points and weights → power D oubles." n n n points → degree 2 n − 1 2n-1 2 n − 1 . And the 2-point nodes: "one over root three" ± 1 3 \pm\frac{1}{\sqrt3} ± 3 1 , weights both 1 .
Why can an n n n -point Gauss rule be exact to degree 2 n − 1 2n-1 2 n − 1 ? It has
2 n 2n 2 n free parameters (
n n n nodes +
n n n weights), enough to match
2 n 2n 2 n moment conditions
∫ x k \int x^k ∫ x k for
k = 0..2 n − 1 k=0..2n-1 k = 0..2 n − 1 .
Where are the nodes of Gauss–Legendre placed? At the roots of the Legendre polynomial
P n ( x ) P_n(x) P n ( x ) on
[ − 1 , 1 ] [-1,1] [ − 1 , 1 ] .
What are the 2-point Gauss–Legendre nodes and weights? x = ± 1 3 x=\pm\frac{1}{\sqrt3} x = ± 3 1 ,
w 1 = w 2 = 1 w_1=w_2=1 w 1 = w 2 = 1 .
Why do roots of P n P_n P n give the extra accuracy? P n P_n P n is orthogonal to all lower-degree polynomials, so the high-degree remainder
q P n qP_n q P n integrates to 0 and vanishes at the nodes.
What change of variable maps [ a , b ] [a,b] [ a , b ] to [ − 1 , 1 ] [-1,1] [ − 1 , 1 ] ? x = b − a 2 t + a + b 2 x=\frac{b-a}{2}t+\frac{a+b}{2} x = 2 b − a t + 2 a + b , with extra factor
b − a 2 \frac{b-a}{2} 2 b − a .
Closed-form weight formula? w i = 2 ( 1 − x i 2 ) [ P n ′ ( x i ) ] 2 w_i=\frac{2}{(1-x_i^2)[P_n'(x_i)]^2} w i = ( 1 − x i 2 ) [ P n ′ ( x i ) ] 2 2 .
Does Gauss–Legendre include the endpoints ± 1 \pm1 ± 1 ? No (that's Gauss–Lobatto). Standard Gauss–Legendre nodes are strictly interior.
Sanity check that you scaled correctly on [ a , b ] [a,b] [ a , b ] ? Integrating
f = 1 f=1 f = 1 must return
b − a b-a b − a .
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 ( 2 n ) ( ξ ) \propto f^{(2n)}(\xi) ∝ f ( 2 n ) ( ξ )
2n free numbers nodes plus weights
Integrate polynomials up to degree 2n-1 exactly
Gauss-Legendre rule sum wi f xi
Pn orthogonal to lower degrees
Exactness on monomials 1 x x2 x3
2-point rule f at plus-minus 1 over root3
Linear change of variable
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. n n n points matlab 2 n 2n 2 n free numbers, isliye degree 2 n − 1 2n-1 2 n − 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 P n ( x ) P_n(x) P n ( x ) ke roots par. Reason yeh hai ki P n P_n P n har chhote degree ke polynomial ke orthogonal hota hai, toh jab tum kisi function ko f = q P n + r f = q\,P_n + r f = q P n + r likhte ho, toh q P n qP_n q P n ka integral 0 ho jaata hai aur nodes par bhi P n = 0 P_n=0 P n = 0 hone se woh term gayab. Bas r r r 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 ± 1 3 \pm\frac{1}{\sqrt3} ± 3 1 , weights dono = 1 =1 = 1 . Agar interval [ − 1 , 1 ] [-1,1] [ − 1 , 1 ] nahi hai, toh change of variable x = b − a 2 t + a + b 2 x=\frac{b-a}{2}t+\frac{a+b}{2} x = 2 b − a t + 2 a + b lagao aur saamne b − a 2 \frac{b-a}{2} 2 b − a ka factor mat bhoolna (yeh Jacobian hai, width ko adjust karta hai). Quick check: f = 1 f=1 f = 1 daalo, answer b − a b-a b − a aana chahiye.
Practically, ∫ 0 1 e x \int_0^1 e^x ∫ 0 1 e x sirf do points se itni accurate aati hai ki error 10 − 5 10^{-5} 1 0 − 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.