Here I have a code written in MATLAB which performs the QR-decomposition of a square matrix $A$ using Givens-Rotations:
function [ Q,R ] = givens ( A )
[~,n] = size(A);
P = eye (n);
for i = 1:n
for j = i+1:n
if (A(i,i) && A(j,i)) == 0
P_j = P;
else
lambda = sqrt(A(i,i)^2 + A(j,i)^2);
P_j = eye(n);
P_j(i,i) = A(i,i)/lambda;
P_j(j,j) = A(i,i)/lambda;
P_j(i,j) = A(j,i)/lambda;
P_j(j,i) = -A(j,i)/lambda;
end
A = P_j * A;
P = P_j * P;
end
end
R = A;
Q = P';
end
Now you can solve a linear system $Ax = b$ with the QR-decomposition with the following code:
function [ x ] = solvelinearsystemQR( Q,R,b )
b = Q' * b;
x = zeros(length(b),1);
for k = length(b):-1:1
x(k,1) = (b(k) - sum(R(k,(k+1):end) * x((k+1):end,1)))/R(k,k);
end
end
since $$Ax = b \quad \Leftrightarrow \quad QRx = b \quad \Leftrightarrow \quad Rx = Q^Hb$$ and $R$ is upper triangular so elementary backwardsubstitution can be applied.