b, n, x = Float16( 1.001 ), 2025, Float16( 1 );
for i = 1:n
x = b*x
end
y = exp( n * log( b ) )
println( "x = ", x, "; y = ", y )x = 5.91; y = 7.22
Time Allowed: 2 hours
Answer SECTION A (40%) and TWO (30% + 30%) of the three optional sections (B, C, D). If you have answered more than than the required two optional sections, you will be given credit for your best two optional sections. As a guide, I suggest you spend around 40 minutes on each section.
Please indicate your answers to multiple choice questions clearly with an ╳ to the left of your answers. Answer the optional sections on separate paper.
Please label any additional paper you use with your name and page number.
Electronic devices are not needed and not permitted in this examination. You may use your own notes, limited to 2 sides of letter sized paper. Answer the questions to Section A in the boxes provided. Additional paper may be requested.
Section A continued.
b, n, x = Float16( 1.001 ), 2025, Float16( 1 );
for i = 1:n
x = b*x
end
y = exp( n * log( b ) )
println( "x = ", x, "; y = ", y )x = 5.91; y = 7.22
Which result do you trust more and why?
Section A continued.
Section A continued.
\begin{align} I = \int_1^n \log(x) \mathrm{d}x \approx \log n! - \frac12 \log n \tag{A.1} \end{align}
Section A continued.
\begin{align} \mathrm{erf}(x) = \frac2{\sqrt\pi} \int_0^x e^{-t^2} \mathrm{d}t. \tag{A.2} \end{align}
What is the approximation to \mathrm{erf} if you use the (i) rectangular rule and the (ii) trapezoid rule on the single interval [0,x]?
Recall that Gauss quadrature rules are of the form \int_{-1}^1 f(x) \mathrm{d}x \approx \sum_{j=0}^n w_j f(x_j) where X = \{ x_0, \dots, x_n \} are the zeros of the Legendre polynomial P_{n+1}. This rule is exact for all polynomials of degree at most 2n+1.
\begin{align} 0 &= \int_{-1}^1 P_{n+1}(x) q(x) \mathrm{d}x % = \int_{-1}^1 (x-x_0) \prod_{j=1}^n (x-x_j)^2 \mathrm{d}x. \tag{A.3} \end{align}
Use this to show that x_0 \in [-1,1]. (The same argument applies to all the roots so X\subset [-1,1]).
Section A continued.
Choose TWO sections from B, C, D (each worth 30%)
We define \|f\|_{L^\infty} := \max_{x\in[a,b]} |f(x)| and let \mathcal P_n be the set of all polynomials of degree at most n. We denote by I_Xf the degree n polynomial interpolation of f \colon [a,b] \to \mathbb R on X = \{x_0 < \dots < x_n\}: i.e. we have I_Xf \in \mathcal P_n and I_Xf(x_j) = f(x_j) for all j=0,\dots,n (in class, we simply called this p_n but here we want to explicitly specify f in the notation).
The Lebesgue constant for X is the smallest number \Lambda_n = \Lambda_n(X) such that
\begin{align} \| I_Xf \|_{L^\infty} \leq \Lambda_n \| f \|_{L^\infty}. \tag{B.1} \end{align}
\begin{align} \| I_Xf \|_{L^\infty} \leq \Big( \max_{x\in[a,b]} \sum_{j=0}^n |\ell_j(x)| \Big) \| f \|_{L^\infty} \tag{B.2} \end{align}
and explain why this means that \Lambda_n \leq \max\limits_{x \in [a,b]} \sum_{j=0}^n |\ell_j(x)|.
Section B continued.
Suppose that p_n^\star is the polynomial of degree n such that
\begin{align} \| f - p_n^\star \|_{L^\infty} = \min_{p_n \in \mathcal P_n} \| f - p_n \|_{L^\infty} \tag{B.3} \end{align}
i.e. p_n^\star is the best polynomial approximation to f in \mathcal P_n in the sense that \| f - p_n^\star\|_{L^\infty} \leq \| f - p_n\|_{L^\infty} for all polynomials p_n \in \mathcal P_n.
Notice, by the triangle inequality, we have
\begin{align} \| f - I_Xf \|_{L^\infty} % &= \| f - p_n^\star + p_n^\star - I_Xf \|_{L^\infty} \nonumber\\ % &\leq \| f - p_n^\star\|_{L^\infty} + \| p_n^\star - I_Xf \|_{L^\infty}. \tag{B.4} \end{align}
\begin{align} \| f - I_Xf \|_{L^\infty} % \leq (1 + \Lambda_n) \| f - p_n^\star\|_{L^\infty}. \tag{B.5} \end{align}
Choose TWO sections from B, C, D (each worth 30%)
In lectures, we saw the Lagrange cardinal polynomials \ell_j(x) (polynomials with \ell_j(x_k) = \delta_{jk}) and, in A8, we saw the cardinal functions for piecewise linear interpolation (we called these “hat functions”). In this part, we consider the cardinal functions for Hermite interpolation on \{ t_0, t_1, t_2, t_3 \} where t_0 = t_1 := 0 and t_2 = t_3 := 1.
We define the Hermite cardinal functions H_0, H_1, K_0, K_1 : [0,1] \to \mathbb R as the cubic polynomials such that
\begin{align} H_0(0) = 1, \quad H_0(1) = 0, \quad H'_0(0) = 0, \quad H'_0(1) = 0, \tag{C.1}\\ H_1(0) = 0, \quad H_1(1) = 1, \quad H'_1(0) = 0, \quad H'_1(1) = 0, \tag{C.2}\\ K_0(0) = 0, \quad K_0(1) = 0, \quad K'_0(0) = 1, \quad K'_0(1) = 0, \tag{C.3}\\ K_1(0) = 0, \quad K_1(1) = 0, \quad K'_1(0) = 0, \quad K'_1(1) = 1. \tag{C.4} \end{align}
Hint: To help visualise, here is a plot of these functions
Left: plots of H_{i}. Here, you can see that H'_{i}(0) = H'_{i}(1) = 0 for i=0,1,
Right: plots of K_i. Here, we also plot x and x-1 in dashed line (so we can see that K_0'(0)=1 and K_1'(1)=1).
Section C continued.
\begin{align*} \begin{matrix} & H_0[t_i] & & H_0[t_i, t_{i+1}] & & H_0[t_i, t_{i+1},t_{i+1}] & & H_0[t_0,t_1,t_2,t_3] \\ \\ t_0 = 0: & & & & \\ \\ t_1 = 0: & & & & \\ \\ t_2 = 1: & & & & \\ \\ t_3 = 1: & & & & \end{matrix} \tag{C.5} \end{align*}
A similar argument (you do not need to prove) gives
\begin{align} H_1(t) &= -2t^3 + 3t^2, \qquad K_0(t) = t^3 - 2t^2 + t, \qquad K_1(t) = t^3 - t^2. \tag{C.6} \end{align}
Let f : [-1,1] \to \mathbb R be some function and X = \{x_0 < \dots < x_n\} be equispaced points with x_0 = -1 and x_n = 1. We define h := \frac2n = x_{i+1}-x_i.
In this question we will prove that there exists an S:[-1,1]\to\mathbb R such that
(i) S is two times continuously differentiable,
(ii) S(x_i) = f(x_i) for i = 0,\dots,n,
(iii) S is a cubic polynomial on each subinterval [x_{i},x_{i+1}], and
(iv) S'(x_0) = f'(x_0) and S'(x_n) = f'(x_n).
Such a function is called a cubic spline (with clamped boundary conditions).
\begin{align} S_i(x) := f(x_i) H_0(t) + f(x_{i+1}) H_1(t) + h \big( m_i K_0(t) + m_{i+1} K_1(t) \big) \tag{C.7} \end{align}
is a cubic polynomial with S_i(x_i) = f(x_i), S_i(x_{i+1}) = f(x_{i+1}), S'_i(x_i) = m_i, and S'_i(x_{i+1}) = m_{i+1}. (Recall that we defined H_0, H_1, K_0, K_1 in \textrm{(C.1)}-\textrm{(C.4)}, above.)
To obtain a cubic spline S : [-1,1] \to \mathbb R, we define S(x) = S_i(x) if x \in [x_i, x_{i+1}].
Section C continued.
One can show that
\begin{align} h^2 S''_i(x_i) &= 6 ( f(x_{i+1}) - f(x_i) ) - 2 h \big( m_{i+1} + 2m_i \big) \nonumber\\ h^2 S''_i(x_{i+1}) &= -6( f(x_{i+1}) - f(x_i) ) + 2 h \big( 2m_{i+1} + m_{i} \big). \tag{C.8} \end{align}
In order to enforce continuity of the second derivatives of S, we require S_{i-1}''(x_{i}) = S_{i}''(x_{i}) for each i = 1,\dots,n-1 which, by \textrm{(C.8)}, is equivalent to
\begin{align} m_{i-1} + 4 m_i + m_{i+1} = 3 \frac{ f(x_{i+1}) - f(x_{i-1}) }{h} \tag{C.9} \end{align}
(you do not need to prove this).
\begin{align} A &= \begin{pmatrix} 4 & 1 & & \\ 1 & 4 & \ddots & \\ & \ddots & \ddots & 1 \\ & & 1 & 4 \end{pmatrix}. % \tag{C.10} %\\ % %b_i &= 3 \frac{f(x_{i+1}) - f(x_{i-1})}{h} - %\begin{cases} % f'(x_0) & \text{if } i=1\nonumber\\ % 0 & \text{if } 2 \leq i \leq n-2\\ % f'(x_n) & \text{if } i = n-1. %\end{cases} %\tag{C.12} \end{align}
It turns out that A is invertible and so there exists a unique \bm m which satisfies A\bm m = \bm b and so there exists a unique cubic spline satisfying the conditions (i)-(iv), above. Moreover, we can compute the cubic spline by using m = A \ b in Julia and evaluating \textrm{(C.7)}.
Choose TWO sections from B, C, D (each worth 30%)
\begin{align} \begin{pmatrix} 2 & 1 & 0 & 0 \\ 1 & 2 & 1 & 0 \\ 0 & 1 & 2 & 1 \\ 0 & 0 & 1 & 2 \end{pmatrix} \tag{D.1} % % = \begin{pmatrix} % 1 & 0 & 0 & 0 \\ % 1/2 & 1 & 0 & 0 \\ % 0 & 2/3 & 1 & 0 \\ % 0 & 0 & 3/4 & 1 % \end{pmatrix} % \begin{pmatrix} % 2 & 1 & 0 & 0 \\ % 0 & 3/2 & 1 & 0 \\ % 0 & 0 & 4/3 & 1 \\ % 0 & 0 & 0 & 5/4 % \end{pmatrix} \end{align}
\begin{align} \begin{pmatrix} 2 & 1 & 0 & 0 \\ 1 & 2 & 1 & 0 \\ 0 & 1 & 2 & 1 \\ 0 & 0 & 1 & 2 \end{pmatrix} \begin{pmatrix} x_1 \\ x_2 \\ x_3 \\ x_4 \end{pmatrix} % = \begin{pmatrix} 12 \\ -24 \\ 8 \\ 26 \end{pmatrix} \tag{D.2} \end{align}
[3 points] You may have noticed that when A is tridiagonal (as in the case of Question 1, above), then L and U are bidiagonal with L only having nonzero entries on the diagonal and lower diagonal and U only having nonzero entries on the diagonal and upper diagonal. Explain why this is true in general.
[3 points] If A is a tridiagonal matrix, what is the computational cost in solving A \bm x = \bm b using LU decomposition and forwards and backwards substitution?
O(n)
O(n^2)
O(n^3)
Section D continued.
Recall that the SVD of A \in \mathbb R^{m\times n} is A = P\Sigma Q^T where P\in \mathbb R^{m\times m} is orthogonal (PP^T = P^TP = I), \Sigma\in \mathbb R^{m\times n} is diagonal with singular values \sigma_i := \Sigma_{ii}, \sigma_1 \geq \sigma_2 \geq \dots \geq \sigma_r \geq 0, and r := \min\{m,n\}, and Q \in \mathbb R^{n\times n} is orthogonal.
\begin{align} \begin{pmatrix} 1 & 0 \\ 1 & 0 \\ 1 & 0 \end{pmatrix}.\tag{D.3} \end{align}
Recall that \|A\| := \max_{\bm x\not= 0} \frac{|A\bm x|}{|\bm x|} where |\bm x|:= \sqrt{\sum_{i} x_i^2}.
\begin{align} \|A\|^2 % = \max_{\bm y \not= 0} \frac {|P\Sigma y|^2} {|y|^2} % = \max_{\bm y \not= 0} \frac{\sum_{i} \sigma_i^2 y_i^2}{\sum_i y_i^2}.\tag{D.4} \end{align}
[2 points] Hence show that \| A \| = \sigma_1.
[2 points] Two matrices A, B \in \mathbb R^{512\times512} represent the following two grayscale images. Which matrix has singular values which decay faster? Why?