# Finding all the solutions of some matrix equations

I am trying to find all possible solutions to the following:

A = ( {
{a11, a12},
{a21, a22}
} );
B = ( {
{b11, b12},
{b21, b22}
} );

A.A

{{a11^2 + a12 a21, a11 a12 + a12 a22}, {a11 a21 + a21 a22, a12 a21 + a22^2}}

A.B

{{a11 b11 + a12 b21, a11 b12 + a12 b22}, {a21 b11 + a22 b21, a21 b12 + a22 b22}}

B.A

{{a11 b11 + a21 b12, a12 b11 + a22 b12}, {a11 b21 + a21 b22, a12 b21 + a22 b22}}

B.B

{{b11^2 + b12 b21, b11 b12 + b12 b22}, {b11 b21 + b21 b22, b12 b21 + b22^2}}


but I am unable to find all solutions, I have found few solutions using:

Solve[
{a11^2 + a12 a21 == a11, a11 a12 + a12 a22 == a12,
a11 a21 + a21 a22 == a21, a12 a21 + a22^2 == a22,
a11 b11 + a12 b21 == b11, a11 b12 + a12 b22 == b12,
a21 b11 + a22 b21 == b21, a21 b12 + a22 b22 == b22,
a11 b11 + a21 b12 == b11, a12 b11 + a22 b12 == b12,
a11 b21 + a21 b22 == b21, a12 b21 + a22 b22 == b22,
b11^2 + b12 b21 == a11, b11 b12 + b12 b22 == a12,
b11 b21 + b21 b22 == a21, b12 b21 + b22^2 == a22},
{a11, a12, a21, a22, b11, b12, b21, b22}]


but not all. Hence, I want to find all solutions.

Also I am trying to solve a similar problem in the 5x5 case. I type the following:

A = ( {
{a11, a12, a13, a14, a15},
{a21, a22, a23, a24, a25},
{a31, a32, a33, a34, a35},
{a41, a42, a43, a44, a45},
{a51, a52, a53, a54, a55}
} );
B = ( {
{b11, b12, b13, b14, b15},
{b21, b22, b23, b24, b25},
{b31, b32, b33, b34, b35},
{b41, b42, b43, b44, b45},
{b51, b52, b53, b54, b55}
} );
C = ( {
{c11, c12, c13, c14, c15},
{c21, c22, c23, c24, c25},
{c31, c32, c33, c34, c35},
{c41, c42, c43, c44, c45},
{c51, c52, c53, c54, c55}
} );
D = ( {
{d11, d12, d13, d14, d15},
{d21, d22, d23, d24, d25},
{d31, d32, d33, d34, d35},
{d41, d42, d43, d44, d45},
{d51, d52, d53, d54, d55}
} );
E = ( {
{e11, e12, e13, e14, e15},
{e21, e22, e23, e24, e25},
{e31, e32, e33, e34, e35},
{e41, e42, e43, e44, e45},
{e51, e52, e53, e54, e55}
} );

Solve[{A.A == A, A.B == B, A.C == C, A.D == D, A.E == E, B.A == B, B.B == C, B.C == D, B.D == E, B.E == A, C.A == C, C.B == D, C.C == E, C.D == A, C.E == B, D.A == D, D.B == E, D.C == A, D.D == B, D.E == C, E.A == E, E.B == A, E.C == B, E.D == C, E.E == D},{a11, a12, a13, a14, a15,a21, a22, a23, a24, a25,a31, a32, a33, a34, a35, a41, a42, a43, a44, a45,a51, a52, a53, a54, a55,b11, b12, b13, b14, b15,b21, b22, b23, b24, b25,b31, b32, b33, b34, b35,b41, b42, b43, b44, b45,b51, b52, b53, b54, b55,c11, c12, c13, c14, c15,c21, c22, c23, c24, c25,c31, c32, c33, c34, c35,c41, c42, c43, c44, c45,c51, c52, c53, c54, c55,d11, d12, d13, d14, d15,d21, d22, d23, d24, d25,d31, d32, d33, d34, d35,d41, d42, d43, d44, d45,d51, d52, d53, d54, d55,e11, e12, e13, e14, e15,e21, e22, e23, e24, e25,e31, e32, e33, e34, e35,e41, e42, e43, e44, e45,e51, e52, e53, e54, e55} ]


But it shows a red thing on the right hand side. What is wrong?

• I am unsure what the equation is you're trying to solve. I only see matrix definitions and operations here. – Sjoerd Smit Nov 15 '18 at 11:54
• @SjoerdSmit I want to find all possible matrices that satisfy the four equations, where A and B are arbitrary 2x2 matrices. I must add let us find all solutions as integers. – Maths Nov 15 '18 at 11:55
• I'm sorry, but I don't see any equations here. An equation has two sides with an == sign in between. You have a lot of equations inside of Solve, but nowhere else in your post. – Sjoerd Smit Nov 15 '18 at 11:57
• no problem, the equations are A^2=A, AB=B, BA=B and B^2=A – Maths Nov 15 '18 at 11:58
• also I would like to the solutions as matrices – Maths Nov 15 '18 at 12:27

Solve[{A.A == A, A.B == B, B.A == B, B.B == A},Join[Flatten[A], Flatten[B]]]


gives a bunch of solutions!

Alternativly Reduce might be useful:

Reduce[{A.A == A, A.B == B, B.A == B, B.B == A},Join[Flatten[A], Flatten[B]]]
% /. {a11 -> 1, a12 -> 0, a21 -> 0, a22 -> 1, b11 -> 0, b12 -> 1, b21 -> 1, b22 -> 0}
(*True*)

• they give the same solutions as the method I did above, but I want all solutions! – Maths Nov 15 '18 at 12:13
• for example the solution which I found analytically is not given in these solutions i.e when A=[1,0:0,1] and B=[0,1:1,0] – Maths Nov 15 '18 at 12:15
• If Solve doesn't calculate all solutions you can use Reduce( I edit my answer) – Ulrich Neumann Nov 15 '18 at 13:10