<s>[INST] Square root of a matrix. Determine all $A,B \in \mathbf{M}_{2}(\mathbf{R})$ such that $A^2+B^2=\begin{pmatrix} 22 & 44\\  
14 & 28 \end{pmatrix}$ and $AB+BA=\begin{pmatrix} 10 & 20\\  
2 & 4 \end{pmatrix}$.
I have tried to assume that $A=\begin{pmatrix} a & b\\  
c & d \end{pmatrix}$ and $B=\begin{pmatrix} e & f\\  
g & h \end{pmatrix}$. And we know that $(A+B)^{2}=A^{2}+B^{2}+AB+BA$ and $(A-B)^{2}=A^{2}+B^{2}-(AB+BA)$. Then, I will end up with $8$ equations and $8$ which can be solve, but it is really complicated. I am just wondering if someone could show me how to take the square root of an matrix. Please if you show that please make sure that you will prove it.  
Would any one have an idea what is the input code for solving that in MATLAB
 [/INST] Here is a general approach to find all square root of a $2\times2$ matrix $A$ which is not a multiple of the identity matrix.
Assume that $X^2 = A$. If we write $t = \operatorname{tr}(A)$ and $d = \det(A)$, then by the Cayley-Hamilton theorem we have
$$ X^2 - tX + dI = 0. $$
Plugging this to $X^2 = A$, we have $A = tX - dI$. Since $A$ is not a multiple of $I$, $t$ is automatically non-zero and we can write
$$X = \frac{1}{t}(A + dI). \tag{1}$$
So it suffices to determine $d$ and $t$. For $d$, we know that
$$d^2 = \det(X)^2 = \det(X^2) = \det(A) \qquad \Rightarrow \qquad d = \pm\sqrt{\det(A)}, \tag{2}$$
which can be computed. Similarly,
$$ \operatorname{tr}(A) = \operatorname{tr}(tX - dI) = t^2 - 2d \qquad \Rightarrow \qquad t = \pm \sqrt{2d + \operatorname{tr}(A)}. \tag{3}$$
This shows that if $X^2 = A$, then $X$ must be of the form $\text{(1)}$ with $d$ and $t$ as above. Conversely, if $d$ and $t$ are as above, then $X$ given by $\text{(1)}$ satisfies
\begin{align*}
X^2
&= \frac{1}{t^2}(A^2 + 2dA + d^2I) \\
&= \frac{1}{t^2}(\operatorname{tr}(A)A - \det(A)I + 2dA + d^2I) \\
&= \frac{1}{t^2}((t^2 - 2d)A - d^2I + 2dA + d^2I) \\
&= A.
\end{align*}
Therefore $X^2 = A$ if and only if $X$ is given by $\text{(1)}$ with $d$ and $t$ given by $\text{(2)}$ and $\text{(3)}$.

Now in your case,
$$ (A+B)^2 = \begin{pmatrix} 32 & 64 \\ 16 & 32 \end{pmatrix}
\quad \Rightarrow \quad d = 0
\quad \Rightarrow \quad t = \pm 8
\quad \Rightarrow \quad A+B = \pm \begin{pmatrix} 4 & 8 \\ 2 & 4 \end{pmatrix} $$
and likewise
$$ (A-B)^2 = \begin{pmatrix} 12 & 24 \\ 12 & 24 \end{pmatrix}
\quad \Rightarrow \quad d = 0
\quad \Rightarrow \quad t = \pm 6
\quad \Rightarrow \quad A-B = \pm \begin{pmatrix} 2 & 4 \\ 2 & 4 \end{pmatrix} $$
This will give you all the possible 4 choices of the pair $(A, B)$.

Remark. If you want to solve an equation of the form $X^2 = kI$, then the general form of $X$ is
$$ X = \begin{pmatrix}a & b \\ c & -a \end{pmatrix} \quad \text{or} \quad \pm\sqrt{k} I, $$
with $a^2 + bc = k$. So there may be an infinitely many solution.
</s>