function x=EliminationGivens(A,b);
% ELIMINATIONGIVENS solves a linear system using Givens-rotations
%   x=EliminationGivens(A,b) solves Ax=b using Givens-rotations. Uses
%   the function BackSubstitutionSAXPY.

n=length(A);
for i= 1:n
  for k=i+1:n
    if A(k,i)~=0
      cot=A(i,i)/A(k,i);                       % rotation angle
      si=1/sqrt(1+cot^2); co=si*cot;
      A(i,i)=A(i,i)*co+A(k,i)*si;              % rotate rows
      h=A(i,i+1:n)*co+A(k,i+1:n)*si;
      A(k,i+1:n)=-A(i,i+1:n)*si+A(k,i+1:n)*co; 
      A(i,i+1:n)=h;
      h=b(i)*co+b(k)*si;                       % rotate right hand side
      b(k)=-b(i)*si+b(k)*co; b(i)=h;
    end
  end;
  if A(i,i)==0 
    error('Matrix is singular');
  end;
end
x=BackSubstitutionSAXPY(A,b);
