Is it true that any matrix in $M_2(\mathbb R)$ is the sum of two squares? I recently show that every polynomial with real coefficient and $P$ is always is a sum of two squares of polynomials, therefore positive. These questions also appear often in arithmetic.

What if we change polynomials by matrices?

I ask my professor and unfortunately he had no idea if this result is already shown or not.
I tried, unsuccessfully, several tracks :
First denote that $$\forall M\in M_n(\mathbb R) , M=1/2[(A+A{}^t)+(A-A{}^t)].$$
and perhaps used the following result :

*

*Any symmetric positive matrix admits a square root

Proof.
By spectral theorem, there exist $\Omega \in \mathbb O_n(\mathbb R)$ and $(\lambda_1,...\lambda_n)\in (\mathbb R^{+})^n$ such that $S=\Omega D \Omega^{-1}$ with $D$ the diagonal matrix formed by the positive eigenvalues​​.
Let $D'$ the diagonal matrix formed of the roots of the eigenvalues​​.
Then , $D'²=S$ and  $D'{}^t=D'$ thus she is a symmetric positive matrix.

Question : Is it possible to believe that all matrices (say in $M_2(\mathbb R)$) are the sum of two squares?
 A: Your statement is TRUE. To begin with, let us introduce some notations and prove some useful facts first. Given $\lambda\ge 0$ and $\theta\in \Bbb R$, define
$$R(\lambda,\theta):=\lambda\cdot\begin{pmatrix}\cos \theta & -\sin \theta\\ \sin \theta & \cos \theta\end{pmatrix}\in M_2(\Bbb R),$$
and note that 
$$R(\lambda,\theta)= \big(R(\sqrt{\lambda},\frac{\theta}{2})\big)^2.$$
Given $M=\begin{pmatrix}a & b\\ c & d\end{pmatrix}\in M_2(\Bbb R)$, denote 
$$\Delta(M):=({\rm tr}M )^2-4\cdot\det M=(a-d)^2+4bc, $$
which is the discriminant of the characteristic polynomial of $M$.


Lemma:  Given $M\in M_2(\Bbb R)$, $\Delta(M)<0$ if and only if the exist $T\in GL_2(\Bbb R)$, $\lambda>0$ and $\theta\in (0,\pi)$, such that 
  $$T^{-1}MT=R(\lambda,\theta).\tag{1}$$

Proof:
$\Delta(M)< 0$ if and only if there exist $\lambda>0$ and $\theta\in(0,\pi)$, such that the two eigenvalues of $M$ are $\lambda e^{i\theta}$ and $\lambda e^{-i\theta}$, so the "if" part is obviously true. To prove the "only if" part, let $u+iv$ be an eigenvector of $M$ with eigenvalue $\lambda e^{-i\theta}$, where $u,v\in\Bbb R^2$. Then $u-iv$ is an eigenvector of $M$ with eigenvalue $\lambda e^{i\theta}$, so $u$ and $v$ are linearly independent. Moreover, 
$$M(u+iv)=\lambda e^{-i\theta}(u+iv)=\lambda\big((\cos \theta\cdot u+\sin \theta\cdot v)+i (-\sin \theta\cdot u +\cos \theta\cdot v)\big).$$
That is to say, $(1)$ holds for $T=(u,v)$. $\quad\square$


Corollary: If $\Delta(M)<0$, then there exists $N\in M_2(\Bbb R)$, such that $M=N^2$.

Proof:
According to the lemma, $(1)$ holds for $M$. Then for $N=T\cdot R(\sqrt{\lambda} ,\frac{\theta}{2})\cdot T^{-1}\in M_2(\Bbb R)$, $M=N^2$. $\quad\square$

Now let us prove your statement. Given $\lambda>0$ and $M=\begin{pmatrix}a & b\\ c & d\end{pmatrix}\in M_2(\Bbb R)$, 
$$M_\lambda:=M+R(\lambda, \frac{\pi}{2})=\begin{pmatrix}a & b-\lambda\\ c+\lambda & d\end{pmatrix}\Longrightarrow \lim_{\lambda\to+\infty}\Delta(M_\lambda)=-\infty.$$
Then by the corollary, when $\lambda>0$ is large, $M_\lambda =N_\lambda ^2$ for some $N_\lambda \in M_2(\Bbb R)$. As a result,
$$M= M_\lambda +R(\lambda, -\frac{\pi}{2})=N_\lambda ^2 + \big( R(\sqrt{\lambda},-\frac{\pi}{4})\big )^2,$$
which completes the proof.

Remark Added: In fact, it is not very hard to prove the following statement.

Proposition: 
  Given $M\in M_2(\Bbb R)$, let $\lambda_1$ and $\lambda_2$ be the two eigenvalues(counting multiplicity) of $M$, and $\Re\lambda_1\ge \Re\lambda_2$, where $\Re z$ denotes the real part of $z\in\Bbb C$. Then there exists $N\in M_2(\Bbb R)$   such that $M=N^2$if and only if one of the following conditions holds:
  
  
