The **4th-order ****Runge-Kutta** method, also referred to as **RK4**, is widely used to solve ordinary differential equations (ODEs) numerically. It gives an approximate solution of an ODE by estimating the value of the next point based on the derivative at a number of intermediary points. RK4 uses four approximations to the slope.

Suppose, there is a first-order differential equation such that its solution needs approximation given by:

** with ****y(t**_{0}**)=y**_{0}

The following slope approximations are used to estimate the slope at some time *t₀* (assuming there is an approximation to* y(t₀) *(that is * y*(t₀)*).

The slope at the start of the time step is known as

**k**_{1}; it is also known as k_{1}in the first and second-order RK methods.A rough estimate of the slope at the midway is represented by

**k**_{2}if we use slope k_{1}to step halfway through the time step.An alternative estimation of the slope is

**k**_{3}at the midpoint if we use slope k_{2}to step halfway through the time step.The slope, k

_{3}, is then used to step through the entire time step (to**t**_{0}), and**+h****k**_{4}is an estimate of the slope at the endpoint.

**Mathematically, the RK4 method can be expressed as follows**

where:

*t*_{0}*y*represents the current value of the solution*h*represents the step size or time interval*f(t*_{0}*, y)*is the derivative function that defines the ODE

Finally, a weighted sum of these four slopes is used to obtain the final estimate of * y*(t₀+h) *is given by:

Here is the weighted average slope estimation

Let's consider an example of the differential equation

with **y(0)=3**

since

Using the equation given above, we can use _{1}.

We estimate the value of the function at the halfway point of the interval, or y(½h), using this slope. The formula for this estimation is

Using the equation of y_{1} given above, we can use it to estimate the slope at the midpoint of the interval,

We estimate the slope at *. *The formula for this estimation is

Using the equation of y_{2} given above, we can use it to estimate the slope at the midpoint of the interval, *t=½h*. This slope is called

We estimate the value of the function at the end of the interval, or y(h), using this slope at

Using the equation of

Creating the final estimate for

**using m, to generate the final estimate**

The final estimate’s value for this example is

Note: Exact solution will not always be given as it is in this case.

Using this estimate as a starting point, we can repeat this procedure to eventually come up with a solution.

All in all, the RK4 method is an iterative process, and compared to lower-order RK approaches, it is relatively accurate and straightforward, which makes it popular. However, to accurately record quick changes in the solution, smaller step sizes could be necessary.

Copyright ©2024 Educative, Inc. All rights reserved

TRENDING TOPICS