2079 11

CSC212 · 2079 · 5 marks

Solve the following differential equation for 0 leq x leq 1 taking h = 0.5 using Runge Kutta 4th order method.

Solve the following differential equation for $0 \leq x \leq 1$ taking $h = 0.5$ using Runge Kutta 4th order method.

$$y'(x) + y = 3x \quad \text{with} \quad y(0) = 2$$

[5]

Numerical MethodChapter 5: Solution of Ordinary Differential EquationsRunge-Kutta methodsNumerical: Runge-Kutta 4th order

Runge-Kutta 4th Order Method

Given

  • ODE: $y'(x) + y = 3x \Rightarrow y' = f(x,y) = 3x - y$
  • Initial condition: $y(0) = 2$
  • Step size: $h = 0.5$
  • Interval: $0 \le x \le 1$
  • Number of steps: 2 (from $x=0$ to $x=1$)

RK4 Formulas

$$k_1 = h,f(x_n, y_n), \quad k_2 = h,f\left(x_n+\tfrac{h}{2}, y_n+\tfrac{k_1}{2}\right)$$ $$k_3 = h,f\left(x_n+\tfrac{h}{2}, y_n+\tfrac{k_2}{2}\right), \quad k_4 = h,f(x_n+h, y_n+k_3)$$ $$y_{n+1} = y_n + \tfrac{1}{6}(k_1 + 2k_2 + 2k_3 + k_4)$$

with $f(x,y) = 3x - y$.


Solution

Iteration 1: $x_0 = 0$, $y_0 = 2$

$$k_1 = 0.5,(3(0) - 2) = 0.5(-2) = -1.0$$

$$k_2 = 0.5,f(0.25,\ 2 - 0.5) = 0.5,(0.75 - 1.5) = 0.5(-0.75) = -0.375$$

$$k_3 = 0.5,f(0.25,\ 2 - 0.1875) = 0.5,(0.75 - 1.8125) = 0.5(-1.0625) = -0.53125$$

$$k_4 = 0.5,f(0.5,\ 2 - 0.53125) = 0.5,(1.5 - 1.46875) = 0.5(0.03125) = 0.015625$$

$$y_1 = 2 + \tfrac{1}{6}(-1.0 + 2(-0.375) + 2(-0.53125) + 0.015625)$$ $$= 2 + \tfrac{1}{6}(-1.0 - 0.75 - 1.0625 + 0.015625) = 2 + \tfrac{1}{6}(-2.796875)$$ $$= 2 - 0.466146 = \boxed{1.533854}$$

$$y(0.5) \approx 1.5339$$

Iteration 2: $x_1 = 0.5$, $y_1 = 1.533854$

$$k_1 = 0.5,f(0.5,\ 1.533854) = 0.5,(1.5 - 1.533854) = 0.5(-0.033854) = -0.016927$$

$$k_2 = 0.5,f(0.75,\ 1.533854 - 0.008464) = 0.5,(2.25 - 1.525390) = 0.5(0.724610) = 0.362305$$

$$k_3 = 0.5,f(0.75,\ 1.533854 + 0.181153) = 0.5,(2.25 - 1.715007) = 0.5(0.534993) = 0.267497$$

$$k_4 = 0.5,f(1.0,\ 1.533854 + 0.267497) = 0.5,(3.0 - 1.801351) = 0.5(1.198649) = 0.599325$$

$$y_2 = 1.533854 + \tfrac{1}{6}(-0.016927 + 2(0.362305) + 2(0.267497) + 0.599325)$$ $$= 1.533854 + \tfrac{1}{6}(-0.016927 + 0.724610 + 0.534993 + 0.599325)$$ $$= 1.533854 + \tfrac{1}{6}(1.842001) = 1.533854 + 0.307000$$ $$= \boxed{1.840854}$$

$$y(1.0) \approx 1.8409$$


Summary Table

$x$$y$
$0.0$$2.0000$
$0.5$$1.5339$
$1.0$$1.8409$

Check (exact): $y = 3x - 3 + 5e^{-x}$; at $x=1$: $y = 0 + 5e^{-1} = 1.8394$. RK4 value $1.8409$ agrees closely.

Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.