Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

QR Factorization Program

veronicak5678veronicak5678 Posts: 4Member
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?

[code]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)
[/code]
Sign In or Register to comment.