function [Q, R] = QRdecomp_student(A)
% Factorization of given matrix [A] into Upper triagular [R] and orthogonormal [Q]
% Using HouseHold Matrix
% Input: A (nxn)
% Output: Q (nxn), R (nxn)
% Initialization
n = size(A,1);
I=eye(n);
R=A;
Q = I;
for j = 1:n-1
% Create vector [c]
% [YOUR CODE GOES HERE]
% c = _______________;
% Create vector [e]
e=zeros(n,1);
% [YOUR CODE GOES HERE]
% e = _______________;
% Create vector [v]
% [YOUR CODE GOES HERE], HINT: use norm(c,2)
% v = _______________;
% Create matrix [H]
% [YOUR CODE GOES HERE]
% H = _______________;
% Update [Q], [R]
Q = Q*H;
R = H*R;
end
end % end of function
Run the code and check the answer with MATLAB's eig(A)
% initialize
N=100;
U=A;
for i = 1:N
% Step 1: A=QR decomposition
[Q, R] = QRdecomp_student(U);
% Step 2: Create Similar Matrix A = Q'AQ
U = R*Q;
if(~mod(i,10))
disp(sprintf('iteration %d \n',i));
U
end
end
% Step 3: eigenvalues from U
lamdas = diag(U);