*
  
*$\lambda_1>0$ and $\lambda_2\ge 0$, or equivalently, $\det M\ge 0$ and ${\rm tr }M >0$;
  
*$|\lambda_1|=|\lambda_2|:=\lambda$, and there are $T\in GL_2(\Bbb R)$ and $\theta\in [0,\pi]$ such that $T^{-1}MT=R(\lambda, \theta)$. 
  

Then to prove your statement, it suffices to show that for every $M\in  M_2(\Bbb R)$, there eixst $A, B\in M_2(\Bbb R)$, such that $M=A+B$ and for both $A$ and $B$, either case 1. or case 2. holds. In Jack's answer, it is shown that one of $A$ and  $B$ can be chosen from case 1. and the other from case 2.;  in my answer, it is shown that  $A$ and $B$ can be chosen from case 2. simultaneously.
A: Let us answer the more general question first:

Is every real square matrix the sum of squares of two real matrices? That is, given $M\in M_n(\mathbb R)$, is it always possible to write $M=A^2+B^2$ for some $A,B\in M_n(\mathbb R)$?

The answer is no.

Lemma 1 (cf. Horn and Johnson, Topics in Matrix Analysis, theorem 6.4.14, p.473). If a real square matrix $X$ has a real matrix square root, each Jordan block of $X$ corresponding to a negative eigenvalue must occur an even number of times.

Now, for a counterexample, consider $n=3$ and $M=-I$. If $A$ is a real square matrix, it is not hard to see that in the (complex) Jordan decomposition of $-I-A^2$, there must be some Jordan block of size 1 that corresponds to a negative eigenvalue and occurs only once in the Jordan form. Hence, by lemma 1, $-I-A^2$ has not any real square root, i.e. it is not possible to write $-I=A^2+B^2$ for some real $A,B$.
However, when $n=2$, the answer is yes. I believe that Jack has answered your question nicely. If you don't like the explicit formula that Jack has used, here is an alternative perspective. First, we have the following lemma, which is closely related to lemma 1:

Lemma 2 (cf. Walter J. Culver, On the existence and uniqueness of the real logarithm of a matrix, Proceedings of the American Mathematical Society, 17(5): 1146-1151, 1966). A real matrix has a real logarithm if and only if it is nonsingular and in its (complex) Jordan normal form, every Jordan block corresponding to a negative eigenvalue occurs an even number of times.

Now, given any $M\in M_2(\mathbb R)$ and sufficiently large $d>0$, the matrix
$$
M-A^2 := M-{\underbrace{\pmatrix{0&-\sqrt{d}\\ \sqrt{d}&0}}_A}^2 = M+dI
$$
has not any zero or negative eigenvalue. Therefore, by lemma 2, $M-A^2=e^Y$ for some real matrix $Y$. Put $B=e^{Y/2}$, we have $M=A^2+B^2$.
A: Emotions seem to have run a little high here. However, I believe Jack's answer to be right and quite clever. I think confusion has arisen because the answer is quite compact. Therefore I will try to explain Jack's answer.
Let 
$$
M =
\begin{pmatrix}
 A & B\\
 C & D
\end{pmatrix}
$$ 
be any matrix with trace $\tau = A+D$ and determinant $\delta= AD-BC$. By the wikipedia link, we know that if $\delta>0$ and $\tau+2\sqrt{\delta}>0$, then $M$ has a square root, namely
$$
R = \frac{1}{\sqrt{\tau+2\sqrt{\delta}}}
\begin{pmatrix}
 A + \sqrt{\delta} & B\\
 C & D + \sqrt{\delta}
\end{pmatrix},
$$
see the wikipedia link to verify it is indeed a square root. 
Now unfortunately this only works when $\delta>0$ and $\tau+2\sqrt{\delta}>0$, but Jack proposes the following solution. Lets just add a diagonal matrix
$$
N = M + cI = 
\begin{pmatrix}
 A + c & B\\
 C & D +c
\end{pmatrix}.
$$ 
Then by making $c$ big enough the trace and determinant of $N$ will both be higher than zero, which means that $N$ has a square root. Moreover
$$
-cI =
\begin{pmatrix}
 0 & -\sqrt{c}\\
 \sqrt{c} & 0
\end{pmatrix}^2,
$$ 
so 
$$
M = N + (- cI),
$$
which is the sum of two squares.
A: Let $dI$ be the identity multiplied by a large positive number $d$.
Then $A+dI$ has a square root. So $A+dI=B^2$
But $-dI=\begin{bmatrix}0&-\sqrt{d}\\\sqrt{d}&0\end{bmatrix}^2$.
So, $$A=B^2+\begin{bmatrix}0&-\sqrt{d}\\\sqrt{d}&0\end{bmatrix}^2$$
