4.7.21Partial Differential Equations

Intro to finite difference methods for PDEs

1,697 words8 min readdifficulty · medium3 backlinks

WHAT is a finite difference method?

Notation convention (memorise this): the subscript is space, the superscript is time. uinu(xi,tn),xi=a+ih,tn=nk.u_i^n \approx u(x_i,\,t_n), \qquad x_i = a + i\,h,\qquad t_n = n\,k.


HOW do we turn a derivative into a difference? (Derivation from scratch)

Everything comes from Taylor's theorem. Expand uu about xix_i, stepping by ±h\pm h:

u(x_i+h) = u_i + h\,u_i' + \tfrac{h^2}{2}u_i'' + \tfrac{h^3}{6}u_i''' + O(h^4)\tag{A} u(x_i-h) = u_i - h\,u_i' + \tfrac{h^2}{2}u_i'' - \tfrac{h^3}{6}u_i''' + O(h^4)\tag{B}

First derivative — three flavours

Forward difference. From (A), solve for uiu_i': ui=ui+1uihh2ui    uiui+1uihu_i' = \frac{u_{i+1}-u_i}{h} - \frac{h}{2}u_i'' - \dots \;\Rightarrow\; \boxed{u_i' \approx \frac{u_{i+1}-u_i}{h}} Why this step? We isolate uiu_i' and drop everything multiplied by hh or higher; the first dropped term is O(h)O(h), so this is first-order accurate, error h\sim h.

Backward difference. From (B):   uiuiui1h\;u_i' \approx \dfrac{u_i - u_{i-1}}{h}, also O(h)O(h).

Central difference. Subtract (B) from (A). The even-power (uiu_i'') terms cancel: u(xi+h)u(xih)=2hui+h33ui+u(x_i+h)-u(x_i-h) = 2h\,u_i' + \tfrac{h^3}{3}u_i''' + \dots uiui+1ui12h,error O(h2).\Rightarrow \boxed{u_i' \approx \frac{u_{i+1}-u_{i-1}}{2h}},\qquad \text{error } O(h^2). Why this step? Cancelling the uu'' term is why central is one order more accurate for the same grid — a free upgrade.

Second derivative

Add (A) and (B). The odd-power (uu', uu''') terms cancel: u(xi+h)+u(xih)=2ui+h2ui+h412ui+u(x_i+h)+u(x_i-h) = 2u_i + h^2 u_i'' + \tfrac{h^4}{12}u_i'''' + \dots Solve for uiu_i'': uiui+12ui+ui1h2,error O(h2).\boxed{u_i'' \approx \frac{u_{i+1} - 2u_i + u_{i-1}}{h^2}},\qquad \text{error } O(h^2).

Figure — Intro to finite difference methods for PDEs

WHY does this work? (The numbers behind accuracy)


Worked Example 1 — Heat equation (explicit FTCS scheme)

Solve the heat equation ut=αuxxu_t = \alpha\,u_{xx}.

Step 1 — Forward in time at node (i,n)(i,n): utuin+1uink.u_t \approx \frac{u_i^{n+1}-u_i^n}{k}. Why? Forward in time means the new value uin+1u_i^{n+1} appears alone — we can solve for it explicitly without inverting a matrix.

Step 2 — Central in space: uxxui+1n2uin+ui1nh2.u_{xx}\approx \frac{u_{i+1}^n - 2u_i^n + u_{i-1}^n}{h^2}. Why? Best accuracy (O(h2)O(h^2)) at no extra cost.

Step 3 — Substitute into the PDE and rearrange: uin+1uink=αui+1n2uin+ui1nh2\frac{u_i^{n+1}-u_i^n}{k} = \alpha\,\frac{u_{i+1}^n - 2u_i^n + u_{i-1}^n}{h^2} uin+1=uin+r(ui+1n2uin+ui1n),r=αkh2.\boxed{u_i^{n+1} = u_i^n + r\big(u_{i+1}^n - 2u_i^n + u_{i-1}^n\big)},\qquad r = \frac{\alpha k}{h^2}. Why this step? Everything on the right is at the known time level nn, so we march forward in time, one row at a time. This is FTCS (Forward-Time Central-Space) and it is explicit.


Worked Example 2 — One Poisson step (boundary value problem)

Solve u=f(x)u'' = f(x) on [0,1][0,1] with u(0)=u(1)=0u(0)=u(1)=0, using h=0.25h=0.25 (so interior nodes x1,x2,x3x_1,x_2,x_3), f2f\equiv -2.

Step 1 — Discretise: ui+12ui+ui1h2=fi\dfrac{u_{i+1}-2u_i+u_{i-1}}{h^2} = f_i. Why? Replace the only derivative present by the central second-difference.

Step 2 — Write equations for each interior node (u0=u4=0u_0=u_4=0, h2=0.0625h^2=0.0625, fih2=0.125f_i h^2 = -0.125): 2u1+u2=0.125,u12u2+u3=0.125,u22u3=0.125.-2u_1 + u_2 = -0.125,\quad u_1 - 2u_2 + u_3 = -0.125,\quad u_2 - 2u_3 = -0.125. Why this step? The boundary values are known constants, so they move to the right-hand side. We get a small linear system Au=bA\mathbf{u}=\mathbf{b} with the tridiagonal matrix A=(210121012).A=\begin{pmatrix}-2&1&0\\1&-2&1\\0&1&-2\end{pmatrix}.

Step 3 — Solve. By symmetry u1=u3u_1=u_3. From eq.1: u2=2u10.125u_2 = 2u_1 - 0.125. Sub into eq.2: u12(2u10.125)+u1=0.1252u1+0.25=0.125u1=0.1875u_1 - 2(2u_1-0.125)+u_1 = -0.125 \Rightarrow -2u_1 +0.25 = -0.125 \Rightarrow u_1 = 0.1875. Then u2=0.25u_2 = 0.25. Check: exact solution of u=2, u(0)=u(1)=0u''=-2,\ u(0)=u(1)=0 is u=x(1x)u=x(1-x); at x=0.25,0.5x=0.25,0.5 it gives 0.1875,0.250.1875, 0.25exact, because the true solution is a quadratic and the central scheme is exact for cubics.


Recall Feynman: explain it to a 12-year-old

Imagine a curve drawn on graph paper. You only mark dots where the grid lines cross. To guess how steep the curve is at a dot, you look at the dot just left and just right and ask "how much did the height change between them?" — that's a slope-from-neighbours. To guess how much it bends, you compare the middle dot to the average of its two neighbours. The whole "finite difference" idea is just: don't measure slopes and bends exactly — estimate them from nearby dots. The closer the dots (smaller hh), the better the guess. The danger: if you step forward in time too greedily, your guesses pile up errors and the picture explodes.


Flashcards

What replaces a derivative in a finite difference method?
A difference quotient of neighbouring grid values, derived from Taylor expansion.
In uinu_i^n, which index is space and which is time?
Subscript ii = space (xix_i), superscript nn = time (tnt_n).
Central difference for uxu_x and its order?
ui+1ui12h\dfrac{u_{i+1}-u_{i-1}}{2h}, order O(h2)O(h^2).
Forward difference for uxu_x and its order?
ui+1uih\dfrac{u_{i+1}-u_i}{h}, order O(h)O(h).
Central second-difference for uxxu_{xx}?
ui+12ui+ui1h2\dfrac{u_{i+1}-2u_i+u_{i-1}}{h^2}, order O(h2)O(h^2).
Why is central first-difference O(h2)O(h^2) but forward only O(h)O(h)?
Subtracting symmetric expansions cancels the uu'' term, removing the leading O(h)O(h) error.
FTCS update for ut=αuxxu_t=\alpha u_{xx}?
uin+1=uin+r(ui+1n2uin+ui1n)u_i^{n+1}=u_i^n+r(u_{i+1}^n-2u_i^n+u_{i-1}^n), r=αk/h2r=\alpha k/h^2.
Stability condition for explicit FTCS heat scheme?
r=αk/h212r=\alpha k/h^2 \le \tfrac12.
If you halve hh, how does an O(h2)O(h^2) error change?
Drops by a factor of about 4.
What kind of system does discretising u=fu''=f (BVP) produce?
A tridiagonal linear system Au=bA\mathbf{u}=\mathbf{b} with boundary values moved to the RHS.

Connections

  • Taylor's Theorem — the engine that generates every difference formula and its error order.
  • Heat Equation — primary parabolic test case (FTCS, implicit schemes).
  • Wave Equation — hyperbolic case; uses central-in-time, leads to CFL condition.
  • Laplace and Poisson Equations — elliptic BVPs giving tridiagonal/banded systems.
  • Von Neumann Stability Analysiswhy the r12r\le\tfrac12 rule exists.
  • Tridiagonal Matrix Algorithm (Thomas) — fast solver for the linear systems FDM produces.

Concept Map

cannot store infinite points

spacings h and k

subscript space superscript time

expand about x_i

isolate u prime

isolate u prime

subtract, u'' cancels

add, u' cancels

replace derivatives

replace derivatives

replace derivatives

derivatives become differences

computer solves

PDE with u x,t

Grid / mesh

Nodal values u i n

Index notation

Taylor theorem

Step by plus/minus h

Forward diff O h

Backward diff O h

Central diff O h squared

Second deriv O h squared

Algebraic system

Approximate solution

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, computer ke paas infinite memory nahi hai, toh woh poore continuous function u(x,t)u(x,t) ko store nahi kar sakta. Isliye hum domain ko ek grid mein chop kar dete hain — sirf grid points pe values rakhte hain: uinu_i^n, jahan subscript ii space hai aur superscript nn time hai. Ab PDE mein jo derivatives hain, unko hum Taylor expansion se banaye gaye "difference quotients" se replace kar dete hain. Bas yahi pura khel hai — derivative ko nearby points ke difference se approximate karna.

Taylor se teen cheezein nikalti hain jo ratta maar lo: forward difference ui+1uih\frac{u_{i+1}-u_i}{h} (accuracy O(h)O(h)), central difference ui+1ui12h\frac{u_{i+1}-u_{i-1}}{2h} (accuracy O(h2)O(h^2), kyunki symmetric subtract karne se uu'' term cancel ho jaata hai — yeh free upgrade hai), aur second derivative ui+12ui+ui1h2\frac{u_{i+1}-2u_i+u_{i-1}}{h^2}. O(h2)O(h^2) ka matlab: hh aadha karo toh error ek-chauthai ho jaata hai — bahut powerful.

Heat equation ut=αuxxu_t=\alpha u_{xx} ke liye FTCS scheme banega: uin+1=uin+r(ui+1n2uin+ui1n)u_i^{n+1}=u_i^n+r(u_{i+1}^n-2u_i^n+u_{i-1}^n), jahan r=αk/h2r=\alpha k/h^2. Isme right side sab known time level pe hai, toh aage march karte jao. Lekin ek trap hai: yeh tabhi stable hai jab r12r\le \tfrac12. Agar hh chhota karoge toh kk ko h2h^2 ki tarah aur chhota karna padega, warna solution oscillate karke explode ho jaayega.

Aur jab BVP type problem ho jaise u=fu''=f, toh discretise karne par ek tridiagonal linear system Au=bA\mathbf{u}=\mathbf{b} ban jaata hai — boundary values known hain isliye unhe right side bhej do, aur solve kar lo. Yaad rakho: FDM = grid banao, derivatives ko differences banao, algebra solve karo, aur stability check karna mat bhoolo.

Test yourself — Partial Differential Equations

Connections