The math optional, made finite. Daily Practice

Algorithms and flowcharts for numerical analysis problems

At a Glance

Why This Chapter Matters

Flowchart questions test whether you can translate a numerical integration formula into a procedural algorithm using standard symbols. The 2014 question (15 marks) asks for a Simpson’s 1/3 rule flowchart including the even-nn validation; the 2019 question (10 marks) asks for a trapezoidal rule flowchart and algorithm for a specific integral. Both are entirely formula-to-diagram translations — there is no numerical computation. The key skill is knowing the correct weight pattern for each rule and expressing it as an accumulator loop.

Minimum Theory

Standard flowchart symbols. Oval (rounded rectangle): START/STOP. Rectangle: process (computation or assignment). Diamond: decision (yes/no branch). Parallelogram: input/output (READ/PRINT). Arrows connect the symbols.

Composite trapezoidal rule algorithm. Input a,b,na,b,n. Compute h=(ba)/nh=(b-a)/n. Initialise S=f(a)+f(b)S=f(a)+f(b). Loop i=1i=1 to n1n-1: x=a+ihx=a+ih, SS+2f(x)S\leftarrow S+2f(x). Result: I=(h/2)SI=(h/2)\cdot S.

Composite Simpson’s 1/3 rule algorithm. Input a,b,na,b,n (with nn even). Compute h=(ba)/nh=(b-a)/n. Validate: if nn is odd, stop with error. Initialise S=f(a)+f(b)S=f(a)+f(b). Loop i=1i=1 to n1n-1: if ii is odd add 4f(xi)4f(x_i); if ii is even (interior) add 2f(xi)2f(x_i). Result: I=(h/3)SI=(h/3)\cdot S. Weight pattern: 1,4,2,4,2,,2,4,11,4,2,4,2,\ldots,2,4,1.

Flowchart symbols for numerical integration algorithms

Question Archetypes

ArchetypeRecognition
flowchart-algorithm”Draw a flowchart for [numerical method]”; or “Draw a flowchart and write an algorithm/program for evaluating [integral] by [method]“

flowchart-algorithm (2 question(s); 2014, 2019)

Recognition Cues

Solution Template

  1. State the formula (one line). Identify the weights: endpoints, odd-indexed, even-indexed interior.
  2. Write the algorithm as numbered pseudocode steps (READ, compute hh, initialise sum, loop, multiply, PRINT, STOP).
  3. Draw the flowchart using proper symbols. Include: START \to READ inputs \to compute hh \to initialise sum \to decision (loop condition) \to process (accumulate) \to loop back \to multiply \to PRINT \to STOP.
  4. For Simpson’s: add a validation diamond: “Is nn even?” — branch to error/STOP if not.

Worked Example

2014 Paper 2, 2014-P2-Q7b (15 marks)

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

Formula. abf(x)dxh3[f(x0)+f(xn)+4 ⁣i oddf(xi)+2 ⁣i even, interiorf(xi)]\displaystyle\int_a^b f(x)\,dx \approx \frac{h}{3}\Big[f(x_0)+f(x_n)+4\!\sum_{i\text{ odd}}f(x_i)+2\!\sum_{i\text{ even, interior}}f(x_i)\Big], h=(ba)/nh=(b-a)/n, nn even.

Algorithm (pseudocode):

1.  START
2.  READ f(x), a, b, n
3.  IF n is ODD: PRINT "n must be even"; STOP
4.  h ← (b − a) / n
5.  S ← f(a) + f(b)
6.  i ← 1
7.  WHILE i ≤ n−1:
8.      x_i ← a + i·h
9.      IF i is ODD:  S ← S + 4·f(x_i)
10.     ELSE:         S ← S + 2·f(x_i)
11.     i ← i + 1
12. integral ← (h/3) · S
13. PRINT integral
14. STOP

Flowchart description (symbols):

[START]

[READ: f(x), a, b, n]

<Is n even?>─No─→[PRINT "n must be even"]─→[STOP]
    │ Yes

[h = (b-a)/n;  S = f(a)+f(b);  i = 1]

<i ≤ n−1?>─No─→[I = (h/3)·S]
    │ Yes             ↓
    ↓            [PRINT I]
[x_i = a+i·h]        ↓
    ↓            [STOP]
<i is odd?>─Yes─→[S = S + 4·f(x_i)]
    │ No                  ↓
    ↓              [i = i + 1]─────┐
[S = S + 2·f(x_i)]                │
    ↓                              │
[i = i + 1]────────────────────→(loop back to <i ≤ n−1?>)

2019 Paper 2, 2019-P2-Q5e (10 marks)

Draw a flowchart and write a basic algorithm for evaluating y=06dx1+x2y=\displaystyle\int_0^6\dfrac{dx}{1+x^2} using the trapezoidal rule.

Formula. Ih2[f(x0)+f(xn)+2i=1n1f(xi)]I\approx\dfrac{h}{2}[f(x_0)+f(x_n)+2\sum_{i=1}^{n-1}f(x_i)], f(x)=1/(1+x2)f(x)=1/(1+x^2), a=0a=0, b=6b=6.

Algorithm:

1.  START
2.  READ a=0, b=6, n
3.  h ← (b − a) / n
4.  S ← f(a) + f(b)          [f(x) = 1/(1 + x²)]
5.  FOR i = 1 TO n−1:
6.      x ← a + i·h
7.      S ← S + 2·f(x)
8.  END FOR
9.  y ← (h/2) · S
10. PRINT y
11. STOP

Flowchart (trapezoidal — no even-nn check needed):

[START]

[READ a, b, n]

[h=(b-a)/n;  S=f(a)+f(b);  i=1]

<i ≤ n−1?>─No─→[y = (h/2)·S]
    │ Yes             ↓
    ↓            [PRINT y]
[x = a+i·h]          ↓
[S = S+2·f(x)]   [STOP]
[i = i+1]

(loop back to <i ≤ n−1?>)

Common Traps

Marks-Aware Writing

A 15-mark flowchart answer must show all standard symbols used correctly (oval for start/stop, diamond for decisions, rectangle for processes), all variable assignments visible, the validation step (for Simpson’s), the loop structure with correct bounds, and the final formula. A 10-mark answer must show the pseudocode algorithm plus a flowchart; the code listing alone without the diagram does not satisfy the question.

Practice Set

We've mapped all 13 years of this exam. Get new chapters, tools, and solutions as we release them — free.