[Math] How to solve this Initial Value Problem using the Runge-Kutta method

integrationordinary differential equations

My Problem is this: given Initial Value Problem

$$y^{\prime}=\frac{3x-2y}{x}\quad y(1)=0$$

There is a given Interval of $[1,2]$ and a given step size $h$ of $h=0.1$

After using Euler's and Heun's method I am looking for a way to solve it with the Runge-Kutta method for differential equations / IV-Problems of first order.

My Approach: To understand the differences between these mentioned methods it seems important for me to calculate at least one example. We already solved this Problem with Euler's and Heun's.

Additionally we have determined the exact solution:
$$y(x) = \dfrac{x^3-1}{x^2}$$
at $x=2$ it is: $$y(2) = \dfrac{7}{4} = 1.75$$

But what is the way to solve it with the Runge-Kutta method? I am stuck in applying it on the solution. But I guess the solution is even more accurate than the solution we got from the Heun's method.

Best Answer

To be complete, it is worth noting that there are many variants of Runge-Kutta (RK), including some new ones. These include, but are not limited to:

  • Generalized RK, RK1, RK2, RK3, RK4, Simple RK, Euler-Cauchy, Optimal Method, RK5, New Variant RK, RK-Merson (RKM), RK-Fehlberg (RKF), Cash-Karp-RK (CKRK), Implicit RK (IRK) ...

For this problem, I will assume you want to typical fourth order RK (RK4).

Initialization

  • $h = \dfrac{b-a}{N} = .1 = \dfrac{2-1}{N} \rightarrow N = 10$
  • $x_0 = a = 1, y_0 = y(a) = y(1) = \alpha = 0 \rightarrow a = 1, \alpha = 0$

Iteration using RK4

  • $y'(x) = f(x, y) = \dfrac{3 x -2 y}{x}, y(1) = 0$
  • $k_1 = h f(x_i, y_i)$
  • $k_2 = h f(x_i + h/2, y_i + k_1/2)$
  • $k_3 = h f(x_i + h/2, y_i + k_2/2)$
  • $k_4 = h f(x_i + h, y_i + k_3)$
  • $y_{i + 1} = y_i + \dfrac{1}{6}\left( k_1+2k_2+2k_3+k_4 \right)$
  • $x_{i + 1} = x_i + h = 1 + 0.1 i$

Results

  • For $i= 1$, we have:
  • $x_0 = 1, y_0 = 0$
  • $k_1 = h f(x_i, y_i) = \dfrac{1}{10} \left(\dfrac{3 x_{i} - 2 y_{i}}{x_{i}}\right) = \dfrac{1}{10}\left(\dfrac{3 x(0) - 2y(0)}{x(0)}\right) = \dfrac{1}{10}\left(\dfrac{3 (1) - 2(0)}{1}\right) = 0.3$
  • $k_2 = h f(x_i + h/2, y_i + k_1/2) = \dfrac{1}{10} \left(\dfrac{3 (x_{i}+(1/20)) - 2(y_{i} + (0.3/2))}{x_{i}+(1/20)}\right) = \dfrac{1}{10} \left(\dfrac{3 (1+(1/20)) - 2(0 + (0.3/2))}{1+(1/20)}\right) = 0.271428571428571428571428571428571428571428571428571428571428$
  • $k_3 = h f(x_i + h/2, y_i + k_2/2) = \dfrac{1}{10} \left(\dfrac{3 (x_{i}+(1/20)) - 2(y_{i} + (0.27142857/2))}{x_{i}+(1/20)}\right) = \dfrac{1}{10} \left(\dfrac{3 (1+(1/20)) - 2(0 + (0.27142857/2))}{1+(1/20)}\right) = 0.274149659863945578231292517006802721088435374149659863945578$
  • $k_4 = h f(x_i + h, y_i + k_3) = \dfrac{1}{10} \left(\dfrac{3 (x_{i}+(1/10)) - 2(y_{i} + 0.2741496598)}{x_{i}+(1/10)}\right) = \dfrac{1}{10} \left(\dfrac{3 (1+(1/10)) - 2(0 + 0.2741496598)}{1+(1/10)}\right)= 0.250154607297464440321583178726035868893011750154607297464440$
  • $y_{i + 1} = y_i + \dfrac{1}{6}\left( k_1+2k_2+2k_3+k_4 \right) = 0.273551844980416408987837559266130694702123273551844980090476 \approx 0.273552$
  • $x_{i + 1} = x_i + h = 1 + 0.1 i = 1.1$

Continuing with this itearation, we generate the following table.

$~~~~~\text{Step} ~~|~~~~ x ~~~|~~ y $

  • $~~00 ~~|~~ 1.0 ~~|~~ 0. 00000$
  • $~~01 ~~|~~ 1.1 ~~|~~ 0.273552$
  • $~~02 ~~|~~ 1.2 ~~|~~ 0.505553$
  • $~~03 ~~|~~ 1.3 ~~|~~ 0.708281$
  • $~~04 ~~|~~ 1.4 ~~|~~ 0.889793$
  • $~~05 ~~|~~ 1.5 ~~|~~ 1.05555$
  • $~~06 ~~|~~ 1.6 ~~|~~ 1.20937$
  • $~~07 ~~|~~ 1.7 ~~|~~ 1.35398$
  • $~~08 ~~|~~ 1.8 ~~|~~ 1.49136$
  • $~~09 ~~|~~ 1.9 ~~|~~ 1.62299$
  • $~~10 ~~|~~ 2.0 ~~|~~ 1.75$

The exact solution is given by:

$$y(x) = \dfrac{x^3-1}{x^2}$$

At $x=2$, we have: $y(2) = \dfrac{7}{4} = 1.75$

Compare that to Runge-Kutta's-4 method, which has $1.75$.