CMPSC/Mathematics 451Final Exam–Part OneDue 11 November 2022Fall 2022You are to write a MATLAB (or Octave) function cgs2 that implementsclassical Gram-Schmidt with reorthogonalization. It...

1 answer below »
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 reorthogonalization. The algorithm was taught in class in a lecture that I have
duplicated in this folder.


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)′; b = 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, be 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); err = yexact− yy; err norm = norm(err, Inf); Give the value of err norm and plot xx and err against one another with approriate graph labels. You are welcome check any of your results using the MATLAB qr function, but that is not necessary. 2
Answered 3 days AfterNov 08, 2022

Answer To: CMPSC/Mathematics 451Final Exam–Part OneDue 11 November 2022Fall 2022You are to write a...

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;
r1 = norm(y1);
q1 = y1/r1;
s2 = Q'*q1 ;
y2 = q1-Q*s2;
r2 = norm(y2);
qb = y2/r2;
sb = s1 + s2*r1;
rb = r2*r1;
R(1:k-1,k)=sb;
R(k,k)=rb;
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