# Square root of a 2 by 2 matrix using MatrixPower[]

According to Wikipedia a square root of a 2×2 matrix M is another 2×2 matrix R such that M = R^2. In general, there can be zero, two, four, or even an infinitude of square-root matrices.

I tried to use MatrixPower with n=1/2 with a classic case of 4 solutions (determinant and trace are non zero) but it returns only one solution... (Mathematica 11.0)

MatrixPower[{{17, -16}, {-8, 9}}, 1/2]
(* return 1 solution {{11/3, -(8/3)}, {-(4/3), 7/3}} *)

What about the other 3 ? How to get the four of them ?

In:= MatrixPower[{{-3, 4}, {2, -1}}, 2]
In:= MatrixPower[{{3, -4}, {-2, 1}}, 2]
In:= MatrixPower[{{11/3, -(8/3)}, {-(4/3), 7/3}}, 2]
In:= MatrixPower[{{-(11/3), 8/3}, {4/3, -(7/3)}}, 2]
Out= {{17, -16}, {-8, 9}}

Of course, I can try Solve[MatrixPower[{{a, b}, {c, d}}, 2] == {{17, -16}, {-8, 9}}, {a, b, c, d}] and I'll get 4 solutions, but... why MatrixPower has such undocumented limitation ?

Does anybody know a clever command to overcome this behavior or should I write a dedicated function to handle these cases ?

• By convention, when things like Power[] or MatrixPower[] are evaluated, only the principal root is taken. Feb 1, 2021 at 11:39
• To put J.M.'s comment in other words, Sqrt[4] also only gives us one solution ($+2$) even though there are two ($+2$ and $-2$) available. Feb 1, 2021 at 11:41
• I would be aghast if MatrixPower returned anything other than a matrix; any other behavior would make it useless. So that "limitation" is both by design and utterly necessary. Feb 1, 2021 at 13:57

The nice thing about Mathematica is that one can (almost) always go back to the definitions if in doubt. For evaluating non-principal roots, one can just go back to the Jordan decomposition of a matrix and change square root signs accordingly. To wit,

{sm, jm} = JordanDecomposition[{{17, -16}, {-8, 9}}];

Table[sm.DiagonalMatrix[d].Sqrt[jm].Inverse[sm], {d, Tuples[{1, -1}, 2]}]
{{{11/3, -8/3}, {-4/3, 7/3}}, {{-3, 4}, {2, -1}},
{{3, -4}, {-2, 1}}, {{-11/3, 8/3}, {4/3, -7/3}}}
• N.B. I exploited here the fact that jm is actually diagonal. If jm had a Jordan block in it, things are not as straightforward. Feb 1, 2021 at 14:05

Here's an approach that's based on an answer I posted on Code Golf SE, with key assistance from member @att: Calculate the integer square root of a matrix

I've removed the integer restriction, and the restriction to give only one solution. I also added RootReduce to put the matrix elements into simpler form (this has no effect here, but can be helpful for solutions with radicals). This will work for both diagonalizable and non-diagonalizable square matrices of any dimension.

m={{17,-16},{-8,9}};

(d=Length@#; q=Array[s,{d,d}])/.RootReduce@Solve[q.q==#]&@m

{ {{3, -4}, {-2, 1}}, {{11/3, -(8/3)}, {-(4/3), 7/3}}, {{-(11/3), 8/ 3}, {4/3, -(7/3)}}, {{-3, 4}, {2, -1}} }

UsingSolve makes it easy to filter solutions based on a domain restriction. E.g., this gives only integer solutions:

(d=Length@#; q=Array[s,{d,d}])/.RootReduce@Solve[q.q==#, Integers]&@m

{ {{-3, 4}, {2, -1}}, {{3, -4}, {-2, 1}} }