Ordinary differential equations · Lecture 21

ODEs I: Taylor, Picard and Euler Methods

Differential equations tell us how a quantity changes, not what it is. Stepping y′=f(x,y)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 TT (°C) of tea in a 25 °C room changes at a rate proportional to the difference.

  • dTdt=−0.1 (T−25)\dfrac{dT}{dt} = -0.1\,(T - 25) per minute, with T(0)=90T(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
tt (min)TT (°C)rate dT/dtdT/dt
090−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 hh
  • 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)) dty(x+h) = y(x) + \int f(t, y(t))\,dt.

Ordinary differential equations · you are here
L21 · ODEs I→L22 · ODEs II
Builds on: L3, L20
Md Mahbub E Noor
Lecture 21: ODEs I: Taylor, Picard, Euler, Heun
University of Barishal
3 / 25
Start here

The idea in one picture

xy0.511.52true solutionstarterroreach arrow: follow the slope y′for one step h
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 problemdydx=f(x,y),y(x0)=y0\frac{dy}{dx} = f(x, y), \qquad y(x_0) = y_0
Integrated form: every method approximates this integraly(xn+1)=y(xn)+∫xnxn+1f(t,y(t)) dty(x_{n+1}) = y(x_n) + \int_{x_n}^{x_{n+1}} f\big(t, y(t)\big)\,dt
  • f(x,y)f(x, y) is the slope of the solution through the point (x,y)(x, y)
  • Drawing short slope segments everywhere gives the slope field; solutions follow it
  • One initial value picks one solution curve
  • Unique solution if ff is smooth (Lipschitz in yy) near (x0,y0)(x_0, y_0)
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+h y0′+h22!y0′′+h33!y0′′′+h44!y0(4)+⋯y(x_0 + h) = y_0 + h\,y_0' + \frac{h^2}{2!}y_0'' + \frac{h^3}{3!}y_0''' + \frac{h^4}{4!}y_0^{(4)} + \cdots
Get the derivatives by differentiating the ODE itself. For y′ = x + y:y′=x+y,y′′=1+y′,y′′′=y′′,y(4)=y′′′y' = x + y, \quad y'' = 1 + y', \quad y''' = y'', \quad y^{(4)} = y'''
  • At (0,1)(0, 1): y′=1y' = 1, y′′=2y'' = 2, y′′′=2y''' = 2, y(4)=2y^{(4)} = 2
  • y(0.1)=1+0.1+0.012(2)+0.0016(2)+0.000124(2)=1.110342y(0.1) = 1 + 0.1 + \tfrac{0.01}{2}(2) + \tfrac{0.001}{6}(2) + \tfrac{0.0001}{24}(2) = 1.110342
  • Exact: 2e0.1−1.1=1.1103422e^{0.1} - 1.1 = 1.110342
  • 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)=y0y^{(k+1)}(x) = y_0 + \int_{x_0}^{x} f\big(t, y^{(k)}(t)\big)\,dt, \qquad y^{(0)}(x) = y_0
For y′ = x + y, y(0) = 1y(1)=1+x+x22y(2)=1+x+x2+x36y(3)=1+x+x2+x33+x424\begin{aligned} y^{(1)} &= 1 + x + \tfrac{x^2}{2} \\ y^{(2)} &= 1 + x + x^2 + \tfrac{x^3}{6} \\ y^{(3)} &= 1 + x + x^2 + \tfrac{x^3}{3} + \tfrac{x^4}{24} \end{aligned}
  • At x=0.1x = 0.1: 1.105, 1.110167, 1.110337 → exact 1.110342
  • Each iteration adds one correct power of xx
  • Needs the integrals in closed form: only for simple ff
  • 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+h f(xn,yn),xn+1=xn+hy_{n+1} = y_n + h\,f(x_n, y_n), \qquad x_{n+1} = x_n + h
