UcenlyOpen in the app

Differential Equations & Numerical Methods · BE5B01DEN · Topic 5 of 13

Numerical solution of ODEs: Euler and Runge–Kutta

Week 5. Euler is order 1, Heun and the midpoint rule are order 2, RK4 is order 4: more slopes per step buy a higher order.

Open the interactive lesson

Key ideas

The Euler method

Follow the slope at the left end of each step. With h=T/n it produces the points (xᵢ,yᵢ); the method has order 1.

Heun and the midpoint method

Both estimate a second slope and use it to correct the step. Heun averages the slopes at both ends; the midpoint method uses the slope at the middle. Both have order 2.

RK4 and error control

RK4 averages four slopes with weights 1,2,2,1 (divided by 6) and has order 4. Adaptive methods such as RKF45 compare two orders and shrink the step when they disagree.

In one line: Order p means halving h divides the final error by about 2^p.

Formulas

Practice with worked solutions

Question 1

Apply the Euler method with h = 1/2 for two steps and give y₂.

y′=x+y,y(0)=1y'=x+y,\quad y(0)=1
Worked solution

Answer: 5/2

  1. y1=1+0.5 (0+1)=1.5y_1=1+0.5\,(0+1)=1.5
  2. y2=1.5+0.5 (0.5+1.5)=2.5y_2=1.5+0.5\,(0.5+1.5)=2.5

Each step adds h·f(xᵢ,yᵢ).

Question 2

Apply one Heun step with h = 1/2 and give y₁.

y′=x+y,y(0)=1y'=x+y,\quad y(0)=1
Worked solution

Answer: 7/4

  1. k1=f(0,1)=1,y∗=1+0.5⋅1=1.5,k2=f(0.5,1.5)=2k_1=f(0,1)=1,\quad y^*=1+0.5\cdot1=1.5,\quad k_2=f(0.5,1.5)=2
  2. y1=1+0.52(1+2)=1.75y_1=1+\tfrac{0.5}2(1+2)=1.75

Average the slope at the left end and the slope at the Euler predictor.

Question 3

Apply one RK4 step with h = 1/2 and give y₁.

y′=y,y(0)=1y'=y,\quad y(0)=1
Worked solution

Answer: 211/128

  1. k1=1, k2=54, k3=2116, k4=5332k_1=1,\ k_2=\tfrac54,\ k_3=\tfrac{21}{16},\ k_4=\tfrac{53}{32}
  2. y1=1+0.56(1+52+218+5332)=211128y_1=1+\frac{0.5}6\Bigl(1+\tfrac52+\tfrac{21}8+\tfrac{53}{32}\Bigr)=\frac{211}{128}

Compute k₁, …, k₄ and combine them with weights 1, 2, 2, 1.

More Differential Equations & Numerical Methods practice in Ucenly

Sources

Written by Ucenly. Based on the BE5B01DEN course materials: