4.8.22Numerical Methods

ODE solvers — Euler's method (derivation, global error)

1,816 words8 min readdifficulty · medium

We want to solve an Initial Value Problem (IVP): dydx=f(x,y),y(x0)=y0\frac{dy}{dx} = f(x,y), \qquad y(x_0) = y_0

The function ff tells us the slope of the solution curve at any point (x,y)(x,y). The catch: we don't have a formula for y(x)y(x) — only its slope. Euler's method turns "I know the slope everywhere" into "I can sketch the curve numerically."


WHY — the problem we're attacking

WHY can't we just integrate? Because ff depends on yy itself, which we don't know yet. We need a stepwise, self-bootstrapping method: use what we have now to estimate the next point.


HOW — deriving the method from first principles

We derive it two ways so it sticks.

Derivation 1: Taylor series (the rigorous route)

Expand the true solution y(x)y(x) around xnx_n for a step hh: y(xn+h)=y(xn)+hy(xn)+h22y(ξ)y(x_n + h) = y(x_n) + h\,y'(x_n) + \frac{h^2}{2}y''(\xi)

  • Why this step? Taylor's theorem is exact with the last term evaluated at some ξ(xn,xn+h)\xi\in(x_n, x_n+h). It tells us precisely what we throw away.

Now substitute y(xn)=f(xn,yn)y'(x_n) = f(x_n, y_n) (that's what the ODE gives us) and drop the h2h^2 term: yn+1=yn+hf(xn,yn)\boxed{y_{n+1} = y_n + h\,f(x_n, y_n)}

Derivation 2: Tangent line / finite difference (the intuitive route)

Approximate the derivative by a forward difference: y(xn)yn+1ynhy'(x_n) \approx \frac{y_{n+1} - y_n}{h}

  • Why this step? It's the definition of derivative before taking the limit h0h\to 0. We keep hh finite because a computer can't take limits.

Set this equal to f(xn,yn)f(x_n,y_n) and solve for yn+1y_{n+1} — you get the same boxed formula.

Figure — ODE solvers — Euler's method (derivation, global error)

Local vs Global error — the heart of "why Euler is only first order"

WHY global error is O(h)O(h), not O(h2)O(h^2)

