Menu Close

Numerical solution of ODEs: UPSC Maths Optional PYQ Solutions (2009–2026)

All 9 questions UPSC has asked on numerical solution of ordinary differential equations in the Mathematics Optional (Paper II, Numerical Analysis and Computer Programming) from 2009 to 2026, solved step by step – latest first.

Try them yourself first: the same questions, without solutions, are on our Numerical Analysis and Computer Programming topic-wise PYQs page.

How we check these solutions

These are our own solutions, prepared with AI help. UPSC does not publish official answers. Every solution is checked a second way before it goes up, and says how:

  • ✓ Checked by computer the answer was worked out again independently with Python: each iteration, table or conversion was run again in double precision (or exact fractions), and algorithms were run on test equations.
  • ✓ Proof checked step by step for “prove that” questions, every step was checked against the definitions.

Spotted a mistake or a neater method? Tell us in the comments below or through Report an error.

Jump to a question (year · question number):

2026 · 8b 2023 · 5b 2022 · 8b 2019 · 5d 2015 · 7b 2014 · 6c 2013 · 7b 2012 · 5c 2009 · 7c

Cover of the UPSC Prelims Topic-wise PYQ book with detailed explanations

From the Optional Province team

Preparing for Prelims too?

Our UPSC Prelims Topic-wise PYQ Book covers every Prelims question with detailed explanations, so you can see exactly where UPSC asks from. Now available as a hard copy and an eBook.

Buy Hard Copy on AmazonBuy eBook (PDF)

Download a free sample

Consider the initial value problem : dydx=1+yx, y(1)=1, h=1 (Step-size) (i) Apply the classical fourth order Runge-Kutta method to approximate the solution y(2). (ii) Use Euler’s method to find y(2) and y(3).

2026 · Paper II · Q8b · 15 marks

Solution

Here f(x,y)=1+yxf(x,y)=1+\dfrac yx, x0=1x_0=1, y0=1y_0=1, h=1h=1.

(i) Runge–Kutta (fourth order).

  • k1=hf(1,1)=1+1=2k_1=h\,f(1,\ 1)=1+1=2
  • k2=hf(1.5,2)=1+21.5=2.333333k_2=h\,f(1.5,\ 2)=1+\tfrac{2}{1.5}=2.333333
  • k3=hf(1.5,2.166667)=2.444444k_3=h\,f(1.5,\ 2.166667)=2.444444
  • k4=hf(2,3.444444)=2.722222k_4=h\,f(2,\ 3.444444)=2.722222

y(2)≈1+16(2+4.666667+4.888889+2.722222)=3.3796.\begin{aligned}y(2)&\approx1+\tfrac16(2+4.666667\\ &\qquad+4.888889+2.722222)\\ &=3.3796.\end{aligned}

(ii) Euler’s method, yn+1=yn+hf(xn,yn)y_{n+1}=y_n+h\,f(x_n,y_n):

nn xnx_n yny_n f(xn,yn)f(x_n,y_n) yn+1=yn+hfy_{n+1}=y_n+hf
0 1 1.0000 2.0000 3.0000
1 2 3.0000 2.5000 5.5000

So y(2)≈3y(2)\approx3 and y(3)≈5.5y(3)\approx5.5.

Comparison. The exact solution of this linear equation is y=xlnx+xy=x\ln x+x, giving y(2)=3.3863y(2)=3.3863 and y(3)=6.2958y(3)=6.2958. Even with the large step h=1h=1, RK4 is within about 0.0070.007 of the true y(2)y(2), while Euler’s method is off by about 0.390.39 at x=2x=2 and 0.800.80 at x=3x=3.

✓ Checked by computer We checked by computer: the exact solution is y=xlnx+xy=x\ln x+x, so y(2)=2ln2+2=3.386294y(2)=2\ln2+2=3.386294 and y(3)=3ln3+3=6.295837y(3)=3\ln3+3=6.295837; the RK4 and Euler values are as computed.

↑ Back to the question list

Given dydx=y2−xy2+x with initial condition y=1 at x=0. Find the value of y for x=0.4 by Euler’s method, correct to 4 decimal places, taking step length h=0.1.

2023 · Paper II · Q5b · 10 marks

Solution

f(x,y)=y2−xy2+xf(x,y)=\dfrac{y^2-x}{y^2+x}, x0=0x_0=0, y0=1y_0=1, h=0.1h=0.1. Euler: yn+1=yn+hf(xn,yn)y_{n+1}=y_n+h\,f(x_n,y_n).

