---
title: Problem set 8
heading: "Problem set 8: fitting and optimization"
eyebrow: A13 · Problem set 8
type: problems
---

::: hook
These problems use lessons 37 and 38: linear and nonlinear least squares, with their uncertainties, and minimization in one and several variables. Report fitted parameters with the precision the data supports.
:::

::: pool
pick: 12

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

## Fit a line to (0, {a}), (1, {b}), (2, {c}).

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

### What is the slope?

::: misses
- [b - a] Use all three points; with x = 0, 1, 2 the slope is $\frac{c - a}{2}$.
- [any] $\frac{\sum(x - \bar x)(y - \bar y)}{\sum(x - \bar x)^2}$ with $\bar x = 1$.
:::
:::

::: part
answer: (a + b + c)/3 - (c - a)/2
tolerance: 0.5%

### What is the intercept?

::: misses
- [a] The line passes through $(\bar x, \bar y)$, not necessarily through the first point.
- [any] $\bar y - m\bar x$.
:::
:::
:::

::: check
kind: parts
given: n = 11 | 21; s = 0.1 | 0.5

## A line is fitted to {n} points at x = 0, 1, …, {n} − 1, each with noise σ = {s}.

::: part
answer: s/sqrt(n*(n^2 - 1)/12)
tolerance: 0.5%

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

::: misses
- [s/sqrt(n)] Divide by $\sqrt{\sum(x - \bar x)^2}$, which grows as $n^{3/2}$.
- [any] $\frac{\sigma}{\sqrt{\sum(x - \bar x)^2}}$ with $\sum(x - \bar x)^2 = \frac{n(n^2 - 1)}{12}$.
:::
:::

::: part
answer: s/sqrt(n)
tolerance: 0.5%

### And the standard error of the fitted value at the middle point?

::: misses
- [any] At $\bar x$ the fit's uncertainty is that of the mean, $\sigma/\sqrt n$.
:::
:::
:::

::: check
kind: parts
given: m = 20 | 50; n = 2 | 4; S = 0.8 | 3

## A fit of {n} parameters to {m} points leaves a sum of squared residuals of {S}.

::: part
answer: S/(m - n)
tolerance: 0.5%

### What is the estimated noise variance?

::: misses
- [S/m] Divide by the degrees of freedom, $m - n$.
- [any] $\frac{\text{SSR}}{m - n}$.
:::
:::
:::

::: check
kind: parts
given: A = 2 | 5; tau = 1 | 3; t = 0.5 | 2

## The model $y = Ae^{-t/\tau}$ with A = {A}, τ = {tau}.

::: part
answer: exp(-t/tau)
tolerance: 0.5%

### What is the Jacobian entry $\partial y/\partial A$ at t = {t}?

::: misses
- [any] $e^{-t/\tau}$.
:::
:::

::: part
answer: A*t*exp(-t/tau)/tau^2
tolerance: 0.5%

### And $\partial y/\partial\tau$?

::: misses
- [-A*t*exp(-t/tau)/tau^2] Differentiating $-t/\tau$ with respect to τ gives $+t/\tau^2$.
- [any] $\frac{At}{\tau^2}e^{-t/\tau}$.
:::
:::
:::

::: check
kind: parts
given: x1 = 5.02 | 3.31; s1 = 0.01 | 0.02; d = 0.03 | -0.04; s2 = 0.03 | 0.04

## Two measurements of the same voltage: {x1} V ± {s1} V, and a second that reads {d} V more, ± {s2} V.

::: part
answer: x1 + d*(1/s2^2)/(1/s1^2 + 1/s2^2)
tolerance: 0.001%

### What is the weighted least-squares estimate?

::: misses
- [x1 + d/2] Weight each by $1/\sigma^2$.
- [any] $\frac{\sum x_i/\sigma_i^2}{\sum1/\sigma_i^2}$.
:::
:::

::: part
answer: 1/sqrt(1/s1^2 + 1/s2^2)
tolerance: 0.5%

### What is its standard deviation?

::: misses
- [any] $\left(\sum\sigma_i^{-2}\right)^{-1/2}$.
:::
:::
:::

::: check
kind: parts
given: k = 3 | 5 | 7

## Least squares through the normal equations with $\kappa(A) = 10^{\given{k}}$.

::: part
answer: 16 - 2*k
tolerance: 0.5%

### About how many digits survive in double precision?

::: misses
- [16 - k] $\kappa(A^TA) = \kappa^2$.
- [any] $16 - 2\log_{10}\kappa$.
:::
:::
:::

::: check
kind: parts
given: L = 1 | 10; d = 0.000001 | 0.0001

## Golden-section search shrinks a bracket by 0.618 per evaluation.

