CMPSC/Mathematics 451
Final Exam–Part One
Due 11 November 2022
Fall 2022
You are to write a MATLAB (or Octave) function cgs2 that implements
classical Gram-Schmidt with reorthogonalization. It should have the first
line
function [Q,R] = cgs2(X)
and should produce Q-R factorization by classical Gram-Schmidt with re-
orthogonalization. The algorithm was taught in class in a lecture that I have
duplicated in this folder.
Here are two test problems that you are asked to use for the your function.
The first is the 6×5 Läuchli matrix which can be generated by the command
≫ X = [ones(1, 5); sqrt(eps) ∗ eye(5)]
For this example, display Q, R, ∥X −QR∥2 and ∥I5 −QTQ∥2.
The second is a least squares function fitting problem to find a polyomial
(written to conform the the MATLAB polyval function)
p5(x) = a0x
5 + a1x
4 + a2x
3 + a3x
2 + a4x+ a5
to the function f(x) = ex on the interval [0, 1
2
(ln 2)].
For this problem complete the following steps
1. The mesh of points and the least squares problem can be generated the
code
d = 0.5 ∗ (log(2))
h = d/10;
x = (0:h: d)′;
= exp(x);
V = vander(x);
X = V (:, 6: 11);
2. Use your cgs2 function to solve for a = (a0, a1, a2, a3, a4, a5)
T . Note,
e sure to treat b as an extra column of X as shown in class. Given
a and the residual r = b−Xa in a manner comforming with how this
algorithm is taught in class.
1
3. Perform the following test on your solution a.
xx = (0: d/100: d)′;
yy = polyval(a, xx);
yexact = exp(xx);
e
= yexact− yy;
e
norm = norm(e
, Inf);
Give the value of e
norm and plot xx and e
against one anothe
with approriate graph labels.
You are welcome check any of your results using the MATLAB q
function, but that is not necessary.
2