Error Analysis of Modern Gram Schmidt Technique -code bug

Click For Summary
SUMMARY

The forum discussion focuses on the implementation of the Modified Gram-Schmidt algorithm for computing the QR decomposition of matrix A. The user encounters an error in the computed one-norm of the difference between Q transpose multiplied by Q and the identity matrix, resulting in an unexpected error value of 1.00. The suggested solution involves modifying the code to set p(:,u) equal to e(:,u) at the end of each iteration of the loop, ensuring that the normalized vectors are correctly stored in p.

PREREQUISITES
  • Understanding of QR decomposition and its applications in linear algebra.
  • Familiarity with the Modified Gram-Schmidt algorithm.
  • Proficiency in MATLAB programming for matrix manipulation.
  • Knowledge of matrix norms, specifically the one-norm.
NEXT STEPS
  • Review MATLAB's matrix manipulation functions to enhance code efficiency.
  • Study the theoretical foundations of the Modified Gram-Schmidt algorithm.
  • Learn about error analysis techniques in numerical linear algebra.
  • Explore alternative QR decomposition methods, such as Householder transformations.
USEFUL FOR

Mathematicians, data scientists, and software engineers working with numerical methods and linear algebra, particularly those implementing QR decomposition algorithms in MATLAB.

SchrodingersMu
Messages
14
Reaction score
0
Hi all,

I am to compute A = QR using the Modified Gram-Schmidt algorithm. I need to find the error using

the one norm of : (Q transpose * Q) - I.

Here is my code:
Code:
%Modern Gram Schmidt
p=zeros(5,5);
e=zeros(5,5);
g=zeros(5,5);

for k=1:n;
    p(:,k)=(A(:,k));
end
%j=k, i=u, r=g, q=e, v=p
for u=1:n
    g(u,u)=norm(p(:,u),2);
    e(:,u)=p(:,u)/g(u,u);
    for k=u+1:n
        g(u,k)=e(:,u)'*p(:,k);
        p(:,k)=p(:,k)-(e(:,u)*g(u,k));
    end
end

W=((p*p')-I);
errormod=norm(W,1);

save errorMGS.dat errormod -ascii
I am getting an errormod of 1.00 . It obviously should be way less than this. I can't see what I am doing wrong, though. I modeled my code after an example proided by my prof: (The left part of the powerpoint)

upload_2015-2-26_0-15-21.png


Any help is appreciated!
 
Last edited by a moderator:
Physics news on Phys.org
Reading through your code, it looks like you are saving the p as the full-scale matrix, where e is the normalized matrix.
Try setting p(:,u)=e(:.u) at the end of the loop for each u.
 

Similar threads

  • · Replies 9 ·
Replies
9
Views
2K
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 16 ·
Replies
16
Views
3K
Replies
15
Views
3K
  • · Replies 7 ·
Replies
7
Views
2K
Replies
2
Views
2K
  • · Replies 6 ·
Replies
6
Views
5K
  • · Replies 5 ·
Replies
5
Views
2K