::: part
answer: ceil(ln(d/L)/ln(0.618034))
tolerance: 0

### How many evaluations shrink a bracket of {L} below {d}?

::: misses
- [ceil(log(L/d)/log(2))] That's bisection's rate; golden section shrinks by 0.618.
- [any] Solve $L \cdot 0.618^n \le d$.
:::
:::
:::

::: check
kind: parts
given: l = 4 | 20; m = 0.5 | 2

## A quadratic's Hessian has eigenvalues from {m} to {l}.

::: part
answer: 2/l
tolerance: 0.5%

### Above what fixed step does gradient descent diverge?

::: misses
- [1/l] The limit is $\frac{2}{\lambda_\max}$.
- [any] $\lvert 1 - h\lambda\rvert < 1$ for every eigenvalue.
:::
:::

::: part
answer: (l - m)/(l + m)
tolerance: 0.5%

### With the best fixed step, what factor does the error shrink by per step?

::: misses
- [any] $\frac{\kappa - 1}{\kappa + 1}$.
:::
:::
:::

::: check
kind: parts
given: c = 3 | 4; x0 = 1 | 1.5

## Minimize $f(x) = x^4 - \given{c}x$ by Newton's method from {x0}.

::: part
answer: x0 - (4*x0^3 - c)/(12*x0^2)
tolerance: 0.1%

### What is the new x?

::: misses
- [any] $x - \frac{f'(x)}{f''(x)}$.
:::
:::

::: part
answer: (c/4)^(1/3)
tolerance: 0.1%

### Where is the minimum?

::: misses
- [any] Solve $4x^3 = c$.
:::
:::
:::

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

## A parabola passes through $(-\given{h}, \given{a})$, $(0, \given{b})$ and $(\given{h}, \given{c})$.

::: part
answer: h*(a - c)/(2*(a - 2*b + c))
tolerance: 0.5%

### Where is its minimum?

::: misses
- [h*(c - a)/(2*(a - 2*b + c))] Check the sign: the minimum leans toward the lower side.
- [any] $\frac{h(f_- - f_+)}{2(f_- - 2f_0 + f_+)}$.
:::
:::
:::

::: check
kind: parts
given: p = 11 | 16 | 24 | 53 | 64 | 113

## A minimum is located by comparing function values in a {p}-bit format.

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

### To about what relative accuracy can its location be found?

::: misses
- [2^(1 - p)] Near a minimum f changes quadratically, so only $\sqrt\varepsilon$ is resolvable.
- [any] $\sqrt\varepsilon$.
:::
:::
:::

::: check
kind: parts
given: n = 3 | 6; m = 20 | 100

## A polynomial of degree {n} is fitted to {m} points.

::: part
answer: n + 1
tolerance: 0

### How many parameters does it have?

::: misses
- [n] Count the constant term.
- [any] $n + 1$ coefficients.
:::
:::

::: part
answer: m - n - 1
tolerance: 0

### How many degrees of freedom remain for estimating noise?

::: misses
- [any] Points minus parameters.
:::
:::
:::

::: check
kind: parts
given: l = 0.001 | 0.01 | 0.1 | 1 | 10 | 100

## A Levenberg–Marquardt step with λ = {l} lowered the sum of squares.

::: part
answer: l/10
tolerance: 0.5%

### What λ comes next, with the usual factor of 10?

::: misses
- [l*10] A successful step lets the method move toward Gauss–Newton: lower λ.
- [any] Divide by 10.
:::
:::
:::

::: check
kind: parts
given: v1 = 3.1 | 2.8; v2 = 1.9 | 1.7; t = 1 | 2

## A decaying voltage reads {v1} V at t = 0 and {v2} V at t = {t} ms. Fit $Ae^{-t/\tau}$ exactly through the two points.

::: part
answer: t/ln(v1/v2)
unit: ms
tolerance: 0.5%

### What is τ?

::: misses
- [t/log(v1/v2)] Use the natural logarithm.
- [any] $\tau = \frac{t}{\ln(v_1/v_2)}$.
:::
:::
:::

::: check
kind: parts
given: x = 1 | 2; y = 1 | -1

## Rosenbrock's function $f = (1 - x)^2 + 100(y - x^2)^2$ at ({x}, {y}).

::: part
answer: -2*(1 - x) - 400*x*(y - x^2)
tolerance: 0.5%

### What is $\partial f/\partial x$?

::: misses
- [any] Differentiate both terms; the second gives $-400x(y - x^2)$.
:::
:::

::: part
answer: 200*(y - x^2)
tolerance: 0.5%

### What is $\partial f/\partial y$?

::: misses
- [any] $200(y - x^2)$.
:::
:::
:::
:::
