---
title: Problem set 5
heading: "Problem set 5: integration and direct solvers"
eyebrow: A13 · Problem set 5
type: problems
---

::: hook
These problems use lessons 17 to 23: the trapezoid and Simpson rules, Gaussian quadrature, adaptive and Romberg integration, and Gaussian elimination with its cost and accuracy.
:::

::: pool
pick: 12

::: check
kind: parts
given: n = 2 | 5 | 8

## $\int_0^1x^2\,dx$ with {n} intervals.

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

### What does the trapezoid rule give?

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

::: part
answer: 1/(6*n^2)
tolerance: 0.5%

### What's its error?

::: misses
- [any] $\frac{(b - a)h^2}{12}f''$.
:::
:::
:::

::: check
kind: parts
given: dt = 2 | 5; a = 20 | 60; c = 50 | 90

## Power samples {dt} ms apart: 0, {a}, {c}, {a}, 0 W.

::: part
answer: dt/1000*(2*a + c)
unit: J
tolerance: 0.5%

### What energy does the trapezoid rule give?

::: misses
- [any] Inner samples count fully, end samples half.
:::
:::

::: part
answer: dt/1000*(8*a + 2*c)/3
unit: J
tolerance: 0.5%

### What does Simpson's rule give?

::: misses
- [any] $\frac h3(f_0 + 4f_1 + 2f_2 + 4f_3 + f_4)$.
:::
:::
:::

::: check
kind: parts
given: b = 0.5 | 1 | 1.5 | 2 | 3 | 4

## $\int_0^{\given{b}}x^4\,dx$.

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

### What does one-panel Simpson give?

::: misses
- [any] $\frac b6\left(4(b/2)^4 + b^4\right)$.
:::
:::

::: part
answer: (b/2)*((b/2*(1 - 1/sqrt(3)))^4 + (b/2*(1 + 1/sqrt(3)))^4)
tolerance: 0.01%

### What does 2-point Gauss give?

::: misses
- [any] Nodes at $\frac b2(1 \pm 1/\sqrt3)$, weight $\frac b2$ each.
:::
:::
:::

::: check
kind: parts
given: L = 1 | 4; n = 10 | 40; M = 2 | 6

## Error bounds with $\lvert f''\rvert \le$ {M} and $\lvert f^{(4)}\rvert \le$ {M} on an interval of length {L}, {n} intervals.

::: part
answer: L^3*M/(12*n^2)
tolerance: 0.5%

### What's the trapezoid rule's bound?

::: misses
- [any] $\frac{(b - a)h^2}{12}M$.
:::
:::

::: part
answer: L^5*M/(180*n^4)
tolerance: 0.5%

### What's Simpson's bound?

::: misses
- [any] $\frac{(b - a)h^4}{180}M$.
:::
:::
:::

::: check
kind: parts
given: k = 4 | 6; n = 3 | 7

## Gauss–Legendre rules.

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

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

::: misses
- [any] $2(1/\sqrt3)^k$.
:::
:::

::: part
answer: 2*n - 1
tolerance: 0

### Through what degree is the {n}-point rule exact?

::: misses
- [any] $2n - 1$.
:::
:::
:::

::: check
kind: parts
given: c = 0.5 | 1 | 1.5 | 2 | 2.5 | 3

## $\int_{-1}^1e^{\given{c}x}\,dx$.

::: part
answer: 2*sinh(c)/c
tolerance: 0.001%

### What's the exact value?

::: misses
- [any] $\frac{e^c - e^{-c}}{c}$.
:::
:::

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

### What does 2-point Gauss give?

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

::: check
kind: parts
given: S1 = 0.9 | 1.6; S2 = 0.95 | 1.58; e = 0.00001 | 0.001

## Adaptive Simpson on one interval gives $S_1$ = {S1} and $S_2$ = {S2}.

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

### What's the corrected estimate?

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

::: part
answer: 15*e
tolerance: 0.5%

### With tolerance {e}, below what $\lvert S_2 - S_1\rvert$ is the interval accepted?

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

::: check
kind: parts
given: j = 1 | 3; N = 16 | 400

## Romberg and singular integrands.

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

### Romberg column {j} has error $O(h^p)$. What's p?

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

::: part
answer: -0.2078862*N^(-1.5)
tolerance: 3%

### About what's the trapezoid error on $\int_0^1\sqrt x\,dx$ with {N} intervals?

::: misses
- [any] $-0.2079N^{-1.5}$.
:::
:::
:::

::: check
kind: parts
given: n = 1500 | 6000; g = 50 | 200

## A dense {n} × {n} system on a {g} GFLOP/s machine.

::: part
answer: 2*n^3/3
tolerance: 1%

### How many operations does LU take?

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

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

### How long does it take?

::: misses
- [any] Operations divided by the rate.
:::
:::
:::

::: check
kind: parts
given: n = 800 | 3000; k = 50 | 5000

## One LU factorization reused for {k} right-hand sides, n = {n}.

::: part
answer: 2*n^3/3 + 2*k*n^2
tolerance: 1%

### How many operations in all?

::: misses
- [any] $\frac23n^3 + 2kn^2$.
:::
:::

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

### How many times more would refactoring for every right-hand side cost?

::: misses
- [any] $k(\frac23n^3 + 2n^2)$ divided by the reuse cost.
:::
:::
:::

::: check
kind: parts
given: n = 20000 | 100000; k = 7 | 12

## Storage and accuracy.

::: part
answer: 8*n^2*1e-9
unit: GB
tolerance: 1%

### How much memory does a dense {n} × {n} matrix of doubles need?

::: misses
- [any] 8 bytes per entry.
:::
:::

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

### With $\kappa = 10^{\given{k}}$, about how many correct digits does a stable solve give?

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

::: check
kind: parts
given: N = 8 | 16; s = 10 | 30

## Periodic signals.

::: part
answer: 0.5
tolerance: 0.001%

### What's $\frac1N\sum_{k=0}^{N-1}\sin^2\frac{2\pi k}{N}$ for N = {N}?

::: misses
- [any] Over a whole period the trapezoid rule is exact for low harmonics.
:::
:::

::: part
answer: s/sqrt(2)
unit: V
tolerance: 0.1%

### A sine of amplitude {s} V is sampled {N} times over one period. What RMS does the sum give?

::: misses
- [any] $A/\sqrt2$, exactly.
:::
:::
:::

::: check
kind: parts
given: a = 4 | 9; b = 2 | 3; c = 6 | 5

## Cholesky factors $\begin{pmatrix}\given{a} & \given{b}\\ \given{b} & \given{c}\end{pmatrix}$.

::: part
answer: sqrt(c - b^2/a)
tolerance: 0.5%

### What is $l_{22}$?

::: misses
- [any] $\sqrt{c - (b/\sqrt a)^2}$.
:::
:::
:::

::: check
kind: parts
given: n = 2000 | 10000; g = 20 | 200

## Dense LU of an {n} × {n} matrix runs at {g} GFLOP/s.

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

### About how long does it take?

::: misses
- [n^3/(g*1e9)] LU costs $\frac23n^3$.
- [any] $\frac{2n^3/3}{\text{rate}}$.
:::
:::
:::

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

## Simpson's rule's error goes as $h^4$.

::: part
answer: k^4
tolerance: 0.5%

### By what factor does the error shrink with {k} times as many intervals?

::: misses
- [k^2] That's the trapezoid rule.
- [any] $k^4$.
:::
:::
:::
:::
