Numerical Methods
Level: 3 (Production — from-scratch derivations, code-from-memory, explain-out-loud) Time limit: 45 minutes Total marks: 60
Instructions: Show all derivations from first principles. Where "pseudocode from memory" is requested, write clean, runnable-style pseudocode. Explain reasoning where prompted.
Question 1 — Newton–Raphson from scratch (10 marks)
(a) Starting from a Taylor expansion of about the current iterate , derive the Newton–Raphson update formula. (3)
(b) Let where is a simple root. Prove that the method is quadratically convergent, giving the asymptotic error constant in terms of and . (5)
(c) State one condition under which quadratic convergence is lost, and what convergence order results. (2)
Question 2 — Catastrophic cancellation (10 marks)
(a) Define catastrophic cancellation and explain, in terms of relative error and machine epsilon, why subtracting two nearly-equal numbers is dangerous. (3)
(b) The roots of (with , ) are computed via for the smaller root. Explain why this loses accuracy and give an algebraically equivalent, numerically stable rewrite. (4)
(c) For , , estimate roughly how many significant decimal digits are lost in the naive formula using IEEE 754 double precision ( digits). (3)
Question 3 — Composite Simpson's 1/3 rule (12 marks)
(a) Derive Simpson's 1/3 rule on by integrating the quadratic interpolating polynomial through with equal spacing . (5)
(b) Write the composite Simpson's 1/3 rule formula for subintervals ( even) and state the requirement on . (3)
(c) Apply composite Simpson's 1/3 with to approximate . Give the answer to 5 decimal places. (4)
Question 4 — Iterative solver, code from memory (10 marks)
(a) Write pseudocode from memory for the Gauss–Seidel iteration to solve , including a stopping criterion. (5)
(b) State the diagonal-dominance sufficient condition for convergence and explain in one line why Gauss–Seidel typically converges faster than Jacobi. (3)
(c) For the system perform one Gauss–Seidel sweep starting from . (2)
Question 5 — RK4 and error orders (10 marks)
(a) Write the classical RK4 stage equations and update for , step . (4)
(b) State the local truncation error order and global error order of RK4, and contrast with Euler's method. (3)
(c) Given , , take one RK4 step with to estimate . Give 5 decimal places and the absolute error against . (3)
Question 6 — Condition number & explain-out-loud (8 marks)
(a) Derive the relative condition number of evaluating a differentiable function at , expressing it as . (4)
(b) Explain out loud (in words) the difference between an ill-conditioned problem and an unstable algorithm, and why a stable algorithm cannot rescue an ill-conditioned problem. (4)
Answer keyMark scheme & solutions
Question 1 (10)
(a) Taylor about : . Set , drop quadratic term, solve for : (1 for expansion, 1 for setting & truncating, 1 for formula.)
(b) Write . Expand and around : Since , Substitute (from expanding rearranged) to get Asymptotic constant ; order . (2 for expansion setup, 2 for substitution/cancellation of term, 1 for constant & stating quadratic.)
(c) If (multiple root) quadratic convergence is lost; convergence becomes linear (order 1). (1+1)
Question 2 (10)
(a) Catastrophic cancellation: subtracting two nearly equal floating-point numbers. Each operand already carries relative rounding error (absolute error ). Their difference is small but the absolute errors persist, so the relative error of the difference is magnified by roughly , destroying significant digits. (1 def, 2 explanation.)
(b) : when , , so we subtract nearly-equal quantities → cancellation. Multiply by conjugate: an addition — no cancellation. (2 identify problem, 2 stable form.)
(c) . Cancellation removes digits . Essentially ~16 digits lost — the naive result is worthless (true small root ). Acceptable answer: about 15–16 digits. (3.)
Question 3 (12)
(a) With Lagrange quadratic through the three points and substitution : Derivation: integrate the interpolating polynomial (or Newton forward form) over ; the coefficients emerge. (3 setup/integration, 2 result.)
(b) Composite ( even, ): Requirement: must be even. (2 formula, 1 requirement.)
(c) ; nodes . (True value .) . (2 evaluations, 2 answer.)
Question 4 (10)
(a) Pseudocode:
GaussSeidel(A, b, x0, tol, maxit):
x = x0
for k = 1 to maxit:
x_old = copy(x)
for i = 1 to n:
s = b[i]
for j = 1 to n, j != i:
s = s - A[i][j] * x[j] # uses updated x for j<i
x[i] = s / A[i][i]
if norm(x - x_old) < tol: return x
return x # (or flag non-convergence)
(2 loop structure, 2 in-place update using new values, 1 stopping test.)
(b) Sufficient condition: strictly diagonally dominant, (also converges for SPD ). Gauss–Seidel uses already-updated components within the same sweep, so it incorporates newer information → generally faster than Jacobi. (2 condition, 1 reason.)
(c) . Then . Result: . (2.) (True solution: .)
Question 5 (10)
(a) (2 stages, 2 update.)
(b) RK4 local truncation error ; global error . Euler: local , global . RK4 is 4th-order accurate vs Euler 1st-order. (1 LTE, 1 global, 1 Euler contrast.)
(c) , , : , , , . ; abs error . , error . (2 stages, 1 answer+error.)
Question 6 (8)
(a) Relative condition number = (relative change in output)/(relative change in input): Using . (2 definition, 2 limit/derivative.)
(b) Ill-conditioned problem: inherent property — small input perturbations cause large output changes regardless of method (). Unstable algorithm: the computational procedure introduces/amplifies rounding error beyond what the problem's conditioning warrants. A stable algorithm bounds added error, but the inherent sensitivity still multiplies the unavoidable input rounding — so no algorithm can produce an accurate result for an ill-conditioned problem. (2 distinction, 2 why stability can't rescue.)
[
{"claim":"Composite Simpson n=4 for integral e^{-x^2} on [0,1] ≈ 0.74685",
"code":"h=Rational(1,4);f=lambda x: exp(-x**2);I=h/3*(f(0)+f(1)+4*(f(Rational(1,4))+f(Rational(3,4)))+2*f(Rational(1,2)));result=abs(float(I)-0.74685)<1e-4"},
{"claim":"RK4 one step h=0.5 for y'=y,y0=1 gives 1.648438",
"code":"h=0.5;y=1.0;f=lambda t,y:y;k1=f(0,y);k2=f(0,y+h/2*k1);k3=f(0,y+h/2*k2);k4=f(0,y+h*k3);y1=y+h/6*(k1+2*k2+2*k3+k4);result=abs(y1-1.648438)<1e-5"},
{"claim":"RK4 abs error vs e^0.5 ≈ 2.8e-4",
"code":"h=0.5;y=1.0;k1=y;k2=y+h/2*k1;k3=y+h/2*k2;k4=y+h*k3;y1=y+h/6*(k1+2*k2+2*k3+k4);result=abs(abs(y1-float(exp(Rational(1,2))))-0.000283)<5e-5"},
{"claim":"Gauss-Seidel one sweep gives (0.75,1.6875)",
"code":"x1=(3-0)/4;x2=(6+x1)/4;result=abs(x1-0.75)<1e-12 and abs(x2-1.6875)<1e-12"}
]