4.8.23Numerical Methods

Modified Euler (Heun's method)

1,632 words7 min readdifficulty · medium1 backlinks

Solving dydx=f(x,y)\dfrac{dy}{dx}=f(x,y), y(x0)=y0y(x_0)=y_0 — but smarter than plain Euler.

The Big Picture


Deriving It From Scratch

Step 1 — Exact statement. Integrate the ODE over one step: y(x1)y(x0)=x0x1f(x,y)dxy(x_1) - y(x_0) = \int_{x_0}^{x_1} f(x,y)\,dx

Why this step? It's exact (Fundamental Theorem of Calculus). The whole game in numerical methods is how we approximate this integral.

Step 2 — Choose the integration rule. Plain Euler uses the left-rectangle rule: hf(x0,y0)\int \approx h\,f(x_0,y_0). That's crude. Instead use the trapezoidal rule: x0x1f(x,y)dx    h2[f(x0,y0)+f(x1,y1)]\int_{x_0}^{x_1} f(x,y)\,dx \;\approx\; \frac{h}{2}\Big[f(x_0,y_0) + f(x_1, y_1)\Big]

Why this step? The trapezoid averages the height at both ends → it matches the straight-line average of slopes, the exact thing our intuition demanded.

Step 3 — The catch. We need f(x1,y1)f(x_1,y_1) but we don't know y1y_1 yet — that's what we're solving for! So we predict it with one cheap Euler step.


Why It's More Accurate (Order of the method)

Quick Taylor check: the true value is y(x1)=y0+hy+h22y+h36y+y(x_1)=y_0 + hy' + \tfrac{h^2}{2}y'' + \tfrac{h^3}{6}y''' + \dots Heun's average-slope formula reproduces the hh and h2h^2 terms exactly (that's why it's order 2); it first disagrees at the h3h^3 term.

Figure — Modified Euler (Heun's method)

Worked Examples


Common Mistakes


Recall Feynman: explain to a 12-year-old

You're hiking and want to know where you'll be after one step. Plain Euler points your feet in the direction the trail goes right now and walks — but trails curve, so you drift off. Heun's trick: take a practice step to peek where the trail points at the end, then walk using the average of the start-direction and end-direction. Looking ahead before committing makes you land much closer to the real path.


Active Recall

What integration rule underlies Heun's method?
The trapezoidal rule applied to x0x1fdx\int_{x_0}^{x_1} f\,dx.
Write the predictor of Heun's method.
y1(p)=y0+hf(x0,y0)y_1^{(p)} = y_0 + h\,f(x_0,y_0) (a plain Euler step).
Write the corrector of Heun's method.
y1=y0+h2[f(x0,y0)+f(x1,y1(p))]y_1 = y_0 + \frac{h}{2}[\,f(x_0,y_0)+f(x_1,y_1^{(p)})\,].
Why do we need a predictor at all?
The trapezoid needs f(x1,y1)f(x_1,y_1) but y1y_1 is unknown, so we predict it with cheap Euler.
What is the global error order of Heun's method?
O(h2)O(h^2) — second order; halving hh cuts error ~4×.
What is the global error order of plain Euler?
O(h)O(h) — first order.
Heun's method is equivalent to which Runge–Kutta method?
RK2 (2-stage Runge–Kutta with equal weights).
In k2=f(x0+h,y0+hk1)k_2 = f(x_0+h, y_0+hk_1), why use y0+hk1y_0+hk_1 not y0y_0?
Because the end-slope must be evaluated at the predicted end-value of yy, not the start value.
For y=x+y,y(0)=1,h=0.1y'=x+y,\,y(0)=1,h=0.1, give y(0.1)y(0.1) by Heun.
1.111.11 (with k1=1,k2=1.2k_1=1,k_2=1.2).
What does iterating the corrector achieve?
It better solves the implicit trapezoidal equation, improving accuracy further.

Connections

  • Euler's Method — the predictor step is exactly plain Euler.
  • Trapezoidal Rule — the corrector is this integration rule in disguise.
  • Runge-Kutta Methods — Heun = RK2; RK4 is the famous higher-order cousin.
  • Order of Accuracy and Step Size — why O(h2)O(h^2) beats O(h)O(h).
  • Predictor-Corrector Methods — Heun is the simplest example.
  • Taylor Series Methods — used to prove Heun is second order.

Concept Map

integrate over step

approximate integral

left rectangle

trapezoidal rule

overshoots undershoots

needs unknown y1

cheap guess

predictor plus corrector

average of k1 and k2

matches h and h squared terms

halving h

ODE y'=f x,y

Exact integral form

Choose integration rule

Plain Euler start slope only

Average both end slopes

Systematic error

Predictor fixes it

Heun's method

2-stage Runge-Kutta RK2

Second order global error h squared

Cuts error 4x

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, normal Euler method ka problem ye hai ki wo sirf shuru wale point ka slope use karke aage chala jaata hai. Lekin curve toh aage badhte hue mudta rehta hai, isliye Euler hamesha thoda over ya under shoot kar deta hai. Heun's method (Modified Euler) bolta hai — "itni jaldi mat karo, pehle aage jhaank ke dekho."

Trick simple hai: pehle ek predictor step lo (yeh bilkul plain Euler hai) — isse ek guess milta hai ki end pe yy kya hoga. Us guessed point pe slope nikaalo. Ab tumhare paas do slope hain — ek shuru ka (k1k_1) aur ek end ka (k2k_2). In dono ka average lo, aur usse asli step maaro: y1=y0+h2(k1+k2)y_1 = y_0 + \frac{h}{2}(k_1+k_2). Yeh average wala kaam hi trapezoidal rule hai integration ka, isliye accuracy badhti hai.

Kyun important hai? Kyunki Heun second order hai (O(h2)O(h^2)) jabki Euler sirf first order (O(h)O(h)). Matlab agar tum step size hh aadha karo, toh Euler ki galti aadhi hoti hai par Heun ki galti chaar guna kam ho jaati hai. Itna fayda sirf ek extra ff evaluation se! Yaad rakhne ka formula: P-A-C — Predict, Average, Correct. Bas h2\frac{h}{2} wala factor mat bhoolna, warna double step pad jaayega.

Go deeper — visual, from zero

Test yourself — Numerical Methods

Connections