% Givens formula applied to a random vector of length n:
% Make the random vector:
n = 6;
a = rand(6,1);
% We want to zero a(j) and put the left-over 'weight' in in a(i):
i = 2;
j = 4;
% Compute c and s as derived in class:
ai = a(i);
aj = a(j);
c = ai/sqrt(ai^2+aj^2);
s = aj/sqrt(ai^2+aj^2);
% For the Givens matrix:
G = eye(n);
G(i,i) = c;
G(j,j) = c;
G(i,j) = s;
G(j,i) = -s;
G
% Compute G*a
G*a