Skip to main content

RK-4: y'' - 3y' + y = sin x

Short answer

Write the second-order equation as y'=z, z'=3z-y+sin x. Using fourth-order Runge-Kutta with h=0.1 over two steps gives y(1.2) approximately 1.3281 and y'(1.2) approximately 0.8104.

Solve the following initial value problem for y(1.2) using the Runge-Kutta fourth order method. y'' - 3y' + y = sin x; y(1) = 1.2; y'(1) = 0.5

Put z = y'. Then y'' = 3y' − y + sin x gives the system

dy/dx = z                    = f(x, y, z)
dz/dx = 3z − y + sin x       = g(x, y, z)
x₀ = 1, y₀ = 1.2, z₀ = 0.5

The step size is not given; take h = 0.1 (two steps to x = 1.2). RK-4 for the system:

k₁ = h·f(x, y, z)                              l₁ = h·g(x, y, z)
k₂ = h·f(x+h/2, y+k₁/2, z+l₁/2)                l₂ = h·g(x+h/2, y+k₁/2, z+l₁/2)
k₃ = h·f(x+h/2, y+k₂/2, z+l₂/2)                l₃ = h·g(x+h/2, y+k₂/2, z+l₂/2)
k₄ = h·f(x+h, y+k₃, z+l₃)                      l₄ = h·g(x+h, y+k₃, z+l₃)
yₙ₊₁ = yₙ + (k₁+2k₂+2k₃+k₄)/6                  zₙ₊₁ = zₙ + (l₁+2l₂+2l₃+l₄)/6

(sin x is in radians.)

Step 1 (x = 1 → 1.1), starting values y = 1.2000, z = 0.5000

k (for y)l (for z)
10.05000.1141
20.05570.1314
30.05660.1337
40.06340.1536
y(1.1) = 1.2000 + (0.0500 + 2(0.0557) + 2(0.0566) + 0.0634)/6 = 1.2563
z(1.1) = 0.5000 + (0.1141 + 2(0.1314) + 2(0.1337) + 0.1536)/6 = 0.6330

Step 2 (x = 1.1 → 1.2), starting values y = 1.2563, z = 0.6330

k (for y)l (for z)
10.06330.1534
20.07100.1754
30.07210.1783
40.08110.2037
y(1.2) = 1.2563 + (0.0633 + 2(0.0710) + 2(0.0721) + 0.0811)/6 = 1.3281
z(1.2) = 0.6330 + (0.1534 + 2(0.1754) + 2(0.1783) + 0.2037)/6 = 0.8104

Answer: y(1.2) ≈ 1.3281 (and y'(1.2) ≈ 0.8104); y(1.1) ≈ 1.2563.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Numerical Method chapter 6 questions →