nn xnx_n yny_n f(xn,yn)f(x_n,y_n) yn+1=yn+hfy_{n+1}=y_n+hf
0 0.0 1.0000 1.0000 1.1000
1 0.1 1.1000 0.8473 1.1847
2 0.2 1.1847 0.7506 1.2598
3 0.3 1.2598 0.6820 1.3280

y(0.4)≈1.3280.y(0.4)\approx1.3280.

✓ Checked by computer We reran Euler’s method in Python: y(0.4)≈1.3280y(0.4)\approx1.3280. (A fine-step RK4 solution gives y(0.4)≈1.3062y(0.4)\approx1.3062, showing the size of Euler’s error.)

↑ Back to the question list

Using Runge-Kutta method of fourth order, solve the differential equation dydx=x+y2 with y(0)=1, at x=0.2. Use four decimal places for calculation and step length 0.1.

2022 · Paper II · Q8b · 15 marks

Solution

f(x,y)=x+y2f(x,y)=x+y^2, x0=0x_0=0, y0=1y_0=1, h=0.1h=0.1.

The classical fourth-order Runge–Kutta step from (xn,yn)(x_n,y_n) is k1=hf(xn,yn)k2=hf(xn+h2,yn+k12)k3=hf(xn+h2,yn+k22)k4=hf(xn+h,yn+k3)\begin{aligned}k_1&=h\,f(x_n,y_n)\\ 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)\\ k_4&=h\,f(x_n+h,\ y_n+k_3)\end{aligned} yn+1=yn+16(k1+2k2+2k3+k4).y_{n+1}=y_n+\tfrac16(k_1+2k_2+2k_3+k_4).

Step 1: x0=0x_0=0, y0=1.0000y_0=1.0000, so x1=0.1x_1=0.1.

  • k1=hf(x0,y0)=0.1000k_1=h\,f(x_0,y_0)=0.1000
  • k2=hf(x0+h2,y0+k12)=0.1153k_2=h\,f\!\left(x_0+\tfrac h2,\ y_0+\tfrac{k_1}2\right)=0.1153
  • k3=hf(x0+h2,y0+k22)=0.1169k_3=h\,f\!\left(x_0+\tfrac h2,\ y_0+\tfrac{k_2}2\right)=0.1169
  • k4=hf(x0+h,y0+k3)=0.1347k_4=h\,f(x_0+h,\ y_0+k_3)=0.1347

y1=y0+16(k1+2k2+2k3+k4)=1.1165.\begin{aligned}y_1&=y_0+\tfrac16(k_1+2k_2+2k_3+k_4)\\ &=1.1165.\end{aligned}

Step 2: x1=0.1x_1=0.1, y1=1.1165y_1=1.1165, so x2=0.2x_2=0.2.

  • k1=hf(x1,y1)=0.1347k_1=h\,f(x_1,y_1)=0.1347
  • k2=hf(x1+h2,y1+k12)=0.1551k_2=h\,f\!\left(x_1+\tfrac h2,\ y_1+\tfrac{k_1}2\right)=0.1551
  • k3=hf(x1+h2,y1+k22)=0.1576k_3=h\,f\!\left(x_1+\tfrac h2,\ y_1+\tfrac{k_2}2\right)=0.1576
  • k4=hf(x1+h,y1+k3)=0.1823k_4=h\,f(x_1+h,\ y_1+k_3)=0.1823

y2=y1+16(k1+2k2+2k3+k4)=1.2736.\begin{aligned}y_2&=y_1+\tfrac16(k_1+2k_2+2k_3+k_4)\\ &=1.2736.\end{aligned}

So y(0.2)≈1.2736.y(0.2)\approx1.2736.

✓ Checked by computer We checked by computer: the RK4 steps give y(0.1)=1.1165y(0.1)=1.1165, y(0.2)=1.2736y(0.2)=1.2736; a very fine-step solution gives y(0.2)=1.2736y(0.2)=1.2736.

↑ Back to the question list

Using Runge-Kutta method of fourth order, solve dydx=y2−x2y2+x2 with y(0)=1 at x=0.2. Use four decimal places for calculation and step length 0.2.

2019 · Paper II · Q5d · 10 marks

Solution

f(x,y)=y2−x2y2+x2f(x,y)=\dfrac{y^2-x^2}{y^2+x^2}, x0=0x_0=0, y0=1y_0=1, h=0.2h=0.2 (one step).

The classical fourth-order Runge–Kutta step from (xn,yn)(x_n,y_n) is k1=hf(xn,yn)k2=hf(xn+h2,yn+k12)k3=hf(xn+h2,yn+k22)k4=hf(xn+h,yn+k3)\begin{aligned}k_1&=h\,f(x_n,y_n)\\ 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)\\ k_4&=h\,f(x_n+h,\ y_n+k_3)\end{aligned} yn+1=yn+16(k1+2k2+2k3+k4).y_{n+1}=y_n+\tfrac16(k_1+2k_2+2k_3+k_4).

