Matlab

Moderators: None (Apply to moderate this forum)
Number of threads: 1494
Number of posts: 2174

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
QR Factorization Program Posted by veronicak5678 on 4 Nov 2010 at 6:11 PM
I am writing my first Matlab program. It is supposed to take an mxn matrix of rank n and perform a QR factorization, then display the Q matrix.

I am using the Gram-Schmidt process to generate my basis vectors.
On this matrix
[1 -1 4 1
-2 0 2 1
0 0 0 0
1 -1 4 0]

I get an extra, incorrect column in Q. It must have something to do with the deflation. When I tried to debug, I see that u in step 3 (j =3), u is a vector with 5 elements, the first being something weird with an exponential and an asterisk afterwards. Why would that happen? Can anyone see the problem?

clear
a=input ('Enter an mxn matrix of rank n: ');
[m,n]=size(a);
k=0;
q=[];
c=[];

for j= 1:n ;
        u(:,j) = a(:,j);
        for i = 1:j-1
                u(:,j)=u(:,j)-q(:,i)'*a(:,j)*q(:,i) ;
        end
        n=norm(u(:,j));
        if n~=0
                k=k+1;
                q(:,k)=u(:,j)/n;
        else
                u(:,j)=[];
        end
end

display 'Matrix A is :'
disp( a)
display 'Matrix Q is :'
disp (q)



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.