4.8.15Numerical Methods

Numerical integration — trapezoidal rule (composite), error

1,359 words6 min readdifficulty · medium6 backlinks

1. From first principles — one strip

HOW we approximate one strip [xi,xi+1][x_i, x_{i+1}] of width h=xi+1xih=x_{i+1}-x_i:

Replace ff by the straight line L(x)L(x) through the endpoints (xi,f(xi))(x_i,f(x_i)) and (xi+1,f(xi+1))(x_{i+1},f(x_{i+1})). The region under LL is a trapezium with parallel sides f(xi)f(x_i) and f(xi+1)f(x_{i+1}) and height hh.


2. Composite rule — chain the strips

Derivation by summing: abfdxk=0n1h2(f(xk)+f(xk+1))\int_a^b f\,dx \approx \sum_{k=0}^{n-1}\frac{h}{2}\big(f(x_k)+f(x_{k+1})\big) Write out terms: f(x0)+f(x1)  +  f(x1)+f(x2)  ++  f(xn1)+f(xn)f(x_0)+f(x_1)\;+\;f(x_1)+f(x_2)\;+\dots+\;f(x_{n-1})+f(x_n). Every interior node x1,,xn1x_1,\dots,x_{n-1} appears in two strips → counted twice. Endpoints appear once.


Figure — Numerical integration — trapezoidal rule (composite), error

3. The error — where does it come from?

Single-strip error (derive the order). On [xi,xi+1][x_i,x_{i+1}], Taylor-expand and integrate the difference. The exact result (from integrating the interpolation error of a line): Estrip=h312f(ξi),ξi(xi,xi+1)E_{\text{strip}} = -\frac{h^3}{12}f''(\xi_i),\qquad \xi_i\in(x_i,x_{i+1})

Composite error. Sum over nn strips and use the mean of the f(ξi)f''(\xi_i) values f(ξ)\to f''(\xi): En=h312f(ξi)=h312nf(ξ)E_n=\sum -\frac{h^3}{12}f''(\xi_i)= -\frac{h^3}{12}\,n\,f''(\xi) Now n=bahn=\dfrac{b-a}{h}, so nh3=(ba)h2n h^3 = (b-a)h^2:


4. Worked examples


5. Common mistakes (steel-manned)


Recall Feynman: explain to a 12-year-old

Imagine a wiggly hill and you want the area under it. You can't measure a wiggle, but you CAN measure straight slopes. So you cut the hill into thin slices and pretend each slice's top is a straight ramp. The area under a ramp is easy (a slanted box). Add all the boxes — that's your answer. If the hill curves a lot, thin slices guess wrong by a little; making slices twice as thin makes the mistake four times smaller.


Flashcards

Composite trapezoidal formula
Tn=h2[f(x0)+2k=1n1f(xk)+f(xn)]T_n=\frac{h}{2}\big[f(x_0)+2\sum_{k=1}^{n-1}f(x_k)+f(x_n)\big], h=banh=\frac{b-a}{n}
Node weights pattern
1,2,2,,2,11,2,2,\dots,2,1 (endpoints 1, interiors 2)
Global error of composite trapezoidal
En=(ba)12h2f(ξ)E_n=-\frac{(b-a)}{12}h^2 f''(\xi), i.e. O(h2)O(h^2)
What happens to error if you double nn?
It falls by a factor of 4\approx 4 (since Eh2=1/n2E\propto h^2=1/n^2)
Trapezoidal rule is exact for polynomials up to degree
1 (linear), because error contains ff''
Sign of error when ff is convex (f>0f''>0)
Positive — rule overestimates (chord above curve)
Single-strip error term
h312f(ξ)-\frac{h^3}{12}f''(\xi) on each strip
Why interior nodes get weight 2
Each interior node is shared by two adjacent strips
Number of nodes for nn strips
n+1n+1

Connections

  • Simpson's Rule — fits parabolas, error O(h4)O(h^4), exact to degree 3
  • Riemann Sums — trapezoidal = average of left & right Riemann sums
  • Taylor's Theorem — source of the interpolation error term
  • Linear Interpolation — the line L(x)L(x) on each strip
  • Richardson Extrapolation — combine Tn,T2nT_n,T_{2n} to kill the h2h^2 term → Romberg
  • Numerical Methods — parent index

Concept Map

often no antiderivative

curve looks straight

area under line

avg height x width

chain n strips and add

interior counted twice

ignores curvature

scales with f''

sum over n strips

f''>0 convex

smaller h

Need integral a to b

Approximate numerically

Replace f by line per strip

Trapezium area

Single strip = h/2 f0+f1

Composite rule Tn

Weights 1,2,...,2,1

Error source

Strip error = -h^3/12 f''

Composite error order h^2

Overestimate

Better accuracy as h to 0

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, kabhi-kabhi integral abf(x)dx\int_a^b f(x)\,dx nikalna mushkil hota hai kyunki antiderivative milta hi nahi (jaise ex2e^{-x^2}), ya phir function sirf kuch data points pe pata hai. Toh hum area ko approximate karte hain. Trapezoidal rule ka core idea simple hai: poore interval ko nn patli-patli strips mein kaato (har strip ki width h=banh=\frac{b-a}{n}), aur har strip ke upar curve ko seedhi line maan lo. Seedhi line ke neeche ka area ek trapezium hota hai, jiska area =h2(left height+right height)=\frac{h}{2}(\text{left height}+\text{right height}).

Jab sab strips ko jodte ho, toh interior wale points dono taraf ke strips mein aate hain, isliye unka weight 2 ho jata hai, aur do endpoints ka weight 1. Yahi se formula banta hai: Tn=h2[f0+2(f1++fn1)+fn]T_n=\frac{h}{2}[f_0+2(f_1+\dots+f_{n-1})+f_n]. Pattern yaad rakho: 1,2,2,,2,11,2,2,\dots,2,1.

Ab error ki baat. Seedhi line curve ka curvature (mudna) ignore karti hai, isliye error ff'' pe depend karta hai: En=(ba)12h2f(ξ)E_n=-\frac{(b-a)}{12}h^2 f''(\xi). Sabse important baat — error h2h^2 ke proportional hai. Matlab agar tum strips ko double kar do (nn double, hh aadha), toh error chaar guna kam ho jata hai! Agar function convex hai (f>0f''>0, cup-jaisa upar khula), toh chord curve ke upar rahegi, toh rule thoda zyada estimate karega. Yeh intuition exam mein sign-check ke liye bahut kaam aata hai.

Test yourself — Numerical Methods

Connections