← 2026 Paper 2

UPSC 2026 Maths Optional Paper 2 Q8b — Step-by-Step Solution

15 marks · Section B

Runge-Kutta methods (RK2/RK4) · Numerical Analysis · asked 5× in 14 yrs · Read the full method →

Question

Consider the initial value problem:

dydx=1+yx,y(1)=1,h=1 (Step-size)\frac{dy}{dx} = 1 + \frac{y}{x},\quad y(1) = 1,\quad h = 1 \text{ (Step-size)}

(i) Apply the classical fourth order Runge-Kutta method to approximate the solution y(2)y(2).

(ii) Use Euler’s method to find y(2)y(2) and y(3)y(3).

Technique

Straight application of two standard one-step formulae, but with a step size h=1h = 1 that is deliberately enormous — that is the whole point of the question, and the marks are in the arithmetic being exact and completely shown. Note that f(x,y)=1+y/xf(x,y) = 1 + y/x depends on both arguments, so the Runge–Kutta stages must advance xx to 1.51.5 and 22 as well as yy; ignoring the xx-shift is the standard way to lose this question. The equation is also linear (y′−y/x=1y' - y/x = 1), so the exact solution is available in one line and the comparison table it makes possible is what lifts the answer above a bare numerical grind.

Solution

Step 0 — The problem is well posed on the interval we use

Here

f(x,y)=1+yx,x0=1, y0=1, h=1.f(x,y) = 1 + \frac{y}{x},\qquad x_0 = 1,\ y_0 = 1,\ h = 1 .

The right-hand side has a singular point at x=0x = 0, where ff is undefined. But every abscissa used below lies in [1,3][1,3]: the Euler nodes are x=1,2,3x = 1, 2, 3 and the Runge–Kutta stages sample x=1, 1.5, 2x = 1,\ 1.5,\ 2. On the strip 1≤x≤31 \le x \le 3, y∈Ry \in \mathbb{R}, both ff and

∂f∂y=1x(∣∂f∂y∣≤1)\frac{\partial f}{\partial y} = \frac{1}{x}\quad\left(\left|\tfrac{\partial f}{\partial y}\right| \le 1\right)

are continuous and bounded, so ff is Lipschitz in yy. By Picard’s theorem the IVP has a unique solution on [1,3][1,3], and the standard convergence theory for one-step methods applies. Nothing is singular on the interval used.

Step 1 — The exact solution (needed for the comparison, and cheap)

The equation is linear of first order: dydx−1xy=1\dfrac{dy}{dx} - \dfrac{1}{x}y = 1. The integrating factor is

exp⁡(−∫dxx)=1x,\exp\left(-\int \frac{dx}{x}\right) = \frac{1}{x},

so

ddx(yx)=1x⟹yx=log⁡x+C.\frac{d}{dx}\left(\frac{y}{x}\right) = \frac{1}{x} \quad\Longrightarrow\quad \frac{y}{x} = \log x + C .

The condition y(1)=1y(1) = 1 gives 1=0+C1 = 0 + C, i.e. C=1C = 1. Hence

  y(x)=x(1+log⁡x)  \boxed{\;y(x) = x\bigl(1 + \log x\bigr)\;}

Check: y′=1+log⁡x+1=2+log⁡xy' = 1 + \log x + 1 = 2 + \log x, while 1+y/x=1+(1+log⁡x)=2+log⁡x1 + y/x = 1 + (1+\log x) = 2 + \log x. ✓

In particular

y(2)=2(1+log⁡2)=2+2log⁡2=3.3862944,y(2) = 2(1 + \log 2) = 2 + 2\log 2 = 3.3862944 , y(3)=3(1+log⁡3)=3+3log⁡3=6.2958369.y(3) = 3(1 + \log 3) = 3 + 3\log 3 = 6.2958369 .

Note also y′′=1/x>0y'' = 1/x > 0: the exact solution is convex on [1,3][1,3]. This is used in Step 4.

Step 2 — (i) Classical fourth-order Runge–Kutta, one step of size h=1h = 1

The classical RK4 formulae are

k1=hf(xi,yi),k2=hf ⁣(xi+h2, yi+k12),k_1 = h f(x_i, y_i),\qquad k_2 = h f\!\left(x_i + \tfrac{h}{2},\, y_i + \tfrac{k_1}{2}\right), k3=hf ⁣(xi+h2, yi+k22),k4=hf(xi+h, yi+k3),k_3 = h f\!\left(x_i + \tfrac{h}{2},\, y_i + \tfrac{k_2}{2}\right),\qquad k_4 = h f\bigl(x_i + h,\, y_i + k_3\bigr), yi+1=yi+16(k1+2k2+2k3+k4).y_{i+1} = y_i + \tfrac{1}{6}\bigl(k_1 + 2k_2 + 2k_3 + k_4\bigr).

With x0=1x_0 = 1, y0=1y_0 = 1, h=1h = 1, so that x0+h2=1.5x_0 + \tfrac{h}{2} = 1.5 and x0+h=2x_0 + h = 2:

k1k_1:

k1=1⋅f(1, 1)=1+11=2.k_1 = 1\cdot f(1,\,1) = 1 + \frac{1}{1} = 2 .

k2k_2: argument (1.5, 1+k12)=(1.5, 2)\left(1.5,\ 1 + \tfrac{k_1}{2}\right) = (1.5,\ 2),

k2=1⋅f(1.5, 2)=1+23/2=1+43=73=2.3333333.k_2 = 1\cdot f(1.5,\,2) = 1 + \frac{2}{3/2} = 1 + \frac{4}{3} = \frac{7}{3} = 2.3333333 .

k3k_3: argument (1.5, 1+k22)=(1.5, 1+76)=(1.5, 136)\left(1.5,\ 1 + \tfrac{k_2}{2}\right) = \left(1.5,\ 1 + \tfrac{7}{6}\right) = \left(1.5,\ \tfrac{13}{6}\right),

k3=1⋅f ⁣(32, 136)=1+13/63/2=1+139=229=2.4444444.k_3 = 1\cdot f\!\left(\tfrac32,\,\tfrac{13}{6}\right) = 1 + \frac{13/6}{3/2} = 1 + \frac{13}{9} = \frac{22}{9} = 2.4444444 .

k4k_4: argument (2, 1+k3)=(2, 319)\left(2,\ 1 + k_3\right) = \left(2,\ \tfrac{31}{9}\right),

k4=1⋅f ⁣(2, 319)=1+31/92=1+3118=4918=2.7222222.k_4 = 1\cdot f\!\left(2,\,\tfrac{31}{9}\right) = 1 + \frac{31/9}{2} = 1 + \frac{31}{18} = \frac{49}{18} = 2.7222222 .

Combine. Over the common denominator 1818:

k1=3618,2k2=143=8418,2k3=449=8818,k4=4918,k_1 = \frac{36}{18},\qquad 2k_2 = \frac{14}{3} = \frac{84}{18},\qquad 2k_3 = \frac{44}{9} = \frac{88}{18},\qquad k_4 = \frac{49}{18}, k1+2k2+2k3+k4=36+84+88+4918=25718.k_1 + 2k_2 + 2k_3 + k_4 = \frac{36 + 84 + 88 + 49}{18} = \frac{257}{18}.

Therefore

y1=y0+16⋅25718=1+257108=365108.y_1 = y_0 + \frac{1}{6}\cdot\frac{257}{18} = 1 + \frac{257}{108} = \frac{365}{108}. y(2)≈y1=365108=3.3796296.y(2) \approx y_1 = \frac{365}{108} = 3.3796296 .

Step 3 — (ii) Euler’s method

Euler: yi+1=yi+h f(xi,yi)y_{i+1} = y_i + h\,f(x_i, y_i), again with h=1h = 1.

Step 1 (x0=1→x1=2x_0 = 1 \to x_1 = 2):

f(1,1)=1+11=2,y1=1+1⋅2=3.f(1,1) = 1 + \frac{1}{1} = 2,\qquad y_1 = 1 + 1\cdot 2 = 3 . y(2)≈y1=3.y(2) \approx y_1 = 3 .

Step 2 (x1=2→x2=3x_1 = 2 \to x_2 = 3):

f(2,3)=1+32=52,y2=3+1⋅52=112=5.5.f(2,3) = 1 + \frac{3}{2} = \frac{5}{2},\qquad y_2 = 3 + 1\cdot\frac{5}{2} = \frac{11}{2} = 5.5 . y(3)≈y2=5.5.y(3) \approx y_2 = 5.5 .

(Note the second Euler step is started from the computed value y1=3y_1 = 3, not from the exact y(2)y(2) — this is why the error compounds.)

Step 4 — Comparison with the exact solution, and why RK4 wins

xxEuler (h=1h=1)RK4 (h=1h=1)Exact x(1+log⁡x)x(1+\log x)Euler errorRK4 error
223.00000003.0000000365108=3.3796296\dfrac{365}{108} = 3.37962962+2log⁡2=3.38629442 + 2\log 2 = 3.38629440.38629440.38629440.00666470.0066647
33112=5.5000000\dfrac{11}{2} = 5.5000000—3+3log⁡3=6.29583693 + 3\log 3 = 6.29583690.79583690.7958369—

Relative errors at x=2x = 2: Euler 11.41%11.41\%, RK4 0.20%0.20\% — a factor of about 5858 in accuracy for four function evaluations instead of one.

Why RK4 is so much closer. The local truncation errors are

Euler: h22y′′(ξ)=O(h2),RK4: O(h5),\text{Euler: } \tfrac{h^2}{2}y''(\xi) = O(h^2),\qquad \text{RK4: } O(h^5),

so the global orders are O(h)O(h) and O(h4)O(h^4). But note carefully: with h=1h = 1 the powers of hh buy nothing — h2=h5=1h^2 = h^5 = 1. The entire advantage here is structural, not asymptotic. Euler uses a single slope, taken at the left endpoint, and extrapolates it linearly across a whole unit interval; RK4 samples the slope field four times (at x=1, 1.5, 1.5, 2x = 1,\ 1.5,\ 1.5,\ 2) and weights the samples 16(1,2,2,1)\tfrac16(1,2,2,1) — Simpson’s weights — so that its increment reproduces the Taylor expansion of the exact solution through the h4h^4 term instead of only through h1h^1. It is the number of matched Taylor terms, not the smallness of hh, that is doing the work at this step size.

Why both undershoot. Since y′′=1/x>0y'' = 1/x > 0, the solution is convex, so the Euler local error

y(xi+1)−[yi+hf(xi,yi)]=h22y′′(ξ)=12ξ>0y(x_{i+1}) - \bigl[y_i + hf(x_i,y_i)\bigr] = \tfrac{h^2}{2}y''(\xi) = \frac{1}{2\xi} > 0

is positive at every step: each Euler step lands below the curve. Moreover the error is propagated forward with the factor 1+h ∂f/∂y=1+1/xi>01 + h\,\partial f/\partial y = 1 + 1/x_i > 0, so successive deficits reinforce rather than cancel. Euler must therefore undershoot at x=2x=2 and undershoot by more at x=3x=3 — which is exactly what the table shows (3<3.3863 < 3.386, 5.5<6.2965.5 < 6.296). This is a prediction, not a post-hoc observation.

Remark 1 (the Euler iteration in closed form). With h=1h=1 and xn=n+1x_n = n+1, Euler reads yn+1=ynn+2n+1+1y_{n+1} = y_n\dfrac{n+2}{n+1} + 1. Putting yn=(n+1)zny_n = (n+1)z_n gives zn+1=zn+1n+2z_{n+1} = z_n + \dfrac{1}{n+2} with z0=1z_0 = 1, so

yn=(n+1)Hn+1,Hm=∑j=1m1j.y_n = (n+1)H_{n+1},\qquad H_m = \sum_{j=1}^{m}\frac1j .

Compare the exact y(xn)=(n+1)(1+log⁡(n+1))y(x_n) = (n+1)\bigl(1 + \log(n+1)\bigr): Euler has simply replaced log⁡(n+1)=∫1n+1dtt\log(n+1) = \int_1^{n+1}\frac{dt}{t} by its right-endpoint rectangle sum ∑j=2n+11j\sum_{j=2}^{n+1}\frac1j on unit subintervals. Because 1/t1/t is decreasing, that sum underestimates the integral — an independent proof of the undershoot. The exact global error is

En=(n+1)[1−(Hn+1−log⁡(n+1))]  ⟶  (1−γ)(n+1)≈0.4228 xn,E_n = (n+1)\Bigl[1 - \bigl(H_{n+1} - \log(n+1)\bigr)\Bigr] \;\longrightarrow\; (1-\gamma)(n+1)\approx 0.4228\,x_n ,

γ\gamma being Euler’s constant: the error grows linearly and without bound, confirming that h=1h=1 is far too coarse for Euler. (Check: n=1n=1 gives 2[1−(1.5−log⁡2)]=0.38629442[1-(1.5-\log 2)] = 0.3862944 ✓, n=2n=2 gives 3[1−(116−log⁡3)]=0.79583693[1-(\tfrac{11}{6}-\log 3)] = 0.7958369 ✓.)

Remark 2 (RK4 continued to x=3x = 3, for completeness — not asked). A second RK4 step from (2,365108)\left(2,\tfrac{365}{108}\right) gives

k1=581216,k2=31211080,k3=158215400,k4=5027116200,y2=1257200=6.285,k_1 = \tfrac{581}{216},\quad k_2 = \tfrac{3121}{1080},\quad k_3 = \tfrac{15821}{5400},\quad k_4 = \tfrac{50271}{16200},\qquad y_2 = \frac{1257}{200} = 6.285 ,

an error of 0.01083690.0108369 against 6.29583696.2958369 — still 7373 times better than Euler at the same point. Under exam conditions do not compute this: part (i) asks for y(2)y(2) only.

■\qquad\blacksquare

Answer

  RK4 (h=1):k1=2, k2=73, k3=229, k4=4918,y(2)≈365108=3.3796296  \boxed{\;\text{RK4 } (h=1):\quad k_1=2,\ k_2=\tfrac73,\ k_3=\tfrac{22}{9},\ k_4=\tfrac{49}{18},\qquad y(2)\approx \frac{365}{108}=3.3796296\;}   Euler (h=1):y(2)≈3,y(3)≈112=5.5  \boxed{\;\text{Euler } (h=1):\quad y(2)\approx 3,\qquad y(3)\approx \frac{11}{2}=5.5\;}   Exact: y=x(1+log⁡x),y(2)=2+2log⁡2=3.3862944,y(3)=3+3log⁡3=6.2958369  \boxed{\;\text{Exact: } y=x(1+\log x),\quad y(2)=2+2\log 2=3.3862944,\quad y(3)=3+3\log 3=6.2958369\;}
We post more of this — worked solutions, CSAT trap breakdowns, guide chapters — a few times a week on Telegram. Free, no sign-in. Join

This solution is part of the Maths Coverage Map — 14 years, mapped. Get the take-away PDF free.