MAT321: Precept 4

In this precept we perform experiments similar to the paper "Experiments on Gram-Schmidt Orthogonalization" by J.R. Rice in Math. Comp. (1966). Consider the following excerpt from the text:

gs1

Task 1: Implement an economy QR factorization by classical Gram-Schmidt and modified Gram-Schmidt in the functions below. (may want to check your notes and/or the Trefethen book)

Test your code on several examples (provided below in code)

We will test for the stability of both methods by looking at two error metrics (both are implemented for you below):

$$ \text{err} = \frac{\|Q Q^\top A - A\|_F}{\|A\|_F} $$

where $\|\cdot\|_F$ is the Frobenius norm, which is equal to the square root of the sum of squares of the entries of the given matrix $ \|A\|_F = \sqrt{\sum_{i=1}^n \sum_{j=1}^m |a_{i,j}|^2} $. Note that, in exact arithmetic, if $A\in \mathbb{R}^{m\times n}$ with $A = QR$ and $Q\in \mathbb{R}^{m\times n}$ has orthonormal columns:

$$ Q Q^TA = QQ^T (QR) = Q (Q^TQ) R = QI_{n,n}R = QR = A $$

where $I_{n,n}$ is the $n \times n$ identity matrix.

Task 2: Implement a full QR by Householder reflection and test on the artificial example

If you are running out of time, use the function as it is implemented for you two cells down. What do you observe compared to Gram-Schmidt?