Runge-Kutta (RK4) Method Calculator
This Runge-Kutta Method Calculator approximates the solution of an initial value problem with the classic fourth-order scheme, and shows the working 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. Work out the four slopes in order for each step. For two more free worked examples, check out the Runge-Kutta (RK4) Method Notes.
The worked examples below go through the same pattern from start to finish, so you can compare every step with your own working. For more practice, the notes page goes further with extra worked examples and fuller explanations of the ideas behind each step. Use them together 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
Notes and Practice Mode
Want to understand the method more deeply? The Runge-Kutta (RK4) Method Notes go through the same pattern with extra worked examples and fuller explanations of the ideas behind each step, so you can see why every step works and not just what to do. 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.
Login and upgrade to Pro to unlock the full step solution.
Example Problems
Click one to load it into the box and solve it.