Reputation: 79
What is happening in my code? I don't understand why I am getting 2 different different matrices when a^-1 * b^-1 = (a*b)^-1 I have tried writing in another language however I keep getting the same inequality.
Input:
A = [3 5 2; 2 1 -1; 1 2 2];
B = [6 -2 4; 6 4 -12; 12 2 8];
inverseA = A^(-1);
inverseB = B^(-1);
inverseMult = inverseA * inverseB;
inverseMatMult = (A*B)^(-1);
equalityCheck = inverseMult == inverseMatMult;
disp(inverseMult)
disp(inverseMatMult)
disp(equalityCheck)
Output:
-0.4038 -0.0863 0.1974
0.3224 0.0923 -0.1478
-0.1518 -0.0804 0.0804
-0.0317 0.0615 0.0694
0.1190 -0.2619 -0.1667
-0.0357 -0.0089 0.0625
0 0 0
0 0 0
0 0 0
Upvotes: 2
Views: 72
Reputation: 75
You may want to recheck the equation.
It might be because (a * b)^-1= (b)^-1 * (a)^-1;
function [t2,t3,t4]= matrixidentity()
a = [3 5 2; 2 1 -1; 1 2 2];
b = [6 -2 4; 6 4 -12; 12 2 8];
t=a^-1;t1=b^-1;
t2=(a*b)^-1;
t3=t1*t;
t4=t*t1;
end
t2 =
-0.0317 0.0615 0.0694
0.1190 -0.2619 -0.1667
-0.0357 -0.0089 0.0625
t3 =
-0.0317 0.0615 0.0694
0.1190 -0.2619 -0.1667
-0.0357 -0.0089 0.0625
t4 =
-0.4038 -0.0863 0.1974
0.3224 0.0923 -0.1478
-0.1518 -0.0804 0.0804
Here you can see that t2==t3 and thus the equation (a * b)^-1 =(b)^-1 * (a)^-1 holds, whereas
(a * b)^-1=(a)^-1 * (b)^-1 does not hold.
Hope it helps!!
Upvotes: 1
Reputation: 212949
You are assuming an incorrect identity - it should be:
(A*B)^-1 = B^-1 * A^-1
(See useful list of invertible matrix identities here.)
So if you change this line:
inverseMatMult = (A*B)^(-1);
to:
inverseMatMult = (B*A)^(-1);
then you should get the expected result. (Note that the equality check may still fail due to rounding errors, but you should see that the two result matrices are identical to a reasonable number of significant figures.)
Upvotes: 9