## Runge-Kutta Method Calculator

Find the solutions of Ordinary Differential equations (ODEs) with the Runge kutta method using this calculator. It calculates the values of x and y based on the initial condition you provide and keeps on finding till the final value is reached.

## How to use this tool?

Contrary to its complex computation, the Runge-Kutta method calculator is rather easy to use.

1. Enter the differential equation.
2. Input the initial condition.
3. Enter the starting and ending values of the interval.
4. Choose  the step size (the smaller the step size, the more accurate the result.)

## What is Runge-Kutta Method?

The Runge-Kutta method is a popular and powerful technique used to numerically solve ordinary differential equations (ODEs). Specifically, it provides a means to approximate the solutions of ODEs when analytical solutions are hard to obtain or don't exist.

The Runge-Kutta method gives you a way to move in small steps from the known value y(t0) to approximate the solution at subsequent times, i.e., y(t0 + h), y(t0 + 2h),..., where ℎ is a small step size.

## Formula for Runge-kutta Method:

The most commonly used version of the method is 4th Order Runge-Kutta (RK4). It uses four estimates (hence "4th order") to compute the next value of y. For each step from t to t+h:

k1 = f(t,y)

k2 = f(t + h/2, y + hk1/2)

k3 = f(t + h/2, y + k2/2)

k4 = f(t + h, y + hk3)

Then, the new approximation for y(t+h) is:

y(t + h) = yt + ⅙ (k1 + 2k2 + 2k3 + k4)

The RK4 method is widely used because of its accuracy and stability for a broad range of ODEs. There are other versions of the Runge-Kutta method, like 2nd order (RK2) and higher-order variants, but RK4 strikes a good balance between computational cost and accuracy for many problems.

In practice, when using the Runge-Kutta method (or any numerical method for ODEs), it's important to be mindful of the step size ℎ. Too large of a step size may result in an unstable or inaccurate solution, while too small of a step size can be computationally difficult.

## Example:

Imagine you are driving a car and you want to know how far you will travel in the next second if you keep changing the speed according to some rule.

Suppose the rate of change of distance (or speed) of the car is given by:

dy /dt = f(t,y) = t^2 + 0.1y

This means that the speed of the car is influenced by both the time and a fraction of the distance already traveled. As the car travels further, its speed increases slightly because of the term 0.1y.

### Given:

Initial time t0 = 0 s

Initial distance y0 =0 meters

Chosen step size h = 0.5 s

Using the RK4 method:

Step 1: Calculate k1.

k1 = f(t0 , y0)

k1 = f(0,0) = 0^2 + 0.1(0) = 0

Step 2: Calculate k2.

k2 = f(t0 + h/2, y0 + h/2.k1 )

Given ℎ and k1:

k2 = f(0 + 0.25, 0 + 0.5 x 0 )  =

k2 = f(0.25, 0) = 0.25^2 + 0.1(0) = 0.0625

Step 3: Calculate k3.

k3 = f(t0 + h/2, y0 + h/2.k2 )

Using the values:

k3 = f(0 + 0.25, 0 + 0.5 × 0.0625)

k3 = f(0.25, 0.03125) = 0.25^2 + 0.1(0.03125)

k3 = 0.0625 + 0.003125 = 0.065625

Step 4: Calculate k4.

k4 = f (t0 + h, y0 + h.k3 )

Using the values:

k4 = f(0 + 0.5, 0 + 0.5 × 0.065625)

k4 = f(0.5, 0.0328125) = 0.5^2 + 0.1(0.0328125)

k4 = 0.25 + 0.00328125 =0.25328125

Final Update: Using the k values to update y:

y(0.5) = y0 + ⅙ (k1 + 2k2 + 2k3 + k4)

y(0.5) = 0 + ⅙  (0 + 2(0.0625) + 2(0.065625) + 0.25328125)

y(0.5) = ⅙  × 0.50953125 = 0.084921875

So, the function where the car's speed depends on both time and the distance already traveled, the car travels approximately 0.084921875 meters in the first 0.5 seconds.

NOTE: We only computed for half the interval till t = 0.5. Let's continue and compute for the full interval till t = 1.

Using the value we obtained:

y(0.5) = 0.084921875 meters

Let t1 = 0.5 s

We'll now find y(1).

Step 1: Calculate k1 for the interval from t1 to t1 + h.

k1 = f(t1, y(0.5))

k1 = f(0.5, 0.084921875) = 0.5^2 + 0.1(0.084921875)

k1 = 0.25 + 0.0084921875 = 0.2584921875

Step 2: Calculate k2.

k2  = f(t1 + h/2, y(0.5) + h/2.k1 )

k2  = f (0.75, 0.084921875 + 0.5 × 0.2584921875)

k2 = f(0.75, 0.21416796875)

k2 = 0.75^2 + 0.1(0.21416796875) = 0.57125 + 0.021416796875 = 0.592666796875

Step 3: Calculate k3

k3  = f(t1 + h/2, y(0.5) + h/2.k2 )

k3 = f(0.75, 0.084921875 + 0.5 × 0.592666796875)

k3 = f(0.75, 0.381255234375)

k3 = 0.75^2 + 0.1(0.381255234375) = 0.57125 + 0.0381255234375 = 0.6093755234375

Step 4: Calculate k4.

k4 = f(t1 +h, y(0.5) + h×k3)

k4 = f(1, 0.084921875 + 0.5 × 0.6093755234375)

k4 = f(1, 0.38960966796875)

k4 = 1^2 + 0.1(0.38960966796875) =1 + 0.038960966796875 = 1.038960966796875

Final Update for the interval from t1 to t1+ h:

y(1) = y(0.5) + ⅙ (k1 + 2k2 + 2k3 + k4)

y(1) = 0.084921875 + ⅙ (0.2584921875 + 2(0.592666796875) + 2(0.6093755234375) + 1.038960966796875)

y(1) = 0.084921875+0.683810313791667 = 0.768732188791667

So, by t = 1s, the car has traveled approximately 0.768732188791667 meters (or ≈ 76.873 centimeters).

Use android or iOS app of our limit calculator on your mobile