Step 1: x0=0x_0=0, y0=1.0000y_0=1.0000, so x1=0.2x_1=0.2.

  • k1=hf(x0,y0)=0.2000k_1=h\,f(x_0,y_0)=0.2000
  • k2=hf(x0+h2,y0+k12)=0.1967k_2=h\,f\!\left(x_0+\tfrac h2,\ y_0+\tfrac{k_1}2\right)=0.1967
  • k3=hf(x0+h2,y0+k22)=0.1967k_3=h\,f\!\left(x_0+\tfrac h2,\ y_0+\tfrac{k_2}2\right)=0.1967
  • k4=hf(x0+h,y0+k3)=0.1891k_4=h\,f(x_0+h,\ y_0+k_3)=0.1891

y1=y0+16(k1+2k2+2k3+k4)=1.1960.\begin{aligned}y_1&=y_0+\tfrac16(k_1+2k_2+2k_3+k_4)\\ &=1.1960.\end{aligned}

y(0.2)≈1.1960.y(0.2)\approx1.1960.

✓ Checked by computer We checked by computer: one RK4 step gives 1.1960001.196000; a fine-step solution gives y(0.2)=1.1960y(0.2)=1.1960.

↑ Back to the question list

Cover of the UPSC Mains Topic-wise and Year-wise PYQs book (2013–2026)

From the Optional Province team

Strengthen your GS papers

Our UPSC Mains Topic-wise & Year-wise PYQ Book (2013–2026) maps every GS question to the syllabus, so you know what UPSC asks and how often. Now available as a hard copy and an eBook.

Buy Hard Copy on AmazonBuy eBook (PDF)

Download a free sample

Solve the initial value problem dydx=x(y−x), y(2)=3 in the interval [2,2.4] using the Runge-Kutta fourth-order method with step size h=0.2.

2015 · Paper II · Q7b · 15 marks

Solution

f(x,y)=x(y−x)f(x,y)=x(y-x), x0=2x_0=2, y0=3y_0=3, h=0.2h=0.2; two steps reach x=2.4x=2.4.

The classical fourth-order Runge–Kutta step from (xn,yn)(x_n,y_n) is k1=hf(xn,yn)k2=hf(xn+h2,yn+k12)k3=hf(xn+h2,yn+k22)k4=hf(xn+h,yn+k3)\begin{aligned}k_1&=h\,f(x_n,y_n)\\ 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)\\ k_4&=h\,f(x_n+h,\ y_n+k_3)\end{aligned} yn+1=yn+16(k1+2k2+2k3+k4).y_{n+1}=y_n+\tfrac16(k_1+2k_2+2k_3+k_4).

Step 1: x0=2x_0=2, y0=3.0000y_0=3.0000, so x1=2.2x_1=2.2.

  • k1=hf(x0,y0)=0.4000k_1=h\,f(x_0,y_0)=0.4000
  • k2=hf(x0+h2,y0+k12)=0.4620k_2=h\,f\!\left(x_0+\tfrac h2,\ y_0+\tfrac{k_1}2\right)=0.4620
  • k3=hf(x0+h2,y0+k22)=0.4750k_3=h\,f\!\left(x_0+\tfrac h2,\ y_0+\tfrac{k_2}2\right)=0.4750
  • k4=hf(x0+h,y0+k3)=0.5610k_4=h\,f(x_0+h,\ y_0+k_3)=0.5610

y1=y0+16(k1+2k2+2k3+k4)=3.4725.\begin{aligned}y_1&=y_0+\tfrac16(k_1+2k_2+2k_3+k_4)\\ &=3.4725.\end{aligned}

Step 2: x1=2.2x_1=2.2, y1=3.4725y_1=3.4725, so x2=2.4x_2=2.4.

  • k1=hf(x1,y1)=0.5599k_1=h\,f(x_1,y_1)=0.5599
  • k2=hf(x1+h2,y1+k12)=0.6681k_2=h\,f\!\left(x_1+\tfrac h2,\ y_1+\tfrac{k_1}2\right)=0.6681
  • k3=hf(x1+h2,y1+k22)=0.6930k_3=h\,f\!\left(x_1+\tfrac h2,\ y_1+\tfrac{k_2}2\right)=0.6930
  • k4=hf(x1+h,y1+k3)=0.8475k_4=h\,f(x_1+h,\ y_1+k_3)=0.8475

y2=y1+16(k1+2k2+2k3+k4)=4.1608.\begin{aligned}y_2&=y_1+\tfrac16(k_1+2k_2+2k_3+k_4)\\ &=4.1608.\end{aligned}

So y(2.2)≈3.4725y(2.2)\approx3.4725 and y(2.4)≈4.1608.y(2.4)\approx4.1608.

✓ Checked by computer We checked by computer: RK4 with h=0.2h=0.2 gives y(2.2)=3.4725y(2.2)=3.4725, y(2.4)=4.1608y(2.4)=4.1608; a fine-step solution gives y(2.4)=4.1611y(2.4)=4.1611.

↑ Back to the question list

Use Runge-Kutta formula of fourth order to find the value of y at x=0.8, where dydx=x+y, y(0.4)=0.41. Take the step length h=0.2.

2014 · Paper II · Q6c · 20 marks

Solution

f(x,y)=x+yf(x,y)=\sqrt{x+y}, x0=0.4x_0=0.4, y0=0.41y_0=0.41, h=0.2h=0.2; two steps reach x=0.8x=0.8.

The classical fourth-order Runge–Kutta step from (xn,yn)(x_n,y_n) is k1=hf(xn,yn)k2=hf(xn+h2,yn+k12)k3=hf(xn+h2,yn+k22)k4=hf(xn+h,yn+k3)\begin{aligned}k_1&=h\,f(x_n,y_n)\\ 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)\\ k_4&=h\,f(x_n+h,\ y_n+k_3)\end{aligned} yn+1=yn+16(k1+2k2+2k3+k4).y_{n+1}=y_n+\tfrac16(k_1+2k_2+2k_3+k_4).

Step 1: x0=0.4x_0=0.4, y0=0.4100y_0=0.4100, so x1=0.6x_1=0.6.

  • k1=hf(x0,y0)=0.1800k_1=h\,f(x_0,y_0)=0.1800
  • k2=hf(x0+h2,y0+k12)=0.2000k_2=h\,f\!\left(x_0+\tfrac h2,\ y_0+\tfrac{k_1}2\right)=0.2000
  • k3=hf(x0+h2,y0+k22)=0.2010k_3=h\,f\!\left(x_0+\tfrac h2,\ y_0+\tfrac{k_2}2\right)=0.2010
  • k4=hf(x0+h,y0+k3)=0.2201k_4=h\,f(x_0+h,\ y_0+k_3)=0.2201

y1=y0+16(k1+2k2+2k3+k4)=0.6103.\begin{aligned}y_1&=y_0+\tfrac16(k_1+2k_2+2k_3+k_4)\\ &=0.6103.\end{aligned}

Step 2: x1=0.6x_1=0.6, y1=0.6103y_1=0.6103, so x2=0.8x_2=0.8.

  • k1=hf(x1,y1)=0.2200k_1=h\,f(x_1,y_1)=0.2200
  • k2=hf(x1+h2,y1+k12)=0.2384k_2=h\,f\!\left(x_1+\tfrac h2,\ y_1+\tfrac{k_1}2\right)=0.2384
  • k3=hf(x1+h2,y1+k22)=0.2391k_3=h\,f\!\left(x_1+\tfrac h2,\ y_1+\tfrac{k_2}2\right)=0.2391
  • k4=hf(x1+h,y1+k3)=0.2569k_4=h\,f(x_1+h,\ y_1+k_3)=0.2569

y2=y1+16(k1+2k2+2k3+k4)=0.8490.\begin{aligned}y_2&=y_1+\tfrac16(k_1+2k_2+2k_3+k_4)\\ &=0.8490.\end{aligned}

y(0.8)≈0.8490.y(0.8)\approx0.8490.

✓ Checked by computer We checked by computer: RK4 gives y(0.6)=0.6103y(0.6)=0.6103, y(0.8)=0.8490y(0.8)=0.8490; a fine-step solution gives y(0.8)=0.8490y(0.8)=0.8490.

↑ Back to the question list

Use Euler’s method with step size h=0.15 to compute the approximate value of y(0.6), correct up to five decimal places from the initial value problem y′=x(y+x)−2y(0)=2

2013 · Paper II · Q7b · 15 marks

Solution

f(x,y)=x(y+x)−2f(x,y)=x(y+x)-2, x0=0x_0=0, y0=2y_0=2, h=0.15h=0.15; four steps reach x=0.6x=0.6.

nn xnx_n yny_n f(xn,yn)f(x_n,y_n) yn+1=yn+hfy_{n+1}=y_n+hf
0 0.00 2.00000 −2.00000 1.70000
1 0.15 1.70000 −1.72250 1.44162
2 0.30 1.44162 −1.47751 1.22000
3 0.45 1.22000 −1.24850 1.03272

