---
title: Problem set 10
heading: "Problem set 10: FFTs, Monte Carlo and sparse matrices"
eyebrow: A13 · Problem set 10
type: problems
---

::: hook
These problems use lessons 47 to 49: the FFT as an algorithm and its practical use, Monte Carlo integration and yield with variance reduction, and sparse matrix storage and solvers. Many are about cost: counting operations, samples or bytes before you commit to a computation.
:::

::: pool
pick: 12

::: check
kind: parts
given: p = 10 | 16 | 20

## A radix-2 FFT has $N = 2^{\given{p}}$ points.

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

### How many butterflies (complex multiplications) does it take?

::: misses
- [2^p*p] Each stage has N/2 butterflies.
- [any] $\frac N2\log_2N$.
:::
:::

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

### How many times fewer than a direct DFT's $N^2$?

::: misses
- [any] $\frac{N^2}{(N/2)\log_2N} = \frac{2N}{\log_2N}$.
:::
:::
:::

::: check
kind: parts
given: L = 1000 | 4000; M = 100 | 300

## Convolve {L} samples with an {M}-tap filter by FFT.

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

### What is the smallest power-of-two FFT length that avoids wraparound?

::: misses
- [2^ceil(log(L)/log(2))] The result has $L + M - 1$ samples.
- [any] At least $L + M - 1$.
:::
:::
:::

::: check
kind: parts
given: fs = 8000 | 44100; N = 512 | 4096

## A record of {N} samples at {fs} Hz.

::: part
answer: fs/N
unit: Hz
tolerance: 0.5%

### What is the FFT's bin spacing?

::: misses
- [any] $f_s/N$.
:::
:::

::: part
answer: N/fs*1000
unit: ms
tolerance: 0.5%

### How long is the record?

::: misses
- [any] $N/f_s$.
:::
:::
:::

::: check
kind: parts
given: N = 8 | 16 | 32; k = 1 | 3

## The twiddle factor $W_N^k = e^{-j2\pi k/N}$, with N = {N} and k = {k}.

::: part
answer: cos(2*pi*k/N)
tolerance: 0.5%

### What is its real part?

::: misses
- [any] $\cos\frac{2\pi k}{N}$.
:::
:::

::: part
answer: -sin(2*pi*k/N)
tolerance: 0.5%

### What is its imaginary part?

::: misses
- [sin(2*pi*k/N)] The exponent is negative.
- [any] $-\sin\frac{2\pi k}{N}$.
:::
:::
:::

::: check
kind: parts
given: s = 0.5 | 2; e = 0.01 | 0.001

## A Monte Carlo integrand has standard deviation {s}.

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

### How many samples bring the standard error to {e}?

::: misses
- [s/e] The error falls as $1/\sqrt N$.
- [any] $N = (\sigma/\varepsilon)^2$.
:::
:::

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

### How many for an error ten times smaller?

::: misses
- [10*(s/e)^2] Ten times smaller needs a hundred times more samples.
- [any] Multiply by 100.
:::
:::
:::

::: check
kind: parts
given: Y = 0.95 | 0.99; N = 1000 | 10000

## A yield simulation passes a fraction {Y} of {N} trials.

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

### What is the yield's standard error?

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

::: check
kind: parts
given: p = 0.001 | 0.0001; r = 0.1 | 0.03

## You estimate a failure probability near {p} by simulation.

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

### How many trials give a relative error of {r}?

::: misses
- [1/(p*r)] The count goes as $\frac{1}{pr^2}$.
- [any] $\frac{1 - p}{pr^2}$.
:::
:::
:::

::: check
kind: parts
given: V = 0.242 | 0.5; C = -0.2 | -0.4

## Antithetic pairs: each sample has variance {V}, and the halves of a pair have covariance {C}.

::: part
answer: (V + C)/2
tolerance: 0.5%

### What is the variance of the pair average?

::: misses
- [V/2] Include the covariance.
- [any] $\frac{V + C}{2}$.
:::
:::
:::

