-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJacobi.m
More file actions
40 lines (32 loc) · 1.16 KB
/
Jacobi.m
File metadata and controls
40 lines (32 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
function [D,eigenVectorMatrix] = Jacobi(A)
clc;
[row,col] = size(A);
eigenVectorMatrix = eye(row,col);
theta = findTheta(A);
[largest,row_ind,col_ind] = findLargestElement(A);
B = eye(row,col);
B(row_ind,row_ind) = cos(theta);
B(col_ind,col_ind) = cos(theta);
B(row_ind,col_ind) = -sin(theta);
B(col_ind,row_ind) = sin(theta);
% B
D = matrixMultiply(matrixMultiply(findTranspose(B),A),B);
D = removeError(D);
eigenVectorMatrix = eigenVectorMatrix*B;
% D
while(~isDiagonal(D))
[row,col] = size(D);
theta = findTheta(D);
[largest,row_ind,col_ind] = findLargestElement(D);
B = eye(row,col);
B(row_ind,row_ind) = cos(theta);
B(col_ind,col_ind) = cos(theta);
B(row_ind,col_ind) = -sin(theta);
B(col_ind,row_ind) = sin(theta);
D = matrixMultiply(matrixMultiply(findTranspose(B),D),B);
D = removeError(D);
eigenVectorMatrix = eigenVectorMatrix*B;
...D
...eigenVectorMatrix
end
end