Numerical linear algebra
For a square matrix $A\in \R^{n\times n}$ non-singular, find $L$ and $U$ so that $$ \begin{align*} A = LU \end{align*} $$ where
-
$L\in \R^{n\times n}$ is lower unitriangular (i.e. $l_{ij} = 0$ for $i<j$ and $l_{ii}=1$ for all $i$); and
-
$U\in \R^{n\times n}$ is upper triangular (i.e. $u_{ij} = 0$ for $i>j$) and non-singular ($u_{ii}\neq 0$ for all $i$).
Let $\v l_k$ be the columns of $L$ and $\v u_k^T$ be the rows of $U$. By matrix multiplication, $$ \begin{align*} A = \sum_{k=1}^{n} \v l_k \v u_k^T. \end{align*} $$
Let $A^{(0)} = A$.
-
Take $\v u_1^T=$ first row of $A^{(0)}$ and $\v l_1 = \frac{1}{A_{11}^{(0)}}\times$ first column of $A^{(0)}$. Then $$ \begin{align*} A^{(1)} := A^{(0)} - \v l_1 \v u_1^T = \pmat{0 & 0 & \ldots & 0 \\ 0 & * & \ldots & * \\ \vdots & \vdots & \ddots & \vdots \\ 0 & * & \ldots & * }. \end{align*} $$
-
Take $\v u_2^T=$ second row of $A^{(1)}$ and $\v l_2 = \frac{1}{A_{22}^{(1)}}\times$ second column of $A^{(1)}$. Then $$ \begin{align*} A^{(2)} := A^{(1)} - \v l_2 \v u_2^T = \pmat{0 & 0 & 0 & \ldots & 0 \\ 0 & 0 & 0 & \ldots & 0 \\ 0 & 0 & * & \ldots & * \\ \vdots & \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & * & \ldots & * }. \end{align*} $$
And so on.
This takes $O(n^3)$ computations. With a better algorithm, we can get $O(n^{\log_2 7}) \approx O(n^{2.8})$.
Example (direct approach of LU factorisation)
The LU algorithm fails if $A_{kk}^{(k-1)} = 0$. To avoid this and to improve numerical stability, we exchange rows so that the element of largest magnitude in column $k$ is at the pivotal position $(k,k)$. This pre-multiplies a permutation matrix.
We obtain a factorisation $$ \begin{align*} PA = LU \implies A = P^T LU \end{align*} $$ where $P$ is the product of all permutation matrices multiplied.
-
Solving linear systems: to solve $A\v x = \v b$ where $A$ is non-singular and square, factorise $A=LU$ (in $O(n^3)$ time), solve $L\v y = \v b$ by forward substitution (in $O(n^2)$ time) and solve $U\v x = \v y$ by backward substitution (in $O(n^2)$ time).
This is better than Gaussian elimination ($O(n^3)$ time) if we need to solve $A\v x=\v b$ for the same $A$ but many different $\v b$.
-
Finding determinant of $A$: $\det A = \det L \det U = 1\cdot \prod_{i=1}^{n} u_{ii}$.
-
Inverting $A$: solve $A\v a\inv_k = \v e_k$ for each $k$.
A square matrix $A\in \R^{n\times n}$ is said to be strictly regular if all its principal minors (top left blocks of $A$, i.e. $A_1 = \pmat{a_{11}}, A_2 = \pmat{a_{11} & a_{12} \\ a_{21} & a_{22}}, \ldots, A_n = A$) are non-singular.
A square matrix $A\in \R^{n\times n}$ admits an LU factorisation iff $A$ is strictly regular.
-
Every non-singular matrix $A$ admits an LU factorisation with pivoting, i.e. $PA = LU$ for some permutation matrix.
LU factorisation is unique, i.e. if $L_1U_1=L_2U_2$ are two LU factorisations ($L_i$ lower unitriangular, $U_i$ non-singular and upper triangular), then $L_1=L_2$ and $U_1=U_2$.
$A\in \R^{n\times n}$ is strictly regular iff it admits a factorisation $A = LDU$, where $L$ is lower unitriangular, $D$ is non-singular and diagonal, and $U$ is upper unitriangular.
Moreover the factorisation is unique.
$A\in \R^{n\times n}$ is strictly regular and symmetric iff it admits a factorisation $A = LDL^T$ where $L$ is lower unitriangular and $D$ is non-singular and diagonal.
Moreover the factorisation is unique.
$A\in \R^{n\times n}$ is symmetric positive definite iff it admits a factorisation $A=LDL^T$ where $L$ is lower unitriangular and $D$ is diagonal with positive entries.
Moreover the factorisation is unique.
$A\in \R^{n\times n}$ is symmetric positive definite iff it admits a factorisation $A = LL^T$ where $L$ is lower triangular with a positive diagonal.
Moreover the factorisation is unique.
A square matrix $A\in \R^{n\times n}$ is said to be strictly diagonally dominant (by rows) if $$ \begin{align*} |a_{ii}| > \sum_{\substack{j=1 \\j\neq i}}^n |a_{ij}| \qquad \forall \text{row }i=1,\ldots,n. \end{align*} $$
If $A\in \R^{n\times n}$ is strictly diagonally dominant, then $A$ is strictly regular.
-
Therefore $A$ admits an LU factorisation.
For an $n\times n$ matrix $A$, for each row $i$ define $$ R_i = \sum_{j\neq i} |A_{ij}| $$ and define a disk $D_i(A_{ii}, R_i)\subset\C$ to be the circle with centre $A_{ii}$ and radius $R_i$.
Then every eigenvalues lie within a disk $D_i$ for some $i$.
A matrix is said to be sparse if most entries are zero. By contrast, a matrix with most entries non-zero is called dense.
A square matrix $A$ is a band matrix with bandwidth $2r+1$ if $a_{ij} = 0$ for $|i-j|>r$.
Let $A=LU$ be the LU factorisation of a sparse matrix $A$. Then
-
all leading zeros in the rows of $A$ to the left of the diagonal are inherited by $L$; and
-
all leading zeros in the columns of $A$ above the diagonal are inherited by $U$.
-
If $A$ is a band matrix, then $L$ and $U$ are also band matrices with the same bandwidth as $A$.
-
Sometimes if $A$ is sparse, we can try reordering its rows and columns to have more leading zeros, thus reducing the fill-in in $L$ and $U$.
The LU algorithm takes $O(nr^2)$ operations to factorise for a banded $A$ with bandwidth $r$. And to solve a linear system after factorisation, it takes $O(nr)$ operations.
For any (rectangular) matrix $A \in \R^{m\times n}$, find $Q,R$ such that $$ \begin{align*} A = QR \end{align*} $$ where
-
$Q\in \R^{m\times m}$ is orthogonal (i.e. $Q^TQ = I$); and
-
$R\in \R^{m\times n}$ is upper triangular (i.e. $r_{ij} = 0$ for $i>j$).
If $m>n$, the bottom $m-n$ rows of $R$ are zero, so we can write $Q\in \R^{m\times n}$ and $R^{n\times n}$ instead. This is the reduced QR factorisation.
Any matrix $A$ has a QR factorisation.
If $A$ is square and non-singular, then $A$ admits a unique factorisation $A = QR$ with $R$ having a positive diagonal.
Proof of existence: see Gram-Schmidt, Givens rotations, or Householder reflections.
Let $\v a_1, \ldots, \v a_n\in \R^m$ be the columns of $A$. By performing the Gram-Schmidt process on $\v a_1, \ldots, \v a_n$, we find an orthonormal set $\v q_1, \ldots, \v q_k \in \R^m$ ($k\leq n$) and coefficients $r_{ij}\in \R$ such that $$ \begin{align*} \v a_i = \sum_{j=1}^{i} r_{ji} \v q_j. \end{align*} $$ Then $$ \begin{align*} A = \underbrace{\pmat{\v q_1 & \ldots & \v q_k}}_{Q} \underbrace{\pmat{r_{11} & r_{12} & \ldots & r_{1k} & \ldots & r_{1n} \\ & r_{22} & \ldots & r_{2k} & \ldots & r_{2n} \\ &&\ddots & \vdots & & \vdots\\ &&&r_{kk} & \ldots & r_{kn}}}_{R}. \end{align*} $$
Example (QR factorisation using the Gram-Schmidt process)
However Gram-Schmidt is very numerically unstable.
For any vector $\v a\in \R^m$, the Givens rotation matrix $Ω^{[p,q]}\in \R^{m\times m}$ is an orthogonal transformation that makes the $q$-th component zero and preserves all components other than the $p$ and $q$-th ones: $$ \begin{align*} \underbrace{\pmat{1\\&\ddots\\&&\frac{a_p}{\sqrt{a_p^2+a_q^2}} && \frac{a_q}{\sqrt{a_p^2+a_q^2}} \\ &&&\ddots \\&&-\frac{a_q}{\sqrt{a_p^2+a_q^2}}&&\frac{a_p}{\sqrt{a_p^2+a_q^2}} \\ &&&&&\ddots \\ &&&&&&1}}_{Ω^{[p,q]}} \underbrace{\pmat{a_{1} \\ \vdots \\ a_p \\ \vdots \\ a_q \\ \vdots \\ a_m}}_{\v a} = \pmat{a_1 \\ \vdots \\ a_p^2 + a_q^2 \\ \vdots \\ 0 \\ \vdots \\a_m} \end{align*} $$
Applying $Ω^{[p,q]}$ to a matrix $A$, all rows other than rows $p$ and $q$ are unchanged, one entry in row $p$ is killed, and the span of rows $p$ and $q$ is preserved.
Thus after at most $mn$ Givens rotations, we can annihilate all subdiagonal elements: $$ \begin{align*} \pmat{*&*&*\\ *&*&* \\ *&*&* \\ *&*&*} &\xrightarrow{Ω^{[1,2]}} \pmat{\bullet &\bullet&\bullet\\ 0 &\bullet&\bullet \\ *&*&* \\ *&*&*} \xrightarrow{Ω^{[1,3]}} \pmat{\bullet &\bullet&\bullet\\ 0 &*&* \\ 0&\bullet&\bullet \\ *&*&*} \xrightarrow{Ω^{[1,4]}} \pmat{\bullet &\bullet&\bullet\\ 0 &*&* \\ 0&*&* \\ 0&\bullet&\bullet} \\ &\xrightarrow{Ω^{[2,3]}} \pmat{*&*&* \\ 0 &\bullet&\bullet \\ 0&0&\bullet \\ 0&*&*} \xrightarrow{Ω^{[2,4]}} \pmat{*&*&* \\ 0 &\bullet&\bullet \\ 0&0&* \\ 0&0&\bullet} \\ &\xrightarrow{Ω^{[3,4]}} \pmat{*&*&* \\ 0 &*&* \\ 0&0&\bullet \\ 0&0&0} \\ \end{align*} $$ (Legend: $*$ remains the same as the previous matrix; $\bullet$ has changed through a rotation.)
Therefore $$ \begin{align*} & R = (Ω^{[m-1,m]})\cdot (Ω^{[m-2,m]} Ω^{[m-2, m-1]}) \cdot \ldots \cdot (Ω^{[1,m]} \ldots Ω^{[1,3]} Ω^{[1,2]}) \cdot A \\ \implies & A = \underbrace{\Bigl[(Ω^{[m-1,m]})\cdot (Ω^{[m-2,m]} Ω^{[m-2, m-1]}) \cdot \ldots \cdot (Ω^{[1,m]} \ldots Ω^{[1,3]} Ω^{[1,2]})\Bigr]^T}_{Q} R. \end{align*} $$
Example (QR factorisation using Givens rotations)
Cost:
-
Computing $R$: $O(mn\cdot n)$.
-
Computing an explicit form of $Q$ (usually not necessary): perform all the Given rotations on $I_m$. This gives an extra cost of $O(mn\cdot m)$.
-
Computing $Q^T \v b$: $O(mn)$.
Given a non-zero vector $\v u\in \R^m$, the $m\times m$ matrix $$ \begin{align*} H_\v u = I - \frac{2}{\|\v u\|^2} \v u \v u^T \end{align*} $$ is called a Householder transformation or reflection.
-
$H_\v u$ reflects a vector about the $(m-1)$-dimensional hyperplane normal to $\v u$. (Derivation)
-
$H_{\v u}$ is orthogonal.
-
If $\|\v a\|=\|\v b\|$, then $H_{\v a - \v b}(\v a) = \v b$.
Given any vector $\v a = (a_1, \ldots, a_{k-1}, a_k, a_{k+1}, \ldots, a_m)\in \R^m$, we can get $\v b = (a_1, \ldots, a_{k-1}, γ, 0, \ldots, 0)\in \R^m$ where $γ = \pm\sqrt{a_k^2 + a_{k+1}^2 + \ldots + a_m^2}$ by applying the Householder reflection for $\v u = \v a - \v b = (0,\ldots,0, a_k - γ, a_{k+1}, \ldots, a_m)$. Note that $H_u$ has the block matrix form $$ \begin{align*} H_\v u = \pmat{I_{k-1} & 0 \\ 0 & *} \end{align*} $$ so the first $k-1$ components are preserved under $H_\v u$.
Therefore we can kill off all subdiagonal entires of a matrix this way: $$ \begin{align*} \pmat{*&*&* \\ *&*&* \\ *&*&* \\ *&*&*} \xrightarrow{H_1} \pmat{\bullet&\bullet&\bullet \\ 0&\bullet&\bullet \\ 0&\bullet&\bullet \\ 0&\bullet&\bullet} \xrightarrow{H_2} \pmat{*&*&* \\ 0&\bullet&\bullet \\ 0&0&\bullet \\ 0&0&\bullet} \xrightarrow{H_3} \pmat{*&*&* \\ 0&*&* \\ 0&0&\bullet \\ 0&0&0} \end{align*} $$ (Legend: $*$ remains the same as the previous matrix; $\bullet$ has changed through a rotation.)
Hence $$ \begin{align*} R = H_m\ldots H_2 H_1 A \implies A = \underbrace{(H_m \ldots H_2H_1)^T}_{Q} R. \end{align*} $$
Example (QR factorisation using Householder reflections)
Practicality:
-
Numerically, don't compute the matrix of $H_\v u$! Always perform vector products $\v v - \frac{2}{\|u\|^2}\v u \v u^T \v v$ instead.
-
How to choose the sign of $γ$?
-
For hand computation, choose $\sign γ = \sign a_k$ to make numbers smaller.
-
For numerical computation, choose $\sign γ = -\sign a_k$ to make numbers larger for stability.
-
Choosing between Givens and Householder transformations:
-
If $A$ is dense, Householder is more convenient.
-
If $A$ is sparse, use Givens to rotate away the non-zero entries.
Given $A \in \R^{m\times n}$ and $\v y\in \R^m$, find $\v c$ that minimises $\|A\v c - \v y\|^2$.
For $m>n$, usually the system $A\v c = \v y$ is overdetermined and there is no solution. We try to find an approximate one.
Application: least square estimator in IB Statistics.
$\v c^\ast\in \R^m$ is the solution to the least squares problem iff it solves the normal equations $$ \begin{align*} A^TA\v c^\ast = A^T \v y. \end{align*} $$ $A^TA$ is called the Gram matrix, and $\v c^\ast$ is the normal solution.
Moreover if $A$ has full rank, then $\v c^\ast = (A^T A)\inv A^T \v y$ is unique.
-
This is not suitable for numerical computation:
-
$A^TA$ may become numerically singular;
-
$A^TA$ can be dense even when $A$ is sparse;
-
computing $A^TA$ may lead to a loss of accuracy.
-
To solve a least squares problem, let $A=QR$ be the QR factorisation of $A$, and assume $A$ has full rank $n$.
Since orthogonal transformations are length-preserving, $$ \begin{align*} \|A\v c - \v y\| = \|Q^T(A\v c - \v y)\| = \|R\v c - Q^T \v y\| \end{align*} $$ Let $Q^T \v y = \v z$. The form of $R\v c - Q^T \v y$ looks like $$ \begin{align*} \pmat{* & * & \ldots & * \\ &* & \ldots & * \\ &&\ddots & \vdots \\ &&&* \\ 0 & 0 & \ldots & 0 \\ \vdots & \vdots & & \vdots \\ 0 & 0 & \ldots & 0} \pmat{c_1 \\ c_2 \\ \vdots \\ c_n} - \pmat{z_1 \\ z_2 \\ \vdots \\ z_{n} \\ z_{n+1} \\ \vdots \\ z_{m}}. \end{align*} $$ We see that the best $\v c$ we can pick is by solving the non-singular linear system corresponding to the first $n$ equations (using back substitution).