::: check
kind: parts
given: d = 2 | 5 | 10; p = 2 | 4

## A grid rule of order {p} is used in {d} dimensions.

::: part
answer: -p/d
tolerance: 0.5%

### Its error goes as $N^q$ in the total number of points. What is q?

::: misses
- [-p] With N points spread over d dimensions, the spacing is $N^{-1/d}$.
- [any] $h \propto N^{-1/d}$ and error $\propto h^p$.
:::
:::

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

### Monte Carlo's error goes as $N^{-1/2}$. The grid rule wins when $\frac pd$ exceeds ½; what is $\frac{p/d}{1/2}$ here?

::: misses
- [any] $\frac{2p}{d}$: above 1 the grid rule wins.
:::
:::
:::

::: check
kind: parts
given: n = 1000000 | 10000000; k = 5 | 7

## A sparse matrix has {n} rows with {k} nonzeros each, stored in CSR (8-byte values, 4-byte indices).

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

### How much memory does it take?

::: misses
- [8*n*n/1e6] That's the dense matrix.
- [any] $12nk + 4(n + 1)$ bytes.
:::
:::

::: part
answer: 2*n*k
tolerance: 0.5%

### How many operations does a matrix–vector product take?

::: misses
- [any] One multiply and one add per nonzero.
:::
:::
:::

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

## A 2D grid of {N} × {N} unknowns is numbered row by row.

::: part
answer: N
tolerance: 0

### What is the matrix's bandwidth?

::: misses
- [N^2] The farthest neighbor is one row away: N positions.
- [any] The vertical neighbor's offset.
:::
:::

::: part
answer: 2*N^2*N^2
tolerance: 0.5%

### About how many operations does banded LU take, $2nb^2$?

::: misses
- [any] $n = N^2$ and $b = N$.
:::
:::
:::

::: check
kind: parts
given: n = 100 | 500 | 1000 | 5000 | 10000 | 100000

## An arrow matrix has a hub row and column connected to all {n} − 1 other unknowns, which connect only to the hub.

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

### If the hub is eliminated first, about how many new nonzeros (fill) appear?

::: misses
- [0] Eliminating the hub couples every pair of its neighbors.
- [any] Every pair of the other unknowns becomes connected.
:::
:::

::: part
answer: 0
tolerance: 0

### And if it's eliminated last?

::: misses
- [any] Eliminating a leaf touches only the hub, which is already connected.
:::
:::
:::

::: check
kind: parts
given: p = 10 | 12; M = 101 | 513; L = 100000 | 1000000

## An {M}-tap filter is applied to {L} samples by overlap-add with FFT blocks of $2^{\given{p}}$ points.

::: part
answer: 2^p - M + 1
tolerance: 0

### How many new output samples does each block produce?

::: misses
- [2^p] Each block's input can be only $N - M + 1$ samples long, or its convolution would wrap around.
- [any] $N - M + 1$.
:::
:::

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

### How many blocks does the whole signal take?

::: misses
- [any] Divide the length by the samples per block and round up.
:::
:::
:::

::: check
kind: parts
given: s = 1 | 3; t = 0.2 | 0.5

## Stratified sampling splits [0, 1] into strata; the integrand's standard deviation is {s} overall but {t} within each stratum.

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

### By about what factor does that cut the number of samples needed?

::: misses
- [s/t] Sample counts go as the variance.
- [any] $(\sigma/\sigma_\text{strata})^2$.
:::
:::
:::

::: check
kind: parts
given: N = 64 | 256; f = 3 | 10

## A smooth periodic signal is sampled N = {N} times per period. Its derivative is wanted at the samples.

::: part
answer: 2*pi*f
tolerance: 0.5%

### Spectrally, differentiation multiplies harmonic {f} by $j\omega$. What is ω for that harmonic, per period of $2\pi$?

::: misses
- [f] Harmonic f has angular frequency $2\pi f$ per unit period.
- [any] $\omega = 2\pi f$.
:::
:::
:::
:::
