Question

I have to multiply to matrices A and B which can consist of numbers 0,2,3,4,5,6 to get an identity matrix, however multiplication happens with moduli after every step. e.g.:

[A1 A2 A3]    and      [B1 B2 B3]
[A4 A5 A6]             [B4 B5 B6]
[A7 A8 A9]             [B7 B8 B9]

((A1*B1)%7+(A2*B4)%7+(A3*B7)%7)%7 = 1 

Which would be the element I_11

How can i find two matrices A and B?

Was it helpful?

Solution

Code to get possible combinations of A and B that would satisfy the required condition -

nums = [0,2,3,4,5,6]    

%// allcomb is a MATLAB File-exchange tool available at -
%// http://www.mathworks.in/matlabcentral/fileexchange/10064-allcomb
t1 = allcomb(nums,nums) 

t2 = mod(prod(t1,2),7)==1
out_comb = t1(t2,:)

Output is -

out_comb =

     2     4
     3     5
     4     2
     5     3
     6     6

This means that the possible combinations of A and B would be (assuming I means 3x3 sized identity matrix) -

A is 2I, B is 4I and A is 4I, B is 2I %%// 2I would be 2.*I and so on
A is 3I, B is 5I and A is 5I, B is 3I
A is 4I, B is 2I and A is 2I, B is 4I
A is 5I, B is 3I and A is 3I, B is 5I
A is 6I, B is 6I and A is 6I, B is 6I

Thanks to the pointer by @Luis, note that you can mix and match these numbers as follows to have more combinations of A and B to choose from -

A as diag([2 4 6]) and B as [4 2 6])
A as diag([5 3 2]) and B as [3 5 4])

OTHER TIPS

Note that it suffices to take the modulo operation at the end. Removing the intermediate modulo operations won't afffect the result. So the condition is that mod(A*B,7) should equal the identity matrix.

Now, since rem(6^2,7) equals 1, a solution is

 A = [ 6     0     0
       0     6     0
       0     0     6 ];

 B = [ 6     0     0
       0     6     0
       0     0     6 ];

Check:

>> rem(A*B,7)
ans =
     1     0     0
     0     1     0
     0     0     1

Another possibility: since rem(2*4,7) is also 1:

 A = [ 2     0     0
       0     2     0
       0     0     2 ];

 B = [ 4     0     0
       0     4     0
       0     0     4 ];

And you could of course combine:

 A = [ 2     0     0
       0     4     0
       0     0     6 ];

 B = [ 4     0     0
       0     2     0
       0     0     6 ];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top