% Givensova rotace

x=[1;2];
G=GRM(x)
y=G*x
norm(y)
norm(x)
G*G'

%
% QR rozklad matice:

format short
A=[1 2 3;4 5 6;7 8 10];

% 1. sloupec

I=[1,2];
x=A(I,1);
Gp=GRM(x);
G1=eye(3);
G1(I,I)=Gp
A2=G1*A;
A2(I(2),1)=0

%

I=[1,3];
x=A2(I,1);
Gp=GRM(x);
G2=eye(3);
G2(I,I)=Gp
A3=G2*A2;
A3(I(2),1)=0

%
% 2. sloupec

I=[2,3];
x=A3(I,2);
Gp=GRM(x);
G3=eye(3);
G3(I,I)=Gp
R=G3*A3;
R(I(2),2)=0
Q=G1'*G2'*G3'

%

function G=GRM(x)
% function G=GRM(x)
% Givens rotation matrix for x of size 2x1,
% Gx=ce_1
r=norm(x);
if r==0
    G=Nan;
    return
end
c=x(1)/r;
s=-x(2)/r;
G=[c -s;s c];
end