如何检查jacobian算法是否完成?

时间:2019-06-11 07:46:08

标签: matlab

我要检查是否矩阵温度的非对角线值接近于零,请完成该过程并从while循环中退出,但不会发生这种情况。 这是我在Matlab中的代码。

format long;

A = [1 2 4 ; 2 3 6 ; 4 6 5];
size_A = size(A);
disp(A)

%holds A_k
temp = A;
disp(temp)
%epsilon
e = 0.001;

%used in if condition in while loop
check = ones(size_A(1)) - eye(size_A(1));

%condition for finishing the process
finish = 1;

%jacobian algorithm
while finish

    %finding index of the absolute maximum value of array
    [i,j] = find(abs(temp) == max(max(abs(temp - diag(diag(temp))))),1);

    %calculating sinus and cosine
    r = -temp(i,j);
    s = (temp(i,i) - temp(j,j))/2;
    t = sqrt(r^2 + s^2);
    cos_theta = sqrt((t + abs(s))/2*t);
    sin_theta = abs(r)/2*t*cos_theta;

    %declaring E_pq
    E = eye(size_A(1));
    E(i,i) = cos_theta;
    E(i,j) = sin_theta;
    E(j,i) = -sin_theta;
    E(j,j) = cos_theta;

    temp = E' * temp * E;
    %disp(temp);
    %disp((temp < 0.001 - diag(diag(temp < 0.001))));

    %check if non-diagonal values are approximately equal to zero
    if check == ((temp - diag(diag(temp))) < 0.001) 
        finish = 0;
    end

end

0 个答案:

没有答案