Runge-Kutta (RK4) Method Notes
These Runge-Kutta (RK4) Method Notes explain how to approximate the solution of an initial value problem with the classic fourth-order scheme, with the working shown line by line. Four slopes are measured across each step, one at the start, two in the middle and one at the end, and their weighted average drives the step. Weighting the middle slopes twice as heavily is what makes it so much more accurate than Euler. Following the same pattern every time keeps the four slopes in order.
Step-by-step method
- Set up the problem.
- Write the update rule.
- Apply the rule step by step.
- Write the approximation.
Formula: Fourth-Order Runge-Kutta Method
Four slopes are worked out in each step, at the start, twice in the middle and at the end, and their weighted average moves the solution forward.
Useful Tips to Remember
A smaller step size h gives a more accurate answer but needs more steps. Keep x and y moving together: every step adds h to x and uses the new y in the next slope. Round only the final answer, and keep the working values as accurate as you can. Check that \(x_{0} + nh\) is the x value you want to reach. The middle slopes \(k_{2}\) and \(k_{3}\) are counted twice, so the weights add up to 6.
Required knowledge
- How the basic step works, covered in the Euler's Method Calculator.
- How to evaluate f at a point, covered in the Function Evaluator Calculator.
Where Is the Runge-Kutta Method Used?
The fourth-order Runge-Kutta method is the workhorse of numerical differential equations. It gives very accurate answers with large steps, so it is used to simulate planetary orbits, rocket flight, chemical reactions and electrical circuits. Many scientific software packages use it, or a close relative, as their default solver.
- Spacecraft and planetary orbits
- Weather and climate models
- Chemical reaction simulations
- Circuit simulation software
- Default solvers in scientific software
Runge-Kutta Method Practice Problems
Example 1 steps \(y' = y - x\) from \(y(0) = 2\) with \(h = 0.2\) for 5 steps, and Example 2 steps \(y' = xy\) from \(y(0) = 1\) with \(h = 0.1\) for 3 steps. Examples 3 and 4 give you two more problems of the same kind to try. Work out the four slopes in order for each step.
The worked examples below go through the same pattern from start to finish, so you can compare every step with your own working. Try each problem on paper first, then open the example and check your working one step at a time, so you can see exactly which step went wrong if your answer does not match. Use them to check your answers and to understand why each step works.
See Example 1 Hide Example 1
Problem
Approach
Step-by-step method
- Set up the problem.
- Write the update rule.
- Apply the rule step by step.
- Write the approximation.
Formula
Formula: Fourth-Order Runge-Kutta Method
Four slopes are worked out in each step, at the start, twice in the middle and at the end, and their weighted average moves the solution forward.
Step 1
Step 1 - Set up the problem.
In this problem: We are approximating the solution of \(y' = - x + y\) starting from \(y(0) = 2\), taking 5 steps of size \(h = 0.2\) to reach \(x = 1\).
Step 2
Step 2 - Write the update rule.
In this problem: The fourth-order Runge-Kutta method samples the slope four times in each step: at the start, twice at the middle and once at the end. Their weighted average, with the middle slopes counted twice, gives a very accurate step.
Step 3
Step 3 - Apply the rule step by step.
In this problem: The rule is applied 5 times, and each step starts where the last one ended. The table shows every point, rounded to 6 decimal places.
Step 3a
Step 3a - Step 1.
In this problem: From \((x_{0}, y_{0}) = (0,\; 2)\), the four slopes are worked out in turn: \(k_{1} = f(0,\; 2) = - 0 + {2} = 2\), \(k_{2} = f(0.1,\; 2.2) = - 0.1 + {2.2} = 2.1\), \(k_{3} = f(0.1,\; 2.21) = - 0.1 + {2.21} = 2.11\) and \(k_{4} = f(0.2,\; 2.422) = - 0.2 + {2.422} = 2.222\). Combining them gives \(y_{1} = 2 + \frac{0.2}{6}\left(2 + 2 \times 2.1 + 2 \times 2.11 + 2.222\right) = 2.4214\).
Step 3b
Step 3b - Step 2.
In this problem: From \((x_{1}, y_{1}) = (0.2,\; 2.4214)\), the four slopes are worked out in turn: \(k_{1} = f(0.2,\; 2.4214) = - 0.2 + {2.4214} = 2.2214\), \(k_{2} = f(0.3,\; 2.64354) = - 0.3 + {2.64354} = 2.34354\), \(k_{3} = f(0.3,\; 2.655754) = - 0.3 + {2.655754} = 2.355754\) and \(k_{4} = f(0.4,\; 2.892551) = - 0.4 + {2.892551} = 2.492551\). Combining them gives \(y_{2} = 2.4214 + \frac{0.2}{6}\left(2.2214 + 2 \times 2.34354 + 2 \times 2.355754 + 2.492551\right) = 2.891818\).
Step 3c
Step 3c - Step 3.
In this problem: From \((x_{2}, y_{2}) = (0.4,\; 2.891818)\), the four slopes are worked out in turn: \(k_{1} = f(0.4,\; 2.891818) = - 0.4 + {2.891818} = 2.491818\), \(k_{2} = f(0.5,\; 3.141) = - 0.5 + {3.141} = 2.641\), \(k_{3} = f(0.5,\; 3.155918) = - 0.5 + {3.155918} = 2.655918\) and \(k_{4} = f(0.6,\; 3.423002) = - 0.6 + {3.423002} = 2.823002\). Combining them gives \(y_{3} = 2.891818 + \frac{0.2}{6}\left(2.491818 + 2 \times 2.641 + 2 \times 2.655918 + 2.823002\right) = 3.422106\).
Step 3d
Step 3d - Step 4.
In this problem: From \((x_{3}, y_{3}) = (0.6,\; 3.422106)\), the four slopes are worked out in turn: \(k_{1} = f(0.6,\; 3.422106) = - 0.6 + {3.422106} = 2.822106\), \(k_{2} = f(0.7,\; 3.704317) = - 0.7 + {3.704317} = 3.004317\), \(k_{3} = f(0.7,\; 3.722538) = - 0.7 + {3.722538} = 3.022538\) and \(k_{4} = f(0.8,\; 4.026614) = - 0.8 + {4.026614} = 3.226614\). Combining them gives \(y_{4} = 3.422106 + \frac{0.2}{6}\left(2.822106 + 2 \times 3.004317 + 2 \times 3.022538 + 3.226614\right) = 4.025521\).
Step 3e
Step 3e - Step 5.
In this problem: From \((x_{4}, y_{4}) = (0.8,\; 4.025521)\), the four slopes are worked out in turn: \(k_{1} = f(0.8,\; 4.025521) = - 0.8 + {4.025521} = 3.225521\), \(k_{2} = f(0.9,\; 4.348073) = - 0.9 + {4.348073} = 3.448073\), \(k_{3} = f(0.9,\; 4.370328) = - 0.9 + {4.370328} = 3.470328\) and \(k_{4} = f(1,\; 4.719586) = - 1 + {4.719586} = 3.719586\). Combining them gives \(y_{5} = 4.025521 + \frac{0.2}{6}\left(3.225521 + 2 \times 3.448073 + 2 \times 3.470328 + 3.719586\right) = 4.718251\).
Step 4
Step 4 - Write the approximation.
In this problem: After 5 steps the approximation is \(y(1) \approx 4.718251\).
Final Answer
See Example 2 Hide Example 2
Problem
Approach
Step-by-step method
- Set up the problem.
- Write the update rule.
- Apply the rule step by step.
- Write the approximation.
Formula
Formula: Fourth-Order Runge-Kutta Method
Four slopes are worked out in each step, at the start, twice in the middle and at the end, and their weighted average moves the solution forward.
Step 1
Step 1 - Set up the problem.
In this problem: We are approximating the solution of \(y' = x y\) starting from \(y(0) = 1\), taking 3 steps of size \(h = 0.1\) to reach \(x = 0.3\).
Step 2
Step 2 - Write the update rule.
In this problem: The fourth-order Runge-Kutta method samples the slope four times in each step: at the start, twice at the middle and once at the end. Their weighted average, with the middle slopes counted twice, gives a very accurate step.
Step 3
Step 3 - Apply the rule step by step.
In this problem: The rule is applied 3 times, and each step starts where the last one ended. The table shows every point, rounded to 6 decimal places.
Step 3a
Step 3a - Step 1.
In this problem: From \((x_{0}, y_{0}) = (0,\; 1)\), the four slopes are worked out in turn: \(k_{1} = f(0,\; 1) = 0 \times {1} = 0\), \(k_{2} = f(0.05,\; 1) = 0.05 \times {1} = 0.05\), \(k_{3} = f(0.05,\; 1.0025) = 0.05 \times {1.0025} = 0.050125\) and \(k_{4} = f(0.1,\; 1.005013) = 0.1 \times {1.005013} = 0.100501\). Combining them gives \(y_{1} = 1 + \frac{0.1}{6}\left(0 + 2 \times 0.05 + 2 \times 0.050125 + 0.100501\right) = 1.005013\).
Step 3b
Step 3b - Step 2.
In this problem: From \((x_{1}, y_{1}) = (0.1,\; 1.005013)\), the four slopes are worked out in turn: \(k_{1} = f(0.1,\; 1.005013) = 0.1 \times {1.005013} = 0.100501\), \(k_{2} = f(0.15,\; 1.010038) = 0.15 \times {1.010038} = 0.151506\), \(k_{3} = f(0.15,\; 1.012588) = 0.15 \times {1.012588} = 0.151888\) and \(k_{4} = f(0.2,\; 1.020201) = 0.2 \times {1.020201} = 0.20404\). Combining them gives \(y_{2} = 1.005013 + \frac{0.1}{6}\left(0.100501 + 2 \times 0.151506 + 2 \times 0.151888 + 0.20404\right) = 1.020201\).
Step 3c
Step 3c - Step 3.
In this problem: From \((x_{2}, y_{2}) = (0.2,\; 1.020201)\), the four slopes are worked out in turn: \(k_{1} = f(0.2,\; 1.020201) = 0.2 \times {1.020201} = 0.20404\), \(k_{2} = f(0.25,\; 1.030403) = 0.25 \times {1.030403} = 0.257601\), \(k_{3} = f(0.25,\; 1.033081) = 0.25 \times {1.033081} = 0.25827\) and \(k_{4} = f(0.3,\; 1.046028) = 0.3 \times {1.046028} = 0.313809\). Combining them gives \(y_{3} = 1.020201 + \frac{0.1}{6}\left(0.20404 + 2 \times 0.257601 + 2 \times 0.25827 + 0.313809\right) = 1.046028\).
Step 4
Step 4 - Write the approximation.
In this problem: After 3 steps the approximation is \(y(0.3) \approx 1.046028\).
Final Answer
See Example 3 Hide Example 3
Problem
Approach
Step-by-step method
- Set up the problem.
- Write the update rule.
- Apply the rule step by step.
- Write the approximation.
Formula
Formula: Fourth-Order Runge-Kutta Method
Four slopes are worked out in each step, at the start, twice in the middle and at the end, and their weighted average moves the solution forward.
Step 1
Step 1 - Set up the problem.
In this problem: We are approximating the solution of \(y' = x + y\) starting from \(y(0) = 1\), taking 4 steps of size \(h = 0.1\) to reach \(x = 0.4\).
Step 2
Step 2 - Write the update rule.
In this problem: The fourth-order Runge-Kutta method samples the slope four times in each step: at the start, twice at the middle and once at the end. Their weighted average, with the middle slopes counted twice, gives a very accurate step.
Step 3
Step 3 - Apply the rule step by step.
In this problem: The rule is applied 4 times, and each step starts where the last one ended. The table shows every point, rounded to 6 decimal places.
Step 3a
Step 3a - Step 1.
In this problem: From \((x_{0}, y_{0}) = (0,\; 1)\), the four slopes are worked out in turn: \(k_{1} = f(0,\; 1) = 0 + {1} = 1\), \(k_{2} = f(0.05,\; 1.05) = 0.05 + {1.05} = 1.1\), \(k_{3} = f(0.05,\; 1.055) = 0.05 + {1.055} = 1.105\) and \(k_{4} = f(0.1,\; 1.1105) = 0.1 + {1.1105} = 1.2105\). Combining them gives \(y_{1} = 1 + \frac{0.1}{6}\left(1 + 2 \times 1.1 + 2 \times 1.105 + 1.2105\right) = 1.110342\).
Step 3b
Step 3b - Step 2.
In this problem: From \((x_{1}, y_{1}) = (0.1,\; 1.110342)\), the four slopes are worked out in turn: \(k_{1} = f(0.1,\; 1.110342) = 0.1 + {1.110342} = 1.210342\), \(k_{2} = f(0.15,\; 1.170859) = 0.15 + {1.170859} = 1.320859\), \(k_{3} = f(0.15,\; 1.176385) = 0.15 + {1.176385} = 1.326385\) and \(k_{4} = f(0.2,\; 1.24298) = 0.2 + {1.24298} = 1.44298\). Combining them gives \(y_{2} = 1.110342 + \frac{0.1}{6}\left(1.210342 + 2 \times 1.320859 + 2 \times 1.326385 + 1.44298\right) = 1.242805\).
Step 3c
Step 3c - Step 3.
In this problem: From \((x_{2}, y_{2}) = (0.2,\; 1.242805)\), the four slopes are worked out in turn: \(k_{1} = f(0.2,\; 1.242805) = 0.2 + {1.242805} = 1.442805\), \(k_{2} = f(0.25,\; 1.314945) = 0.25 + {1.314945} = 1.564945\), \(k_{3} = f(0.25,\; 1.321052) = 0.25 + {1.321052} = 1.571052\) and \(k_{4} = f(0.3,\; 1.39991) = 0.3 + {1.39991} = 1.69991\). Combining them gives \(y_{3} = 1.242805 + \frac{0.1}{6}\left(1.442805 + 2 \times 1.564945 + 2 \times 1.571052 + 1.69991\right) = 1.399717\).
Step 3d
Step 3d - Step 4.
In this problem: From \((x_{3}, y_{3}) = (0.3,\; 1.399717)\), the four slopes are worked out in turn: \(k_{1} = f(0.3,\; 1.399717) = 0.3 + {1.399717} = 1.699717\), \(k_{2} = f(0.35,\; 1.484703) = 0.35 + {1.484703} = 1.834703\), \(k_{3} = f(0.35,\; 1.491452) = 0.35 + {1.491452} = 1.841452\) and \(k_{4} = f(0.4,\; 1.583862) = 0.4 + {1.583862} = 1.983862\). Combining them gives \(y_{4} = 1.399717 + \frac{0.1}{6}\left(1.699717 + 2 \times 1.834703 + 2 \times 1.841452 + 1.983862\right) = 1.583648\).
Step 4
Step 4 - Write the approximation.
In this problem: After 4 steps the approximation is \(y(0.4) \approx 1.583648\).
Final Answer
See Example 4 Hide Example 4
Problem
Approach
Step-by-step method
- Set up the problem.
- Write the update rule.
- Apply the rule step by step.
- Write the approximation.
Formula
Formula: Fourth-Order Runge-Kutta Method
Four slopes are worked out in each step, at the start, twice in the middle and at the end, and their weighted average moves the solution forward.
Step 1
Step 1 - Set up the problem.
In this problem: We are approximating the solution of \(y' = 2 x\) starting from \(y(0) = 0\), taking 4 steps of size \(h = 0.5\) to reach \(x = 2\).
Step 2
Step 2 - Write the update rule.
In this problem: The fourth-order Runge-Kutta method samples the slope four times in each step: at the start, twice at the middle and once at the end. Their weighted average, with the middle slopes counted twice, gives a very accurate step.
Step 3
Step 3 - Apply the rule step by step.
In this problem: The rule is applied 4 times, and each step starts where the last one ended. The table shows every point, rounded to 6 decimal places.
Step 3a
Step 3a - Step 1.
In this problem: From \((x_{0}, y_{0}) = (0,\; 0)\), the four slopes are worked out in turn: \(k_{1} = f(0,\; 0) = 2 \times 0 = 0\), \(k_{2} = f(0.25,\; 0) = 2 \times 0.25 = 0.5\), \(k_{3} = f(0.25,\; 0.125) = 2 \times 0.25 = 0.5\) and \(k_{4} = f(0.5,\; 0.25) = 2 \times 0.5 = 1\). Combining them gives \(y_{1} = 0 + \frac{0.5}{6}\left(0 + 2 \times 0.5 + 2 \times 0.5 + 1\right) = 0.25\).
Step 3b
Step 3b - Step 2.
In this problem: From \((x_{1}, y_{1}) = (0.5,\; 0.25)\), the four slopes are worked out in turn: \(k_{1} = f(0.5,\; 0.25) = 2 \times 0.5 = 1\), \(k_{2} = f(0.75,\; 0.5) = 2 \times 0.75 = 1.5\), \(k_{3} = f(0.75,\; 0.625) = 2 \times 0.75 = 1.5\) and \(k_{4} = f(1,\; 1) = 2 \times 1 = 2\). Combining them gives \(y_{2} = 0.25 + \frac{0.5}{6}\left(1 + 2 \times 1.5 + 2 \times 1.5 + 2\right) = 1\).
Step 3c
Step 3c - Step 3.
In this problem: From \((x_{2}, y_{2}) = (1,\; 1)\), the four slopes are worked out in turn: \(k_{1} = f(1,\; 1) = 2 \times 1 = 2\), \(k_{2} = f(1.25,\; 1.5) = 2 \times 1.25 = 2.5\), \(k_{3} = f(1.25,\; 1.625) = 2 \times 1.25 = 2.5\) and \(k_{4} = f(1.5,\; 2.25) = 2 \times 1.5 = 3\). Combining them gives \(y_{3} = 1 + \frac{0.5}{6}\left(2 + 2 \times 2.5 + 2 \times 2.5 + 3\right) = 2.25\).
Step 3d
Step 3d - Step 4.
In this problem: From \((x_{3}, y_{3}) = (1.5,\; 2.25)\), the four slopes are worked out in turn: \(k_{1} = f(1.5,\; 2.25) = 2 \times 1.5 = 3\), \(k_{2} = f(1.75,\; 3) = 2 \times 1.75 = 3.5\), \(k_{3} = f(1.75,\; 3.125) = 2 \times 1.75 = 3.5\) and \(k_{4} = f(2,\; 4) = 2 \times 2 = 4\). Combining them gives \(y_{4} = 2.25 + \frac{0.5}{6}\left(3 + 2 \times 3.5 + 2 \times 3.5 + 4\right) = 4\).
Step 4
Step 4 - Write the approximation.
In this problem: After 4 steps the approximation is \(y(2) \approx 4\).
Final Answer
Calculator and Practice Mode
Want to check your own working? The Runge-Kutta (RK4) Method Calculator solves any problem you type in and shows every step, so you can compare it line by line with your answer and find exactly where a mistake crept in. When you are ready to test yourself, Runge-Kutta (RK4) Method Practice gives you a new problem at Easy, Medium or Hard level, checks your answer and shows the full working whenever you get one wrong. Practice Mode for this calculator is available on the Pro plan.