My QR-decomposition code returns transpose of MATLABs Q, why?
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
clear
clc
%Create random integer dimensions m and n
m=randi(100);
n=randi(100);
%Create A of random integer dimensions m and n
A = randn(m,n);
%Assign A to A1 for calculation of relative error in the end
A1=A;
%Assign identity matrix to Q for the very first orthogonal transformation
Q=eye(m);
%Compute smallest dimension. This number will be en number of iterations of
%the loop
mindim=min(m-1,n);
%MATLABs Q and R, use for comparison
[Q1,R1]=qr(A);
for j=1:mindim
[v,tau] = gallery('house',A(j:end,j));
l=length(v);
Z = (eye(length(v)) - tau*(v*v'))';
block = [eye(j-1) zeros(j-1,l); zeros(j-1,l)' Z];
%Multiplying all reflections Q
Q=block'*Q;
%Multiplying all transformations of
A = block'*A;
end
%Q=Q';
R=A;
%Check and see if relative error is small, on the order of E-15.
relerr = norm(A1-Q*R) / norm(A1);
I have a script that takes in any matrix A and should return the factors Q and R of the QR-decomposition. R is created just fine, but my Q is different from MATLABs Q (Q1 in my code) in that it is the transpose of MATLABs Q. Why is this? I have tried finding an explanation but failed. Can anyone explain this to me?
4 Commenti
Torsten
il 11 Set 2022
Since we know what the result must be, the change of
Q=block'*Q;
to
Q = Q*block;
gives the correct Q.
But don't ask me why.
Risposte (0)
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!