y(0.6)≈1.03272.y(0.6)\approx1.03272. (Euler’s method is only first-order accurate, so this approximates the true solution only roughly; the arithmetic of the method is carried to five decimals as asked.)

✓ Checked by computer We reran Euler’s method in Python: y(0.6)≈1.03272y(0.6)\approx1.03272.

↑ Back to the question list

Provide a computer algorithm to solve an ordinary differential equation dydx=f(x,y) in the interval [a,b] for n number of discrete points, where the initial value is y(a)=α, using Euler’s method.

2012 · Paper II · Q5c · 12 marks

Solution

Euler’s method. Divide [a,b][a,b] into nn equal steps h=(b−a)/nh=(b-a)/n, xi=a+ihx_i=a+ih. Starting from y0=αy_0=\alpha, yi+1=yi+hf(xi,yi),y_{i+1}=y_i+h\,f(x_i,y_i), for i=0,1,…,n−1i=0,1,\dots,n-1. (This follows the tangent line at (xi,yi)(x_i,y_i) for one step; the local error is O(h2)O(h^2), the global error O(h)O(h).)

ALGORITHM  Euler's method for dy/dx = f(x, y), y(a) = alpha, on [a, b]
Input : a, b, alpha, n (number of steps, so there are n+1 points)
1. h = (b - a)/n
2. x = a;  y = alpha
3. Print x, y
4. For i = 1 to n do
       y = y + h*f(x, y)          (Euler step: uses the slope at the left end)
       x = a + i*h                (computed from a to avoid round-off build-up)
       Print x, y
   end for
5. Stop

A program would define f(x, y) as a separate function so that the same algorithm works for any equation.

✓ Checked by computer We ran the algorithm in Python on y′=yy'=y, y(0)=1y(0)=1 on [0,1][0,1]: with n=10n=10 it prints y(1)≈2.593742y(1)\approx2.593742 (=1.110=1.1^{10}), and the error falls roughly in proportion to hh as nn grows.

↑ Back to the question list

Find the value of y(1.2) using Runge-Kutta fourth order method with step size h=0.2 from the initial value problem : y′=xy,y(1)=2.

2009 · Paper II · Q7c · 15 marks

Solution

f(x,y)=xyf(x,y)=xy, x0=1x_0=1, y0=2y_0=2, h=0.2h=0.2 (one step).

The classical fourth-order Runge–Kutta step from (xn,yn)(x_n,y_n) is k1=hf(xn,yn)k2=hf(xn+h2,yn+k12)k3=hf(xn+h2,yn+k22)k4=hf(xn+h,yn+k3)\begin{aligned}k_1&=h\,f(x_n,y_n)\\ 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)\\ k_4&=h\,f(x_n+h,\ y_n+k_3)\end{aligned} yn+1=yn+16(k1+2k2+2k3+k4).y_{n+1}=y_n+\tfrac16(k_1+2k_2+2k_3+k_4).

k1=0.2(1)(2)=0.4000k2=0.2(1.1)(2+0.2)=0.4840k3=0.2(1.1)(2.242)=0.493240k4=0.2(1.2)(2.493240)=0.598378\begin{aligned}k_1&=0.2(1)(2)=0.4000\\ k_2&=0.2(1.1)(2+0.2)=0.4840\\ k_3&=0.2(1.1)(2.242)=0.493240\\ k_4&=0.2(1.2)(2.493240)=0.598378\end{aligned} k1+2k2+2k3+k4=2.952858,k_1+2k_2+2k_3+k_4=2.952858, y(1.2)≈2+2.9528586=2.4921.y(1.2)\approx2+\frac{2.952858}{6}=2.4921. (Exact: y=2e(x2−1)/2y=2e^{(x^2-1)/2}, so y(1.2)=2e0.22=2.4922y(1.2)=2e^{0.22}=2.4922.)

✓ Checked by computer We checked by computer: one RK4 step gives 2.4921432.492143; the exact solution y=2e(x2−1)/2y=2e^{(x^2-1)/2} gives y(1.2)=2e0.22=2.492153y(1.2)=2e^{0.22}=2.492153.

↑ Back to the question list

More on Numerical Analysis and Computer Programming

Questions: UPSC Civil Services (Main) Examination, Mathematics Paper II, 2009–2026. Solutions: Optional Province. Found an error? Tell us.

Spotted an error? Tell us.

We classify every PYQ with care, but mistakes can slip in. If a question is in the wrong topic, has a typo, the wrong year, or is missing, let us know. We review every report and update the page.

Report an Error
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted