---
title: Problem set 12
heading: "Problem set 12: numerical methods across the course"
eyebrow: A13 · Problem set 12
type: problems
---

::: hook
These problems mix the whole course, including the FFT, Monte Carlo and sparse matrices from lessons 47 to 49. Several combine two ideas, the way a real computation does: an error estimate and a cost, a conditioning and a stability.
:::

::: pool
pick: 12

::: check
kind: parts
given: x = 3000 | 0.04; p = 24 | 53

## Spacing and epsilon.

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

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

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

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

### What's the best central-difference step in a {p}-bit format?

::: misses
- [any] $\varepsilon^{1/3}$.
:::
:::
:::

::: check
kind: parts
given: d = 0.0001 | 0.000001; k = 5 | 9

## Cancellation and conditioning.

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

### About how many digits does $(1 + \given{d}) - 1$ lose?

::: misses
- [any] $\log_{10}\frac{a + b}{a - b}$.
:::
:::

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

### Least squares by the normal equations with $\kappa(A) = 10^{\given{k}}$: digits left?

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

::: check
kind: parts
given: W = 1 | 10; d = 0.000001 | 0.000000001; r = 0.3 | 0.8

## Root finding.

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

### Bisection steps from a bracket {W} wide to within {d}?

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

::: part
answer: 12/log(1/r)
tolerance: 1%

### A linear iteration with rate {r}: steps for 12 digits?

::: misses
- [any] $12/\log_{10}(1/\rho)$.
:::
:::
:::

::: check
kind: parts
given: a = 6 | 15; x0 = 2 | 3; m = 3 | 5

## Newton's method.

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

### One step toward $\sqrt{\given{a}}$ from {x0}?

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

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

### Its rate at a root of multiplicity {m}?

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

::: check
kind: parts
given: N = 256 | 4096; n = 6 | 12; i = 1 | 3

## Tables and nodes.

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

### Worst linear-interpolation error of an {N}-entry sine table?

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

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

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

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

::: check
kind: parts
given: b = 2 | 3; c = 1.5 | 2.5

## Quadrature.

::: 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$.
:::
:::

::: part
answer: exp(-c/sqrt(3)) + exp(c/sqrt(3))
tolerance: 0.001%

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

::: misses
- [any] $f(-1/\sqrt3) + f(1/\sqrt3)$.
:::
:::
:::

::: check
kind: parts
given: n = 3000 | 20000; g = 100 | 1000; k = 5 | 9

## Dense and sparse storage.

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

### LU of a dense {n} × {n} matrix at {g} GFLOP/s?

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

::: part
answer: (12*k*n + 4*n)/1e6
unit: MB
tolerance: 1%

### CSR storage with {k} nonzeros per row?

::: misses
- [any] $12\,\text{nnz} + 4n$ bytes.
:::
:::
:::

::: check
kind: parts
given: N = 64 | 256; d = 6 | 10; k = 900 | 90000

## Iterative solvers.

::: part
answer: d*ln(10)/(-ln(2/(1 + sin(pi/N)) - 1))
tolerance: 1%

### SOR sweeps at $\omega_{opt}$ for an {N} × {N} grid, {d} digits?

::: misses
- [any] $\rho = \omega_{opt} - 1$.
:::
:::

::: part
answer: sqrt(k)/2*ln(2*10^d)
tolerance: 2%

### CG steps for κ = {k}, {d} digits?

::: misses
- [any] $\frac{\sqrt\kappa}{2}\ln\frac2\varepsilon$.
:::
:::
:::

::: check
kind: parts
given: a = 3 | 6; b = 1 | 2; d = 1 | 2

## The matrix ({a}, {b}; {b}, {d}).

::: part
answer: (a + d + sqrt((a - d)^2 + 4*b^2))/2
tolerance: 0.1%

### Its larger eigenvalue?

::: misses
- [any] From the trace and determinant.
:::
:::

::: part
answer: b*(a*d - b^2)/(a^2 + b^2)
tolerance: 0.1%

### Its off-diagonal after one unshifted QR step?

::: misses
- [any] $\frac{b(ad - b^2)}{a^2 + b^2}$.
:::
:::
:::

::: check
kind: parts
given: k = 5 | 40; h = 0.01 | 0.03; t = 2 | 0.5

## Steps and stiffness.

::: part
answer: 1 - k*h
tolerance: 0.01%

### One Euler step on $\dot y = -\given{k}y$ from 1 with h = {h}?

::: misses
- [any] $1 - kh$.
:::
:::

::: part
answer: 1/(1 + 100/t)
tolerance: 0.5%

### Backward Euler's factor for a mode with τ = {t} µs at h = 100 µs?

::: misses
- [any] $\frac{1}{1 + h/\tau}$.
:::
:::
:::

::: check
kind: parts
given: p = 10 | 20; L = 1500 | 3000; M = 100 | 600

## FFTs.

::: part
answer: 2*2^p/p
tolerance: 0.5%

### Speedup of a $2^{\given{p}}$-point FFT over a direct DFT?

::: misses
- [any] $2N/\log_2N$.
:::
:::

::: part
answer: 2^ceil(ln(L + M - 1)/ln(2))
tolerance: 0

### Power-of-two length to convolve {L} samples with {M} taps?

::: misses
- [any] Round $L + M - 1$ up.
:::
:::
:::

::: check
kind: parts
given: s = 0.3 | 2; e = 0.001 | 0.0001; Y = 0.9 | 0.97; N = 2000 | 20000

## Monte Carlo.

::: part
answer: (s/e)^2
tolerance: 0.5%

### Samples for a standard error of {e} with s = {s}?

::: misses
- [any] $(s/\varepsilon)^2$.
:::
:::

::: part
answer: sqrt(Y*(1 - Y)/N)
tolerance: 0.5%

### Standard error of a yield of {Y} from {N} trials?

::: misses
- [any] $\sqrt{Y(1 - Y)/N}$.
:::
:::
:::

::: check
kind: parts
given: e = 0.0001 | 0.0005 | 0.001 | 0.002 | 0.005 | 0.01

## The constant term of $(x - 1)(x - 2)(x - 3)$ changes by {e}.

::: part
answer: -e/2
tolerance: 1%

### About how far does the root at 3 move?

::: misses
- [e/2] $\delta r \approx -\delta/p'(r)$.
- [any] $p'(3) = 2$.
:::
:::
:::

::: check
kind: parts
given: e = 0.2 | 0.5 | 0.8

## A Chebyshev low-pass filter has ripple factor ε = {e}.

::: part
answer: 10*log(1 + e^2)
unit: dB
tolerance: 0.5%

### What is its passband ripple?

::: misses
- [any] $10\log_{10}(1 + \varepsilon^2)$.
:::
:::
:::

::: check
kind: parts
given: N = 50 | 100 | 200 | 500 | 1000 | 2000

## The 2D model problem on an {N} × {N} grid is solved by CG to $10^{-6}$.

::: part
answer: (N + 1)/pi*ln(2e6)
tolerance: 1%

### About how many steps does it take?

::: misses
- [any] $\frac{\sqrt\kappa}{2}\ln\frac2\varepsilon$ with $\sqrt\kappa = \frac{2(N + 1)}{\pi}$.
:::
:::
:::
:::
