---
title: Midterm exam
heading: "Midterm exam: numerical methods"
eyebrow: A13 · Midterm exam
type: problems
---

::: hook
Twelve problems from the first half of the course: floating point and rounding, conditioning and stability, root finding, interpolation and splines, numerical differentiation, quadrature, and Gaussian elimination. Give yourself two hours, work without the lessons open, and write out your reasoning before checking each answer. "Another set" deals a different exam.
:::

::: pool
pick: 12

::: check
kind: parts
given: x = 20 | 700; p = 24 | 53

## Floating point.

::: part
answer: 2^(floor(ln(x)/ln(2)) - 52)
tolerance: 0.5%

### What's the spacing between doubles near {x}?

::: misses
- [any] $2^{\lfloor\log_2x\rfloor - 52}$.
:::
:::

::: part
answer: 2^(1 - p)
tolerance: 0.5%

### What's the machine epsilon of a {p}-bit format?

::: misses
- [any] $2^{1-p}$.
:::
:::
:::

::: check
kind: parts
given: d = 0.001 | 0.0001 | 0.00001 | 0.000001 | 0.0000001 | 0.00000001

## Subtracting 1 from 1 + {d}.

::: part
answer: (2 + d)/d
tolerance: 1%

### By what factor does the relative error grow?

::: misses
- [any] $(a + b)/(a - b)$.
:::
:::

::: part
answer: log((2 + d)/d)
tolerance: 1%

### About how many digits are lost?

::: misses
- [any] $\log_{10}$ of the factor.
:::
:::
:::

::: check
kind: parts
given: b = 2000000 | 50000000; c = 3 | 8

## $x^2 - \given{b}x + \given{c} = 0$.

::: part
answer: 2*c/(b + sqrt(b^2 - 4*c))
tolerance: 0.5%

### What's the small root, computed without cancellation?

::: misses
- [any] $\frac{2c}{b + \sqrt{b^2 - 4c}}$.
:::
:::

::: part
answer: b
tolerance: 0.5%

### What's the large root, to three significant figures?

::: misses
- [any] Nearly b.
:::
:::
:::

::: check
kind: parts
given: x = 1.5 | 3; y = 8 | 30

## Condition numbers.

::: part
answer: 1/abs(ln(x))
tolerance: 0.5%

### What's κ of $\ln x$ at x = {x}?

::: misses
- [any] $1/\lvert\ln x\rvert$.
:::
:::

::: part
answer: y^y/y!
tolerance: 1%

### How large is the biggest term of the series for $e^{-\given{y}}$?

::: misses
- [any] $y^y/y!$.
:::
:::
:::

::: check
kind: parts
given: W = 2 | 6; d = 0.00001 | 0.000000001; c = 2 | 4

## Simple iterations.

::: part
answer: ceil(ln(W/d)/ln(2) - 1)
tolerance: 0

### How many bisection steps get within {d} of a root bracketed {W} wide?

::: misses
- [any] Smallest n with $W/2^{n+1} \le \delta$.
:::
:::

::: part
answer: 1/((c + sqrt(c^2 + 4))/2)^2
tolerance: 0.5%

### By what factor does $x \leftarrow \given{c} + 1/x$ shrink the error each step?

::: misses
- [any] $1/x^{*2}$.
:::
:::
:::

::: check
kind: parts
given: a = 5 | 13; x0 = 2 | 4

## Newton's method for $\sqrt{\given{a}}$ from {x0}.

::: part
answer: (x0 + a/x0)/2
tolerance: 0.01%

### What's $x_1$?

::: misses
- [any] $\frac12(x_0 + a/x_0)$.
:::
:::

::: part
answer: 0.5/sqrt(a)*((x0 + a/x0)/2 - sqrt(a))^2
tolerance: 2%

### Using $e_{n+1} \approx \frac{e_n^2}{2\sqrt a}$, what's the predicted error of $x_2$?

::: misses
- [any] $C = f''/(2f') = 1/(2\sqrt a)$ times $e_1^2$.
:::
:::
:::

::: check
kind: parts
given: m = 3 | 5; a = 1 | 2; q = 1.5 | 3; let e0 = 10^(-a); let e1 = 10^(-a*q); let e2 = 10^(-a*q^2)

## Rates.

::: part
answer: (m - 1)/m
tolerance: 0.5%

### Newton's rate at a root of multiplicity {m}?

::: misses
- [any] $(m - 1)/m$.
:::
:::

::: part
answer: ln(e2/e1)/ln(e1/e0)
tolerance: 1%

### A run's errors are {e0}, {e1}, {e2}. What's its order?

::: misses
- [any] $\frac{\ln(e_2/e_1)}{\ln(e_1/e_0)}$.
:::
:::
:::

::: check
kind: parts
given: a = 1 | 4; b = 2 | 7; c = 3 | 5

## The points (0, {a}), (1, {b}), (2, {c}).

::: part
answer: -0.125*a + 0.75*b + 0.375*c
tolerance: 0.1%

### What's the interpolating quadratic at 1.5?

::: misses
- [any] Lagrange weights at 1.5: −0.125, 0.75, 0.375.
:::
:::

::: part
answer: 1.5*(a - 2*b + c)
tolerance: 0.1%

### What's $M_1$ for the natural spline through them?

::: misses
- [any] $4M_1 = 6(a - 2b + c)$.
:::
:::
:::

::: check
kind: parts
given: n = 5 | 9; i = 1 | 2; N = 100 | 2048

## Nodes and tables.

::: part
answer: cos((2*i + 1)*pi/(2*(n + 1)))
tolerance: 0.1%

### What's Chebyshev node $x_{\given{i}}$ for n = {n}?

::: misses
- [any] $\cos\frac{(2i + 1)\pi}{2(n + 1)}$.
:::
:::

::: part
answer: (2*pi/N)^2/8
tolerance: 0.5%

### What's the worst linear-interpolation error of an {N}-entry sine table?

::: misses
- [any] $(2\pi/N)^2/8$.
:::
:::
:::

::: check
kind: parts
given: x = 2 | 3; h = 0.25 | 0.5

## Differences of $x^3$ at {x} with h = {h}.

::: part
answer: 3*x^2 + 3*x*h + h^2
tolerance: 0.01%

### Forward difference?

::: misses
- [any] $3x^2 + 3xh + h^2$.
:::
:::

::: part
answer: 3*x^2 + h^2
tolerance: 0.01%

### Central difference?

::: misses
- [any] $3x^2 + h^2$.
:::
:::
:::

::: check
kind: parts
given: p = 24 | 53; s = 2 | 5; h = 4 | 25

## Steps and noise.

::: part
answer: sqrt(2^(1 - p))
tolerance: 1%

### About what's the best forward-difference step in a {p}-bit format?

::: misses
- [any] $\sqrt\varepsilon$.
:::
:::

::: part
answer: sqrt(2)*s/h*1000
unit: V/s
tolerance: 0.5%

### Samples with {s} mV of noise, {h} µs apart: how noisy is their difference quotient?

::: misses
- [any] $\sqrt2\,\sigma/h$.
:::
:::
:::

::: check
kind: parts
given: n = 4 | 8; b = 2 | 3

## Integration rules.

::: part
answer: 1/3 + 1/(6*n^2)
tolerance: 0.01%

### Trapezoid with {n} intervals for $\int_0^1x^2\,dx$?

::: misses
- [any] $\frac13 + \frac{1}{6n^2}$.
:::
:::

::: part
answer: 5*b^5/24
tolerance: 0.01%

### One-panel Simpson for $\int_0^{\given{b}}x^4\,dx$?

::: misses
- [any] $5b^5/24$.
:::
:::
:::

::: check
kind: parts
given: c = 1.5 | 3; k = 4 | 8

## Gaussian quadrature.

::: part
answer: 5/9*(exp(-c*sqrt(0.6)) + exp(c*sqrt(0.6))) + 8/9
tolerance: 0.001%

### 3-point Gauss for $\int_{-1}^1e^{\given{c}x}\,dx$?

::: misses
- [any] $\frac59(e^{-c\sqrt{0.6}} + e^{c\sqrt{0.6}}) + \frac89$.
:::
:::

::: part
answer: 2*(1/3)^(k/2)
tolerance: 0.1%

### 2-point Gauss for $\int_{-1}^1x^{\given{k}}\,dx$?

::: misses
- [any] $2(1/3)^{k/2}$.
:::
:::
:::

::: check
kind: parts
given: S1 = 2.1 | 0.48; S2 = 2.05 | 0.5; j = 2 | 3

## Adaptive and Romberg.

::: part
answer: S2 + (S2 - S1)/15
tolerance: 0.01%

### Simpson gives {S1} on an interval and {S2} on its halves. Corrected estimate?

::: misses
- [any] $S_2 + (S_2 - S_1)/15$.
:::
:::

::: part
answer: 2*j + 2
tolerance: 0

### Error order of Romberg column {j}?

::: misses
- [any] $2j + 2$.
:::
:::
:::

::: check
kind: parts
given: n = 2500 | 12000; g = 40 | 400; k = 9 | 13

## Dense systems.

::: part
answer: 2*n^3/3/(g*1e9)
unit: s
tolerance: 1%

### How long does LU of a {n} × {n} matrix take at {g} GFLOP/s?

::: misses
- [any] $\frac23n^3$ over the rate.
:::
:::

::: part
answer: 15.95 - k
tolerance: 1%

### With $\kappa = 10^{\given{k}}$, about how many digits can you trust?

::: misses
- [any] $15.95 - \log_{10}\kappa$.
:::
:::
:::

::: check
kind: parts
given: u1 = 3 | -2; u2 = 2 | 5; u3 = 4 | 0.5; p = 1 | 2

## $PA = LU$ took {p} row swaps, and U's diagonal is {u1}, {u2}, {u3}.

::: part
answer: (-1)^p*u1*u2*u3
tolerance: 0.5%

### What is $\det A$?

::: misses
- [any] $(-1)^p\prod u_{ii}$.
:::
:::
:::
:::
