All problems
RK4 One Step
Problem
Take one classical fourth-order Runge-Kutta step for the ODE y' = t + y starting at (t, y) with step size h.
The stage slopes are k1 = f(t, y), k2 = f(t + h/2, y + h*k1/2), k3 = f(t + h/2, y + h*k2/2), and k4 = f(t + h, y + h*k3). Return y + h*(k1 + 2*k2 + 2*k3 + k4)/6.
Hint
The weighted average of the four slopes has fourth-order accuracy.
Test cases
case 1
in: [0,1,0.1]
expected: 1.1103416666666668
case 2
in: [0,1,0.5]
expected: 1.796875
case 3
in: [1,0,0.2]
expected: 0.24280000000000004
case 4
in: [0,0,0]
expected: 0
Starter codePython
def rk4_step(t, y, h):
# Your code here
pass4 test cases · run your code against them in the editor