Here is the steel-manned reasoning (don't skip — this is the 20% that earns 80% of the marks):

  • Each step adds an error of size h22y\sim \frac{h^2}{2}|y''|.
  • To reach x=bx=b we take N=bx0hN = \dfrac{b-x_0}{h} steps — so NN grows as hh shrinks.
  • Naïve total: N×O(h2)=bx0hO(h2)=O(h)N \times O(h^2) = \dfrac{b-x_0}{h}\cdot O(h^2) = O(h).

So one power of hh is lost because more steps are needed for smaller hh.

Why the eL(xnx0)e^{L(x_n-x_0)} factor? Errors don't just add — earlier errors get amplified as they propagate through ff. The Lipschitz constant LL measures how fast nearby solutions diverge; the exponential is the worst-case growth.


Worked Examples


Common Mistakes (steel-manned)


Recall Explain it to a 12-year-old (Feynman)

Imagine walking in fog and you can only see which direction the path points right where you stand. You can't see the whole path. So you face that direction, take one small step, look again at the new direction, take another small step. Each step you're slightly off because the path curved while you walked straight — but small steps keep you close. Taking smaller steps keeps you closer to the real path, but you need many more steps to finish.


Flashcards

What IVP does Euler's method solve?
y=f(x,y), y(x0)=y0y'=f(x,y),\ y(x_0)=y_0 — an ODE with a known starting value.
State the Euler update formula.
yn+1=yn+hf(xn,yn)y_{n+1} = y_n + h\,f(x_n,y_n), with xn+1=xn+hx_{n+1}=x_n+h.
Derive Euler from Taylor series.
y(xn+h)=yn+hy(xn)+h22y(ξ)y(x_n+h)=y_n+hy'(x_n)+\frac{h^2}{2}y''(\xi); substitute y=fy'=f, drop O(h2)O(h^2) term.
What is the local truncation error of Euler?
h22y(ξ)=O(h2)\frac{h^2}{2}y''(\xi) = O(h^2) — error of a single step.
What is the global error order and why?
O(h)O(h)N=(bx0)/hN=(b-x_0)/h steps each O(h2)O(h^2), so NO(h2)=O(h)N\cdot O(h^2)=O(h); one power lost.
If you halve hh, what happens to the global error?
It roughly halves (first-order method).
Why does the error bound contain eL(xx0)e^{L(x-x_0)}?
Earlier errors get amplified as they propagate; LL (Lipschitz constant) bounds the worst-case exponential growth.
Forward vs Backward Euler?
Forward uses slope at current point f(xn,yn)f(x_n,y_n) (explicit); Backward uses f(xn+1,yn+1)f(x_{n+1},y_{n+1}) (implicit, solve for yn+1y_{n+1}).
Geometric interpretation of Euler?
Follow the tangent line at the current point for horizontal distance hh.

Connections

  • Taylor Series Expansion — the engine behind the derivation & error analysis
  • Runge-Kutta Methods — higher-order successors (RK4 is O(h4)O(h^4) global)
  • Backward Euler & Implicit Methods — for stiff equations
  • Numerical Stability — why Example 3 blew up
  • Lipschitz Continuity — guarantees the error bound exists
  • Finite Difference Approximations — forward difference = Euler's derivation route

Concept Map

no closed form

self-bootstrapping

drop h^2 term

solve for y_n+1

same as

remainder term

one step error

accumulate over N steps

N ~ 1 over h

first order

IVP: y' = f x,y with y x0 = y0

Need stepwise method

Euler update y_n+1 = y_n + h f

Taylor expansion of y x_n+h

Forward difference of y'

Tangent line geometry

Local truncation error O h^2

Global error O h

N = b - x0 over h steps

Euler is first-order accurate

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, Euler's method ka idea bahut simple hai. Tumhare paas ek differential equation hai y=f(x,y)y'=f(x,y) jo batati hai ki kisi bhi point par curve ka slope kya hai, aur ek starting point y(x0)=y0y(x_0)=y_0 pata hai. Lekin poori curve ka formula nahi pata. Toh hum kya karte hain — current point par jo slope hai, us direction me ek chhota step hh lete hain. Formula bana: yn+1=yn+hf(xn,yn)y_{n+1} = y_n + h\cdot f(x_n,y_n) — yaani "naya = purana + step × slope". Bas yahi baar baar repeat karo.

Ye formula nikalta kaise hai? Taylor series se. y(xn+h)=yn+hy(xn)+h22y(ξ)y(x_n+h) = y_n + h\,y'(x_n) + \frac{h^2}{2}y''(\xi). Hum yy' ki jagah ff daal dete hain aur h2h^2 wala term fenk dete hain. Wahi fenka hua term hamari ek-step ki galti hai, jise local truncation error kehte hain, aur wo O(h2)O(h^2) hai.

Ab sabse important baat — exam me yahi puchha jaata hai. Local error h2h^2 hai, lekin global error (poore raaste ka total error) sirf O(h)O(h) hota hai. Kyun? Kyunki endpoint tak pahunchne ke liye N=(bx0)/hN=(b-x_0)/h steps lagte hain. Jaise jaise hh chhota karte ho, steps zyada hote jaate hain. Toh N×O(h2)=O(h)N \times O(h^2) = O(h) — ek power hh ki kam ho gayi. Iska matlab: Euler first order method hai, hh ko aadha karoge toh error bhi roughly aadha hoga.

Practical baat: chhota hh accha hai par bahut chhota karoge toh round-off error aur time barbaad. Aur agar equation "stiff" hai (jaise y=2yy'=-2y bade hh ke saath), toh answer phat jaata hai — wahan stability ka concept aata hai. Isiliye aage Runge-Kutta jaise behtar methods padhte hain.

Go deeper — visual, from zero

Test yourself — Numerical Methods

Connections