Matlab's Jacobi Method
You need to write the necessary code instead of comments. I'm not strong in Matlab, can someone help?)
function JacobiRotation
A=[6.6 3.3 1.65 -1.65 ;
3.3 6.6 3.3 1.65;
1.65 3.3 6.6 3.3
-1.65 1.65 3.3 6.6];
eps=1e-6;
%printf('Jacobi:\n')
%Lamda=Jacobi(A,eps)
printf('eig:\n')
eig(A)
endfunction
function Lamda=Jacobi(A,eps)
n=length(A);
nA=norm(A);
k=0;
while true
max=0;p=0;q=0;
%find maximal off-diagonal element in A
if max<=eps*nA
break;
endif
tau=(A(p,p)-A(q,q))/(2*A(p,q));
t=sign(tau)/(abs(tau)+sqrt(1+tau*tau));
c=1/sqrt(1+t*t);s=t*c;
%calculate A->B
A(:,p)=B(:,p);A(:,q)=B(:,q);
%calculate B->A using matrix B
A(p,:)=B(p,:);A(q,:)=B(q,:);
k=k+1;
endwhile
k
Lamda=A;
endfunction
function s=sign(x)
if x<0
s=-1;
else
s=1;
endif
endfunction
0
Author: Захар Дементьев, 2020-04-17