2081 11

CSC212 · 2081 · 5 marks

Solve fracdydx = fracxy, y(0) = 1, at x = 0.4 using Runge-Kutta's 4th order method.

Solve $\frac{dy}{dx} = \frac{x}{y}$, $y(0) = 1$, at $x = 0.4$ using Runge-Kutta's 4th order method. [5]

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

Runge-Kutta 4th Order Method

Given Data

$$\frac{dy}{dx} = f(x,y) = \frac{x}{y}, \quad y_0 = 1 \text{ at } x_0 = 0, \quad \text{find } y(0.4)$$

Step size: $h = 0.4$ (single step).

RK4 Formulas

$$k_1 = h f(x_0, y_0)$$ $$k_2 = h f\left(x_0+\tfrac{h}{2}, y_0+\tfrac{k_1}{2}\right)$$ $$k_3 = h f\left(x_0+\tfrac{h}{2}, y_0+\tfrac{k_2}{2}\right)$$ $$k_4 = h f\left(x_0+h, y_0+k_3\right)$$ $$y_1 = y_0 + \tfrac{1}{6}(k_1 + 2k_2 + 2k_3 + k_4)$$

Calculation

$k_1$: $$k_1 = 0.4 \cdot f(0, 1) = 0.4 \cdot \frac{0}{1} = 0$$

$k_2$: $$k_2 = 0.4 \cdot f(0.2, \ 1+0) = 0.4 \cdot \frac{0.2}{1} = 0.08$$

$k_3$: $$k_3 = 0.4 \cdot f(0.2, \ 1+0.04) = 0.4 \cdot \frac{0.2}{1.04} = 0.4 \cdot 0.192308 = 0.076923$$

$k_4$: $$k_4 = 0.4 \cdot f(0.4, \ 1+0.076923) = 0.4 \cdot \frac{0.4}{1.076923} = 0.4 \cdot 0.371429 = 0.148571$$

Final Result

$$y_1 = 1 + \frac{1}{6}\big(0 + 2(0.08) + 2(0.076923) + 0.148571\big)$$

$$= 1 + \frac{1}{6}\big(0 + 0.16 + 0.153846 + 0.148571\big)$$

$$= 1 + \frac{1}{6}(0.462418) = 1 + 0.077070$$

$$\boxed{y(0.4) \approx 1.0771}$$

Verification (Exact Solution)

Separating variables: $y,dy = x,dx \Rightarrow \tfrac{y^2}{2} = \tfrac{x^2}{2} + C$. With $y(0)=1$, $C = \tfrac12$, so $y = \sqrt{1+x^2}$.

At $x=0.4$: $y = \sqrt{1.16} = 1.07703$.

The RK4 result $1.0771$ matches the exact value very closely.

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