function [d,V]=Jacobi1(A);
% JACOBI1 computes the eigen-decomposition of a symmetric matrix
%   [d,V]=Jacobi1(A) computes the eigenvalues d and the eigenvectors V
%   of the symmetric matrix A, a first version not using the symmetry
%   of the matrix in the algorithm

n=length(A); V=eye(size(A));
S=1;
while S~=0                                            % sweep
  for p=1:n-1
    for q=p+1:n
      theta=(A(q,q)-A(p,p))/2/A(p,q);                 % rotate a_pq=0
      t=1/(abs(theta)+sqrt(1+theta^2));
      if theta<0, t=-t; end
      c=1/sqrt(1+t^2); s=c*t;
      h=A(p,:)*c-A(q,:)*s;                            % A=U^T*A
      A(q,:)=A(p,:)*s+A(q,:)*c;
      A(p,:)=h;
      h=A(:,p)*c-A(:,q)*s;                            % A=A*U
      A(:,q)=A(:,p)*s+A(:,q)*c;
      A(:,p)=h;
      h=V(:,p)*c-V(:,q)*s;                            % V=V*U
      V(:,q)=V(:,p)*s+V(:,q)*c;
      V(:,p)=h;
   end 
  end 
  A                                                   % test output
  S=norm(A,'fro')^2-norm(diag(A))^2
end  
d=diag(A);
