BIT203 · 2082 · 5 marks
Solve fracdydx = x2 + y, with y(0) = 1 for x = 1.5, using RK fourth order method.
Solve $\frac{dy}{dx} = x^2 + y$, with $y(0) = 1$ for $x = 1.5$, using RK fourth order method. [5]
RK4 Method: dy/dx = x² + y, y(0) = 1, find y(1.5)
Given data
- ODE: $\dfrac{dy}{dx} = f(x,y) = x^2 + y$
- Initial condition: $x_0 = 0$, $y_0 = 1$
- Target: $y$ at $x = 1.5$
- Step size (chosen): $h = 0.5$, giving 3 steps: $0 \to 0.5 \to 1.0 \to 1.5$
RK4 formulas
$$k_1 = h f(x_n, y_n),\quad k_2 = h f!\left(x_n+\tfrac h2, y_n+\tfrac{k_1}{2}\right)$$ $$k_3 = h f!\left(x_n+\tfrac h2, y_n+\tfrac{k_2}{2}\right),\quad k_4 = h f(x_n+h, y_n+k_3)$$ $$y_{n+1} = y_n + \tfrac16(k_1 + 2k_2 + 2k_3 + k_4)$$
Step 1: $x_0=0 \to x_1=0.5$, $y_0=1$
$$k_1 = 0.5(0^2+1) = 0.5$$ $$k_2 = 0.5\big(0.25^2 + (1+0.25)\big) = 0.5(0.0625+1.25) = 0.65625$$ $$k_3 = 0.5\big(0.0625 + (1+0.328125)\big) = 0.5(1.390625) = 0.6953125$$ $$k_4 = 0.5\big(0.25 + (1+0.6953125)\big) = 0.5(1.9453125) = 0.9726563$$
$$y_1 = 1 + \tfrac16(0.5 + 1.3125 + 1.390625 + 0.9726563) = 1 + \tfrac16(4.1757813)$$ $$\boxed{y_1 = 1.6959635}$$
Step 2: $x_1=0.5 \to x_2=1.0$, $y_1=1.6959635$
$$k_1 = 0.5(0.25 + 1.6959635) = 0.9729818$$ $$k_2 = 0.5\big(0.5625 + (1.6959635+0.4864909)\big) = 0.5(2.7449544) = 1.3724772$$ $$k_3 = 0.5\big(0.5625 + (1.6959635+0.6862386)\big) = 0.5(2.9447021) = 1.4723511$$ $$k_4 = 0.5\big(1.0 + (1.6959635+1.4723511)\big) = 0.5(4.1683146) = 2.0841573$$
$$y_2 = 1.6959635 + \tfrac16(0.9729818 + 2.7449544 + 2.9447022 + 2.0841573)$$ $$= 1.6959635 + \tfrac16(8.7467957) = 1.6959635 + 1.4577993$$ $$\boxed{y_2 = 3.1537628}$$
Step 3: $x_2=1.0 \to x_3=1.5$, $y_2=3.1537628$
$$k_1 = 0.5,f(1.0, 3.1537628) = 0.5(1.0 + 3.1537628) = 0.5(4.1537628) = 2.0768814$$
$y_2 + k_1/2 = 3.1537628 + 1.0384407 = 4.1922035$ $$k_2 = 0.5,f(1.25, 4.1922035) = 0.5(1.5625 + 4.1922035) = 0.5(5.7547035) = 2.8773518$$
$y_2 + k_2/2 = 3.1537628 + 1.4386759 = 4.5924387$ $$k_3 = 0.5,f(1.25, 4.5924387) = 0.5(1.5625 + 4.5924387) = 0.5(6.1549387) = 3.0774693$$
$y_2 + k_3 = 3.1537628 + 3.0774693 = 6.2312321$ $$k_4 = 0.5,f(1.5, 6.2312321) = 0.5(2.25 + 6.2312321) = 0.5(8.4812321) = 4.2406161$$
$$y_3 = 3.1537628 + \tfrac16\big(2.0768814 + 2(2.8773518) + 2(3.0774693) + 4.2406161\big)$$ $$= 3.1537628 + \tfrac16(2.0768814 + 5.7547036 + 6.1549386 + 4.2406161)$$ $$= 3.1537628 + \tfrac16(18.2271397)$$ $$= 3.1537628 + 3.0378566$$ $$\boxed{y_3 = y(1.5) \approx 6.1916}$$
Result
$$y(1.5) \approx 6.1916$$
(Exact solution $y = 3e^x - x^2 - 2x - 2$ gives $y(1.5) = 3e^{1.5} - 2.25 - 3 - 2 = 13.4450 - 7.25 = 6.1950$, confirming the RK4 result to about 3 significant figures.)
Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.