Error per step (local) and after reaching a fixed x (global)local: h22y′′(ξ)=O(h2),global: O(h)\text{local: } \frac{h^2}{2}y''(\xi) = O(h^2), \qquad \text{global: } O(h)
  • = first two Taylor terms; = left-rectangle rule for the integral
  • One evaluation of ff per step
  • 1/h1/h steps, each with an O(h2)O(h^2) error, add up to O(h)O(h)
  • Halve hh: 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

  1. Write the problem as y′=f(x,y)y' = f(x, y), y(x0)=y0y(x_0) = y_0; choose hh
  2. Evaluate the slope f(xn,yn)f(x_n, y_n) at the current point
  3. Step: yn+1=yn+h f(xn,yn)y_{n+1} = y_n + h\,f(x_n, y_n),   xn+1=xn+h\;x_{n+1} = x_n + h
  4. Repeat until xx reaches the target
  5. Check: repeat with h/2h/2; the change estimates the error

The loop condition avoids an extra step caused by rounding in x+hx + 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)f(x, y)
  • Red: Euler's polygon; dashed: the exact solution
  • Press h÷2h \div 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+yy' = x + y, y(0)=1y(0) = 1

Use Euler's method with h=0.1h = 0.1 to find y(0.4)y(0.4). Compare with the exact solution y=2ex−x−1y = 2e^x - x - 1.
nnxnx_nyny_nf(xn,yn)=xn+ynf(x_n, y_n) = x_n + y_nyn+1=yn+0.1fy_{n+1} = y_n + 0.1fexact y(xn+1)y(x_{n+1})error
00.01.00001.00001.10001.1103420.0103
10.11.10001.20001.22001.2428060.0228
20.21.22001.42001.36201.3997180.0377
30.31.36201.66201.52821.5836490.0554

y(0.4)≈1.5282y(0.4) \approx 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+h f(xn,yn)yn+1=yn+h2[f(xn,yn)+f(xn+1,yn+1∗)]\begin{aligned} y^{*}_{n+1} &= y_n + h\,f(x_n, y_n) \\ y_{n+1} &= y_n + \frac h2\big[f(x_n, y_n) + f(x_{n+1}, y^{*}_{n+1})\big] \end{aligned}
Errorlocal O(h3),global O(h2)\text{local } O(h^3), \qquad \text{global } O(h^2)
  • Slope at the start and an estimated slope at the end, averaged
  • Two evaluations of ff per step; second order: halve hh, error ÷4\div 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

  1. Slope at the start: k1=f(xn,yn)k_1 = f(x_n, y_n)
  2. Predict with Euler: y∗=yn+h k1y^{*} = y_n + h\,k_1
  3. Slope at the predicted end point: k2=f(xn+h,y∗)k_2 = f(x_n + h, y^{*})
  4. Correct: yn+1=yn+h2(k1+k2)y_{n+1} = y_n + \dfrac h2(k_1 + k_2)
  5. (Optional) recompute k2k_2 with the corrected value and repeat step 4 until two values agree

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+yy' = x + y, y(0)=1y(0) = 1

