Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

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...

1 answer below »
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
Answered 3 days After Nov 08, 2022

Solution

Baljit answered on Nov 11 2022
41 Votes
Function cgs2(X):
Matlab Code:-
function [Q, R]=cgs2(X)
[m, n]=size(X);
R(1,1) = norm(X(:,1));
Q(:,1) = X(:,1)/R;
for k = 2:n
s1 = Q'*X(:,k);
y1 =X(:,k)-Q*s1;
1 = norm(y1);
q1 = y1
1;
s2 = Q'*q1 ;
y2 = q1-Q*s2;
2 = norm(y2);
qb = y2
2;
sb = s1 + s2*r1;
= r2*r1;
R(1:k-1,k)=sb;
R(k,k)=
;
Q(:,k)=qb;
end

Operation on 6×5 Lauchli matrix:
·
·
·
·
Least...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here