Householder Algorithm finding Q

조회 수: 41 (최근 30일)
Frederick Melanson
Frederick Melanson 2021년 3월 8일
답변: Athul Prakash 2021년 3월 12일
Hi, i have this algorithm:
function [Q,R] = householder(A)
% Write your code here.
[m,n]=size(A);
Q=eye(m);
for k=1:n
z = -sign(A(k,k))*norm(A(k:m,k));
v = [zeros(k-1,1); A(k,k)-z; A(k+1:m,k)];
f = v'*v;
if f == 0, continue; end
for j = k:n
c = v'*A(:,j);
A(:,j) = A(:,j)-(2*c/f)*v;
end
end
R=A;
end
I get the correct R matrix, but I can't seem to find Q correctly. Please let me know ASAP
  댓글 수: 2
Jan
Jan 2021년 3월 9일
편집: Jan 2021년 3월 9일
Terms like "ASAP" are not appropriate, if you ask voluntary members of an internet forum to help you.
What did you try to determine Q?
Frederick Melanson
Frederick Melanson 2021년 3월 9일
I added an extra forloop at the end like this:
for j=k:m
c = v'*Q(:,j);
Q(:,j) = Q(:,j)-(2*c/f)*v;
end
Q=Q';
I get the lower triangular part of Q correctly, the problem is with the upper half of the matrix

댓글을 달려면 로그인하십시오.

답변 (1개)

Athul Prakash
Athul Prakash 2021년 3월 12일
Hi Frederick,
You may prefer the MATLAB built-in qr() function.
[Q,R] = qr(M);
See this documentation:
Alternately, you may search the Mathworks File Exchange for alternate implementations of Householder algorithm. For example:
These are submissions by other MATLAB users, and not part of the MATLAB product. It is not tested or qualified by Mathworks, so use at your own responsibility.

카테고리

Help CenterFile Exchange에서 Distributed Arrays에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by