Find y(0.1)y(0.1) and y(0.2)y(0.2) with h=0.1h = 0.1. Then iterate the corrector in the first step.
1
Step 1: k1=0+1=1k_1 = 0 + 1 = 1;   y∗=1+0.1(1)=1.1\;y^* = 1 + 0.1(1) = 1.1;   k2=0.1+1.1=1.2\;k_2 = 0.1 + 1.1 = 1.2;   y1=1+0.05(1+1.2)=1.11\;y_1 = 1 + 0.05(1 + 1.2) = 1.11
2
Step 2: k1=0.1+1.11=1.21k_1 = 0.1 + 1.11 = 1.21;   y∗=1.231\;y^* = 1.231;   k2=0.2+1.231=1.431\;k_2 = 0.2 + 1.231 = 1.431;   y2=1.11+0.05(2.641)=1.24205\;y_2 = 1.11 + 0.05(2.641) = 1.24205
3
Iterated corrector in step 1: 1.11→1+0.05(1+0.1+1.11)=1.1105→1.110525→1.1105261.11 \to 1 + 0.05(1 + 0.1 + 1.11) = 1.1105 \to 1.110525 \to 1.110526
y(0.2)≈1.24205y(0.2) \approx 1.24205 (exact 1.242806, error 7.6×10−47.6\times10^{-4}; Euler's error was 2.3×10−22.3\times10^{-2}).
Md Mahbub E Noor
Lecture 21: ODEs I: Taylor, Picard, Euler, Heun
University of Barishal
14 / 25

Local and global error: what halving hh does

hhEuler y(1)y(1)errorHeun y(1)y(1)errorRK4 (Lecture 22)error
0.22.9766400.4603.4054163.1×10−23.1\times10^{-2}3.436502276.1×10−56.1\times10^{-5}
0.13.1874850.2493.4281628.4×10−38.4\times10^{-3}3.436559494.2×10−64.2\times10^{-6}
0.053.3065950.1303.4343822.2×10−32.2\times10^{-3}3.436563392.7×10−72.7\times10^{-7}
0.0253.3701280.0663.4360085.6×10−45.6\times10^{-4}3.436563641.7×10−81.7\times10^{-8}

y′=x+yy' = x + y, y(0)=1y(0) = 1, exact y(1)=3.436564y(1) = 3.436564. Halving hh 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+yy' = x + y: linear, integrating factor e−xe^{-x}
  • (ye−x)′=xe−x(ye^{-x})' = xe^{-x}, so y=2ex−x−1y = 2e^x - x - 1
  • y(1)=3.436564y(1) = 3.436564, exactly
vs
Algorithm

Numerical (Heun, h=0.1h = 0.1)

  • 10 steps, 20 evaluations of ff
  • y(1)=3.428162y(1) = 3.428162 (error 0.008)
  • Same code for any f(x,y)f(x, y)
When the classical approach cannot work

y′=x2+y2y' = x^2 + y^2, y(0)=0y(0) = 0 (a Riccati equation)

No elementary formula exists (the solution involves Bessel functions). Numerically: Euler (h=0.1h = 0.1) 0.2925, Heun 0.3518, RK4 0.350234; very accurate value y(1)=0.350232y(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+yy' = x + y, h=0.1h = 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′=−20yy' = -20y: the true solution decays to 0 almost at once
  • Euler multiplies yy by (1−20h)(1 - 20h) each step: h=0.12h = 0.12 gives −1.4-1.4, so the numbers explode
  • Stability needs ∣1+hλ∣<1|1 + h\lambda| < 1, i.e. h<0.1h < 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 dydx=y−x\dfrac{dy}{dx} = y - x, y(0)=2y(0) = 2, find y(0.2)y(0.2) by Euler's method with h=0.1h = 0.1, then improve the result with the modified Euler method. Compare with the exact solution y=ex+x+1y = e^x + x + 1."
How to write a complete answer
  • Euler: y1=2+0.1(2)=2.2y_1 = 2 + 0.1(2) = 2.2;   y2=2.2+0.1(2.2−0.1)=2.41\;y_2 = 2.2 + 0.1(2.2 - 0.1) = 2.41
  • Modified Euler step 1: k1=2k_1 = 2, y∗=2.2y^* = 2.2, k2=2.1k_2 = 2.1, y1=2+0.05(4.1)=2.205y_1 = 2 + 0.05(4.1) = 2.205
  • Step 2: k1=2.105k_1 = 2.105, y∗=2.4155y^* = 2.4155, k2=2.2155k_2 = 2.2155, y2=2.205+0.05(4.3205)=2.421025y_2 = 2.205 + 0.05(4.3205) = 2.421025
  • Exact e0.2+1.2=2.421403e^{0.2} + 1.2 = 2.421403: errors 0.0114 (Euler) and 0.00038 (modified Euler); present both as tables
Md Mahbub E Noor
Lecture 21: ODEs I: Taylor, Picard, Euler, Heun
University of Barishal
19 / 25
When to use it

Euler and modified Euler: method profile

Best case
  • Teaching, quick sketches, very simple models
  • Heun: modest accuracy (3–4 digits) with little code
  • Euler inside game physics and real-time loops, where speed matters more than accuracy
Worst case
  • Long time spans: errors accumulate (first order)
  • Stiff equations: unstable unless hh is tiny
  • Oscillations and orbits: Euler adds energy and spirals outwards (Lecture 22)
Best suited for
  • Prototyping a model
  • Heun as a building block: predictor–corrector schemes
  • Taylor and Picard: deriving series solutions by hand; existence proofs
Avoid when
  • Production simulations (use RK4 or adaptive solvers)
  • Stiff problems (use implicit methods)
  • When 6+ digits are needed

Rule of thumb: Euler to understand, Heun for a quick improvement, RK4 (Lecture 22) for real work.

Md Mahbub E Noor
Lecture 21: ODEs I: Taylor, Picard, Euler, Heun
University of Barishal
20 / 25

Comparative analysis: methods for y′=f(x,y)y' = f(x, y)

MethodNeedsEvaluations per stepGlobal ordery(1)y(1) error (y′=x+yy' = x+y, h=0.1h = 0.1)Best use
Taylor (4 terms)derivatives of ffseveral formulas4≈4×10−6\approx 4\times10^{-6}simple ff, hand work
Picardintegrals in closed form—seriesdepends on iterationstheory, series solutions
Eulerff only110.249teaching, real-time loops
Heun (modified Euler)ff only228.4×10−38.4\times10^{-3}quick, modest accuracy
RK4 (Lecture 22)ff only444.2×10−64.2\times10^{-6}general purpose

RK4 matches the Taylor method's accuracy using only values of ff: that is the subject of the next lecture.

Md Mahbub E Noor
Lecture 21: ODEs I: Taylor, Picard, Euler, Heun
University of Barishal
21 / 25
Roadmap

Limitations, and where we fix them

Euler and Heun show the principle; real problems need more accuracy, more stability and systems of equations.

What it does well (keep this)
  • Step along the slope: yn+1=yn+h⋅y_{n+1} = y_n + h \cdot(slope)
  • Predictor–corrector idea
  • Local O(hp+1)O(h^{p+1}) vs global O(hp)O(h^p)
  • Check by halving hh
LimitationHow it is overcomeWhere
Low order: many steps for few digits
→
Runge–Kutta: several slopes per step, order 4
Lecture 22 →
Slopes from earlier steps are thrown away
→
Multistep: Milne, Adams–Bashforth–Moulton
Lecture 22 →
Instability with large steps (stiff problems)
→
Stability regions; implicit methods
Lecture 22 →
Real models have several unknowns
→
Systems: the same methods with vectors
Lecture 22 →
Md Mahbub E Noor
Lecture 21: ODEs I: Taylor, Picard, Euler, Heun
University of Barishal
22 / 25
Applications

Where this method runs in the real world

Click a card to see an ODE being stepped in a real system.

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′=2yy' = 2y, y(0)=1y(0) = 1, h=0.1h = 0.1. What is y1y_1?
A1.21.2
B1.11.1
C1.22141.2214
D0.20.2
A. y1=1+0.1×2(1)=1.2y_1 = 1 + 0.1 \times 2(1) = 1.2. The exact value is e0.2=1.2214e^{0.2} = 1.2214 (option C); Heun gives 1+0.05(2+2.4)=1.221 + 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' = f(x, y), y(x0)=y0y(x_0) = y_0; every method approximates ∫f(t,y(t))dt\int f(t, y(t))dt over each step
  • Taylor: expand and differentiate the ODE; Picard: y(k+1)=y0+∫f(t,y(k))dty^{(k+1)} = y_0 + \int f(t, y^{(k)})dt
  • Euler yn+1=yn+hfny_{n+1} = y_n + hf_n, global O(h)O(h); Heun: predictor + trapezoidal corrector, O(h2)O(h^2)
  • Too large hh can make the solution explode: stability, not only accuracy
Opening problem: solved

Tea after 10 minutes: Euler (h=1h = 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
  1. Solve y′=−2xy2y' = -2xy^2, y(0)=1y(0) = 1 to x=0.2x = 0.2 by Euler and by modified Euler (h=0.1h = 0.1). Compare with y=1/(1+x2)y = 1/(1 + x^2).
  2. Find the first three Picard approximations for y′=1+xyy' = 1 + xy, y(0)=1y(0) = 1.
  3. Use the Taylor series method (4 terms) to find y(0.1)y(0.1) for y′=x2+y2y' = x^2 + y^2, y(0)=1y(0) = 1.
  4. For y′=−50yy' = -50y, find the largest hh 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