← 2014 Paper 2

UPSC 2014 Maths Optional Paper 2 Q7b — Step-by-Step Solution

15 marks · Section B

Algorithms and flowcharts for numerical analysis problems · Numerical Analysis · asked 2× in 13 yrs · Read the full method →

Question

Draw a flowchart for Simpson’s one-third rule.

Technique

Standard composite Simpson’s 1/3 rule implementation; flowchart with input validation, accumulator-loop, and output.

Solution

Algorithm. Composite Simpson’s 1/3 rule approximates abf(x)dx\int_a^b f(x)\,dx using nn subintervals (with nn even) of width h=(ba)/nh=(b-a)/n. The formula is

abf(x)dxh3[f(x0)+f(xn)+4 ⁣i oddf(xi)+2 ⁣i even (interior)f(xi)].\int_a^b f(x)\,dx\approx\dfrac{h}{3}\bigl[f(x_0)+f(x_n)+4\!\sum_{i\text{ odd}}f(x_i)+2\!\sum_{i\text{ even (interior)}}f(x_i)\bigr].

Flowchart (textual ASCII rendering)

┌─────────────┐
│   START     │
└──────┬──────┘

┌────────────────────────────────────────────┐
│ READ:                                      │
│   f(x), a (lower limit), b (upper limit),  │
│   n (even integer, number of subintervals) │
└──────────────────┬─────────────────────────┘

       ┌─────────────────────────┐
       │ IS n EVEN?              │
       └────┬───────────────┬────┘
         No │            Yes│
            ▼               ▼
       ┌──────────┐  ┌──────────────────┐
       │ PRINT:   │  │ Compute h=(b-a)/n│
       │ "n must  │  │ Initialize:      │
       │  be even"│  │   sum = f(a)+f(b)│
       │ STOP     │  │   i = 1          │
       └──────────┘  └────────┬─────────┘

       ┌──────────────────────────────────┐
       │ LOOP: WHILE i ≤ n-1              │
       │   x_i = a + i*h                  │
       │   IF i is ODD:                   │
       │       sum = sum + 4*f(x_i)       │
       │   ELSE (i EVEN):                 │
       │       sum = sum + 2*f(x_i)       │
       │   i = i + 1                      │
       └─────────────┬────────────────────┘

       ┌──────────────────────────────┐
       │ integral = (h/3) * sum       │
       └──────────────┬───────────────┘

       ┌──────────────────────────┐
       │ PRINT integral           │
       └──────────────┬───────────┘

                 ┌────────┐
                 │  STOP  │
                 └────────┘

Verbal description of steps

  1. Input: function f(x)f(x), interval [a,b][a,b], even integer nn.

  2. Validate nn: if odd, abort with error.

  3. Compute step size: h=(ba)/nh=(b-a)/n.

  4. Initialise accumulator: sum=f(a)+f(b)\text{sum}=f(a)+f(b) (endpoint contributions, weight 1).

  5. Loop through interior points i=1,2,,n1i=1,2,\ldots,n-1:

    • Compute xi=a+ihx_i=a+ih.
    • If ii is odd: add 4f(xi)4f(x_i) to sum.
    • If ii is even: add 2f(xi)2f(x_i) to sum.
  6. Combine: integral=h3sum\text{integral}=\dfrac{h}{3}\cdot\text{sum}.

  7. Output the integral value and stop.

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 — 13 years, mapped. Get the take-away PDF free.