Jacobi Rotation
Jacobi Rotation
Jacobi Rotation
m 1 of 2
%-----------------------------------------------------------------------% This code performs Similarity Transformation corresponding to Jacobi
% Rotation to compute eigen values and eigen vectors of a symmetric matrix [A].
% [A*] = [R'][A][R]
% [A*] is a diagonal matrix with eigen values as diagonal elements
% Final transformation matrix is stored in [P] and is the accumulation of
% individual rotations [Ri].
% AML702: Advance Computational Method, IIT Delhi
% Praveen Kumar Srivastava, 2011AMZ8095
% Nomesh Kumar 2011AMZ8097
% Suresh Kumar 2011CEZ8273
%-----------------------------------------------------------------------tol = eps; n = size(A,1); max_rotation = 100;
% Initialize rotation matrix [P]
P = eye(n);
% Begin Rotation
for k = 1:max_rotation
% Find maximum off-diagonal element in [A] and its index p & q
Amax = 0.0;
for i = 1:n-1
for j = i+1:n
if abs(A(i,j))>= Amax
Amax = abs(A(i,j));
p = i;
q = j;
end
end
end
% If Amax is < eps, then print results
if Amax < tol
fprintf( '\nEigen values (e_val) and Eigen vectors (e_vect) of [A] at the end of k_th rotation:\n')
e_val = diag(diag(A))
e_vect = P
k
return
end