比较两个在MATLAB / Octave中产生错误的相同矩阵

时间:2014-12-07 06:26:15

标签: matlab matrix comparison octave

我有以下代码。我试图显示矩阵反转的属性。具体做法是:

inv(A*B) = inv(B)*inv(A)

我写了以下代码:

disp("Verifying if inv(A*B) = inv(B)*inv(A)");
A = [1 2 ; 3 4]
B = [1 6 ; 5 7]
format short
E = A*B;
C = inv(E);
disp("inv(A*B) is :"), disp(rats(C));
D = inv(B)*inv(A);
disp("inv(B)*inv(A) is :"), disp(rats(D));
if (isequal(C,D))
    disp("Yes they are equal");
else 
    disp("No they are not equal");
endif

这是我收到的输出:

Verifying if inv(A*B) = inv(B)*inv(A)
A =

   1   2
   3   4

B =

   1   6
   5   7

inv(A*B) is 
          1     -10/23
       -1/2      11/46
inv(B)*inv(A) is :
          1     -10/23
       -1/2      11/46
No they are not equal

声明怎么不相等?

0 个答案:

没有答案