Differential equations tell us how a quantity changes, not what it is. Stepping y′=f(x,y) forward: the Taylor series and Picard methods, Euler's method, the modified Euler (Heun) method, and the difference between local and global error.
Md Mahbub E Noor · Assistant Professor CSE-3107 Numerical Methods · B.Sc. 3rd Year 1st Semester Department of CSE, University of Barishal
Why this lecture
The problem: a law of change, not a formula
Newton's law of cooling: the temperature T (°C) of tea in a 25 °C room changes at a rate proportional to the difference.
dtdT=−0.1(T−25) per minute, with T(0)=90
We know the rate at every moment, not the temperature itself
This one can be solved by hand; most real models (epidemics, circuits, orbits, neural ODEs) cannot
Idea: start from the known value and take small steps, using the rate to predict each next value
t (min)
T (°C)
rate dT/dt
0
90
−6.5
1
?
?
2
?
?
…
…
…
10
?
Md Mahbub E Noor
Lecture 21: ODEs I: Taylor, Picard, Euler, Heun
University of Barishal
2 / 25
Today's goals
State an initial value problem and read its slope field
Solve by the Taylor series method and by Picard's successive approximations
Apply Euler's method and the modified Euler (Heun) method by hand and in code
Distinguish local and global error; predict how the error changes with h
Recognise when a step size is too large (instability)
Last time
Integration rules: rectangle, trapezoid, Simpson.
Today
Integrate an equation whose integrand depends on the unknown: y(x+h)=y(x)+∫f(t,y(t))dt.
A differential equation gives the slope y′ at every point, not y itself.We know one point: the starting value.Compute the slope there and walk along it for one step h.At the new point compute the slope again and take another step.Repeat: a chain of short straight pieces.Each piece leaves the true curve a little …… and the errors pile up. Smaller steps (or a smarter method) reduce the gap.
In plain words
An ODE tells us the slope of the unknown curve at every point
Start at the known point and walk a short step in that direction
Repeat. Shorter steps follow the true curve better
New words today
ODE
an equation containing y′, the rate of change of y
initial value
the known starting point y(x₀) = y₀
step size h
how far we move each time
Euler's method
new y = old y + h × slope
Md Mahbub E Noor
Lecture 21: ODEs I: Taylor, Picard, Euler, Heun
University of Barishal
4 / 25
Initial value problems and slope fields
First-order initial value problemdxdy=f(x,y),y(x0)=y0
Integrated form: every method approximates this integraly(xn+1)=y(xn)+∫xnxn+1f(t,y(t))dt
f(x,y) is the slope of the solution through the point (x,y)
Drawing short slope segments everywhere gives the slope field; solutions follow it
One initial value picks one solution curve
Unique solution if f is smooth (Lipschitz in y) near (x0,y0)
Md Mahbub E Noor
Lecture 21: ODEs I: Taylor, Picard, Euler, Heun
University of Barishal
5 / 25
The Taylor series method
Expand the solution about x₀ (Lecture 3)y(x0+h)=y0+hy0′+2!h2y0′′+3!h3y0′′′+4!h4y0(4)+⋯
Get the derivatives by differentiating the ODE itself. For y′ = x + y:y′=x+y,y′′=1+y′,y′′′=y′′,y(4)=y′′′
Accurate, but each new ODE needs its own derivative formulas, which quickly become messy
Md Mahbub E Noor
Lecture 21: ODEs I: Taylor, Picard, Euler, Heun
University of Barishal
6 / 25
Picard's method of successive approximations
Iterate on the integral equation (a fixed-point iteration for functions, Lecture 8)y(k+1)(x)=y0+∫x0xf(t,y(k)(t))dt,y(0)(x)=y0
For y′ = x + y, y(0) = 1y(1)y(2)y(3)=1+x+2x2=1+x+x2+6x3=1+x+x2+3x3+24x4
At x=0.1: 1.105, 1.110167, 1.110337 → exact 1.110342
Each iteration adds one correct power of x
Needs the integrals in closed form: only for simple f
Its real value is theoretical: it proves that solutions exist
Md Mahbub E Noor
Lecture 21: ODEs I: Taylor, Picard, Euler, Heun
University of Barishal
7 / 25
Euler's method
Follow the slope at the current point for one stepyn+1=yn+hf(xn,yn),xn+1=xn+h
Error per step (local) and after reaching a fixed x (global)local: 2h2y′′(ξ)=O(h2),global: O(h)
= first two Taylor terms; = left-rectangle rule for the integral
One evaluation of f per step
1/h steps, each with an O(h2) error, add up to O(h)
Halve h: the error at the end halves (and the work doubles)
Md Mahbub E Noor
Lecture 21: ODEs I: Taylor, Picard, Euler, Heun
University of Barishal
8 / 25
The method, step by step
Euler's method, step by step
Write the problem as y′=f(x,y), y(x0)=y0; choose h
Evaluate the slope f(xn,yn) at the current point
Step: yn+1=yn+hf(xn,yn), xn+1=xn+h
Repeat until x reaches the target
Check: repeat with h/2; the change estimates the error
Pseudocode
input f, x0, y0, h, x_end
x ← x0; y ← y0
while x < x_end − h/2:
y ← y + h·f(x, y)
x ← x + h
print x, y
return y
The loop condition avoids an extra step caused by rounding in x+h.
Md Mahbub E Noor
Lecture 21: ODEs I: Taylor, Picard, Euler, Heun
University of Barishal
9 / 25
Explore: stepping along the slope field
Grey dashes: the slope field f(x,y)
Red: Euler's polygon; dashed: the exact solution
Press h÷2 and watch the final error halve
Tick Heun and RK4 to preview the better methods
Md Mahbub E Noor
Lecture 21: ODEs I: Taylor, Picard, Euler, Heun
University of Barishal
10 / 25
Problem 1: Euler's method for y′=x+y, y(0)=1
Use Euler's method with h=0.1 to find y(0.4). Compare with the exact solution y=2ex−x−1.
n
xn
yn
f(xn,yn)=xn+yn
yn+1=yn+0.1f
exact y(xn+1)
error
0
0.0
1.0000
1.0000
1.1000
1.110342
0.0103
1
0.1
1.1000
1.2000
1.2200
1.242806
0.0228
2
0.2
1.2200
1.4200
1.3620
1.399718
0.0377
3
0.3
1.3620
1.6620
1.5282
1.583649
0.0554
y(0.4)≈1.5282; the error grows step by step because each step starts from a point that is already wrong.
Md Mahbub E Noor
Lecture 21: ODEs I: Taylor, Picard, Euler, Heun
University of Barishal
11 / 25
Modified Euler (Heun): predict, then correct with the average slope
Predictor (Euler) and corrector (trapezoidal rule)yn+1∗yn+1=yn+hf(xn,yn)=yn+2h[f(xn,yn)+f(xn+1,yn+1∗)]
Errorlocal O(h3),global O(h2)
Slope at the start and an estimated slope at the end, averaged
Two evaluations of f per step; second order: halve h, error ÷4
Some textbooks repeat the corrector until it settles (iterated modified Euler)
It is the trapezoidal rule of Lecture 20 with a predicted end value
Md Mahbub E Noor
Lecture 21: ODEs I: Taylor, Picard, Euler, Heun
University of Barishal
12 / 25
The method, step by step
Modified Euler (Heun), step by step
Slope at the start: k1=f(xn,yn)
Predict with Euler: y∗=yn+hk1
Slope at the predicted end point: k2=f(xn+h,y∗)
Correct: yn+1=yn+2h(k1+k2)
(Optional) recompute k2 with the corrected value and repeat step 4 until two values agree
Pseudocode
input f, x0, y0, h, x_end
x ← x0; y ← y0
while x < x_end − h/2:
k1 ← f(x, y)
yp ← y + h·k1 # predictor
k2 ← f(x + h, yp)
y ← y + h/2·(k1 + k2) # corrector
x ← x + h
return y
Twice the work of Euler per step, but far fewer steps for the same accuracy.
Md Mahbub E Noor
Lecture 21: ODEs I: Taylor, Picard, Euler, Heun
University of Barishal
13 / 25
Problem 2: modified Euler for y′=x+y, y(0)=1
Find y(0.1) and y(0.2) with h=0.1. Then iterate the corrector in the first step.
Iterated corrector in step 1: 1.11→1+0.05(1+0.1+1.11)=1.1105→1.110525→1.110526
y(0.2)≈1.24205 (exact 1.242806, error 7.6×10−4; Euler's error was 2.3×10−2).
Md Mahbub E Noor
Lecture 21: ODEs I: Taylor, Picard, Euler, Heun
University of Barishal
14 / 25
Local and global error: what halving h does
h
Euler y(1)
error
Heun y(1)
error
RK4 (Lecture 22)
error
0.2
2.976640
0.460
3.405416
3.1×10−2
3.43650227
6.1×10−5
0.1
3.187485
0.249
3.428162
8.4×10−3
3.43655949
4.2×10−6
0.05
3.306595
0.130
3.434382
2.2×10−3
3.43656339
2.7×10−7
0.025
3.370128
0.066
3.436008
5.6×10−4
3.43656364
1.7×10−8
y′=x+y, y(0)=1, exact y(1)=3.436564. Halving h divides the global error by 2 (Euler, order 1), 4 (Heun, order 2) and 16 (RK4, order 4).
Md Mahbub E Noor
Lecture 21: ODEs I: Taylor, Picard, Euler, Heun
University of Barishal
15 / 25
Classical vs numerical
Same kind of problem, two approaches
Calculus
Classical (solve exactly)
y′=x+y: linear, integrating factor e−x
(ye−x)′=xe−x, so y=2ex−x−1
y(1)=3.436564, exactly
vs
Algorithm
Numerical (Heun, h=0.1)
10 steps, 20 evaluations of f
y(1)=3.428162 (error 0.008)
Same code for any f(x,y)
When the classical approach cannot work
y′=x2+y2, y(0)=0 (a Riccati equation)
No elementary formula exists (the solution involves Bessel functions). Numerically: Euler (h=0.1) 0.2925, Heun 0.3518, RK4 0.350234; very accurate value y(1)=0.350232. Most models in science and engineering are like this.
Md Mahbub E Noor
Lecture 21: ODEs I: Taylor, Picard, Euler, Heun
University of Barishal
16 / 25
Euler and modified Euler in Python and C
Both methods for y′=x+y, h=0.1
Prints each step with the exact value
Change f for any other equation
Lab: the tea-cooling model
Md Mahbub E Noor
Lecture 21: ODEs I: Taylor, Picard, Euler, Heun
University of Barishal
17 / 25
When Euler goes wrong
Limitations shown failing
y′=−20y: the true solution decays to 0 almost at once
Euler multiplies y by (1−20h) each step: h=0.12 gives −1.4, so the numbers explode
Stability needs ∣1+hλ∣<1, i.e. h<0.1 here, whatever the accuracy
First order is slow: halving the error doubles the work
Md Mahbub E Noor
Lecture 21: ODEs I: Taylor, Picard, Euler, Heun
University of Barishal
18 / 25
Practice
Practice problem
Problem 3"Given dxdy=y−x, y(0)=2, find y(0.2) by Euler's method with h=0.1, then improve the result with the modified Euler method. Compare with the exact solution y=ex+x+1."
Click a card to see an ODE being stepped in a real system.
🧠 ResNets are Euler steps
Where exactly: deep learning. A residual network block computes xk+1=xk+F(xk,θk): exactly Euler's method with h=1 for the ODE dx/dt=F(x,θ(t)). "Neural ODEs" (2018) replace the stack of layers by an ODE solver.
Layer k: input xk, learned function F (convolutions + activation)
Output xk+F(xk): the skip connection is the "yn+" of Euler
Many thin layers ≈ small steps; stability of the forward pass ≈ stability of Euler
Neural ODEs use adaptive Runge–Kutta solvers and fewer parameters
This view explains why very deep ResNets train well: each block makes only a small change, like a small Euler step.
🎮 Game physics
Where exactly: game engines. Each frame (h=1/60 s) the engine updates velocity from forces and position from velocity: Euler's method for Newton's second law.
vn+1=vn+hmFn,xn+1=xn+hvn+1
Using the new velocity for the position ("semi-implicit Euler") keeps orbits and springs from gaining energy
Cheap: one force evaluation per object per frame
Stiff springs or very fast objects need smaller sub-steps, or they explode: the instability on the limitations slide
Accuracy matters less than stability and speed
Physics engines such as Box2D use semi-implicit Euler for exactly these reasons.
🔌 Charging a capacitor (RC circuit)
Where exactly: circuit simulation. A capacitor charging through a resistor from a 5 V source obeys V′=(5−V)/(RC); with RC=1 ms and time in ms: V′=5−V, V(0)=0.
With h=0.5 ms Euler runs ahead of the exact curve (2.5 V instead of 1.97 V after the first step); Heun (1.88 V) stays close. SPICE uses implicit trapezoidal steps, the stable relative of Heun.
🕵️ Forensics: time of death
Where exactly: forensic science. Body temperature cools roughly by Newton's law toward the room temperature; measuring the temperature and the cooling rate gives an estimate of the time since death.
Model: T′=−k(T−Troom), with k estimated from two measurements an hour apart
Step the ODE backwards (negative h) from the measured temperature until T reaches 37 °C
Real models (Henssge's nomogram) add body mass and clothing: no closed form, solved numerically
Uncertainty in k dominates the numerical error
A good example of the model error being much larger than the method error: no need for RK4 here.
Md Mahbub E Noor
Lecture 21: ODEs I: Taylor, Picard, Euler, Heun
University of Barishal
23 / 25
Checkpoint
Checkpoint · think, then discuss with your neighbourOne Euler step for y′=2y, y(0)=1, h=0.1. What is y1?
A1.2
B1.1
C1.2214
D0.2
A. y1=1+0.1×2(1)=1.2. The exact value is e0.2=1.2214 (option C); Heun gives 1+0.05(2+2.4)=1.22.
Md Mahbub E Noor
Lecture 21: ODEs I: Taylor, Picard, Euler, Heun
University of Barishal
24 / 25
Summary
Key points
IVP y′=f(x,y), y(x0)=y0; every method approximates ∫f(t,y(t))dt over each step
Taylor: expand and differentiate the ODE; Picard: y(k+1)=y0+∫f(t,y(k))dt
Euler yn+1=yn+hfn, global O(h); Heun: predictor + trapezoidal corrector, O(h2)
Too large h can make the solution explode: stability, not only accuracy
Opening problem: solved
Tea after 10 minutes: Euler (h=1) gives 47.66 °C, Heun 48.96 °C; the exact value is 48.91 °C. Heun's error is 30 times smaller for twice the work.
Homework
Solve y′=−2xy2, y(0)=1 to x=0.2 by Euler and by modified Euler (h=0.1). Compare with y=1/(1+x2).
Find the first three Picard approximations for y′=1+xy, y(0)=1.
Use the Taylor series method (4 terms) to find y(0.1) for y′=x2+y2, y(0)=1.
For y′=−50y, find the largest h for which Euler's method does not grow. Check it in the lab.
Next lecture
ODEs II: Runge–Kutta and predictor–corrector methods. Fourth-order accuracy, multistep methods, stability, stiff equations and systems.
Md Mahbub E Noor
Lecture 21: ODEs I: Taylor, Picard, Euler, Heun
University of Barishal
25 / 25
Keys →Space next step · ← back A reveal the whole slide number + Enter jump to slide S slide list · F full screen · N notes [] previous / next lecture · L lab In a code box: Ctrl+Enter runs the code