Tutorial 3

1) Condition Number of a Matrix

\({}\)

\({}\)

$\Delta b_1$ = ± $\Delta b_2$ = ±

Recall tutorial 1 where we talked about the condition number of a function, $f(x)$. As the error in $x$ increases, how does the error in $f(x)$ increase with it?
Imagine we have a system of linear equations $Ax = b$. As the error in $b$ increases, how does the error in $x$ increase? This can also be quantified with the condition number of $A$.

$$cond(A) = \frac{\sigma_{max}}{\sigma_{min}}$$

Question 1: Find the condition number for matrices $A_1$ and $A_2$.

$cond(A_1)$ =

$cond(A_2)$ =






2) More Eigenvectors

$$ A = \begin{bmatrix} 1 & 1 \\ 2 & 1 \\ 1 & 2 \end{bmatrix}$$

Question 2: (From the 2014 test) The eigenvectors of $A^TA$ are $v_1 = \begin{bmatrix} 1 \\ 1 \end{bmatrix}$ and $v_2 = \begin{bmatrix} -1 \\ 1 \end{bmatrix}$. Find the eigenvalues.

$A^TA$ =

$(\lambda_1, \lambda_2)$ =






3) Principal Component Analysis

$$ A = \begin{bmatrix} 3 & -3 & 0 & -2 \\ 4 & -2 & -1 & 7 \\ 1 & 1 & 1 & -2 \end{bmatrix}$$

Question 3: With help form the linalg library, find the amount of $a_1$ in the direction of the first principal component ($u_1$) and the second principal component ($u_2$). Remember to centre $A$ first.

$A$ centred =

$U =$

$u_1^Ta_1 =$

$u_2^Ta_1 =$






4) Find the secret code using PCA

$A = $



There are three files on the tutorial page. sheev.pgm is a $150\times 200$ pgm file, code.txt is a $150\times 2561$ matrix which contains a hidden code, and tutorial3Q4.ipynb contains some useful functions.

Question 4: Find the secret code in matrix $C$ (code.txt). First, find the principal component matrix $U$ of the $A$ matrix (sheev.pgm). Then, find $U_2$ - the matrix which contains the first two principal components of $A$. Finally, apply $U_2$ to code.txt to project the code.txt onto the first two principal components of sheev.pgm. This will give a 2×2561 matrix. Plot these two rows using the plot_first_2_rows(mat) function.

Dimensions of $U$:

pgm of $U$:

Dimensions of $U_2$:

pgm of $U_2$:

Plot the first two rows $C$:

Plot the solved code: