Mathematical Applications · BE5B15MAA · Topic 12 of 13
Using Nest and NestList for numerical algorithms, Euler and Runge–Kutta method
Week 12. A numerical method is a step function applied again and again, and NestList records every step.
Key ideas
Nest, NestList and NestWhileList
Nest[f,x,n] returns f applied n times; NestList[f,x,n] returns the n+1 values x, f[x], …, and NestWhileList[f,x,test] stops when the test fails. Fixed-point iteration is NestWhileList[Cos,1.,Abs[Cos[#]−#]>10^−5&]; Newton’s method is NestList of x−f[x]/f′[x].
Euler method as a step function
Keep a point as {t,y}, define step[{t_,y_}]:={t+Δt, y+Δt*derivative[{t,y}]} and run NestList[step,{tStart,yStart},nSteps]. Halving Δt gives a better curve; compare it with DSolve or NDSolve.
Runge–Kutta of fourth order
One RK4 step evaluates the derivative four times: at the start (k1), at the midpoint with k1 (k2), at the midpoint with k2 (k3) and at the end with k3 (k4), and moves along the weighted average. It agrees with the Taylor series up to the fourth power of the step.
In one line: NestList is the loop of numerical analysis: write the step once, then let Nest repeat it.
Formulas
- Nest, NestList and NestWhileList
- Euler method as a step function
- Runge–Kutta of fourth order
Practice with worked solutions
Question 1
Take one step of the fourth order Runge–Kutta method for y′ = y, y(0) = 1 with step h = 1. What is y₁?
Worked solution
Answer: 65/24
The four slopes are k1 = 1, k2 = 1.5, k3 = 1.75, k4 = 2.75, and their weighted average is moved along the step.
Question 2
One step of the fourth order Runge–Kutta method for y′ = −y, y(0) = 1 with step h = 1. What is y₁?
Worked solution
Answer: 3/8
The four slopes are k₁ = −1, k₂ = −1/2, k₃ = −3/4 and k₄ = −1/4; their weighted mean is −5/8.
More Mathematical Applications practice in Ucenly
Sources
Written by Ucenly. Based on the BE5B15MAA course materials:
- Course card BE5B15MAA (Bílá kniha), p. 1
- Seminar notebook, 14 Mar 2019 (seminar14032019.nb), text extract, p. 1
- Runge-Kutta method notebook (CAO-RungeKuttaEng.nb), text extract, p. 1
- Lecture notebook English 2015 (lecture English2015.nb), text extract, p. 1
- Seminar notebook, state of 28 Mar 2019 (seminar2832019.nb), text extract, p. 1