constructive canonical form of orthogonal matrix For every orthogonal matrix $Q$ over the reals there is an orthogonal matrix $P$ and a block diagonal matrix $D$ such that $D=PQP^{t}$. Each block in D is either $(1)$, $(-1)$ or a two dimensional block of the form $\left( \begin{array}{cc}
\cos(\alpha) & -\sin(\alpha)  \\
\sin(\alpha) & \cos(\alpha)  \\
\end{array} \right) $. Is there a constructive proof for this fact? Maybe a code in Matlab or sage?
 A: You could go with a real Schur decomposition, which is a constructive proof. There is one here: it constructs a single $1 \times 1$ or $2 \times 2$ diagonal block and then goes on inductively.
After you do that, use the orthogonality to show that $T$ (the triangular factor from the Schur decomposition) is orthogonal quasidiagonal (it has blocks of order at most $2$).
Next, it is easy to show that blocks themselves must be orthogonal. The blocks of order $1$ are trivial. As for the blocks of order $2$, go with the most general form:
$$U = \begin{bmatrix} u_{11} & u_{12} \\ u_{21} & u_{22} \end{bmatrix}.$$
Now, use that $U^TU = {\rm I}_2$ and $UU^T = {\rm I}_2$, so
\begin{align*}
\begin{bmatrix} u_{11}^2 + u_{21}^2 & u_{11} u_{12} + u_{21} u_{22} \\ u_{11} u_{12} + u_{21} u_{22} & u_{12}^2 + u_{22}^2 \end{bmatrix} = \begin{bmatrix} 1 \\ & 1 \end{bmatrix}, \\
\begin{bmatrix} u_{11}^2 + u_{12}^2 & u_{11} u_{21} + u_{12} u_{22} \\ u_{11} u_{21} + u_{12} u_{22} & u_{21}^2 + u_{22}^2 \end{bmatrix} = \begin{bmatrix} 1 \\ & 1 \end{bmatrix}.
\end{align*}
From the diagonal elements, you see right away that $u_{12}^2 = u_{21}^2$. Since all is real, $u_{12} = \pm u_{21}$. Then use the nondiagonal elements to get that $u_{11} = \mp u_{22}$. For now, assume that $u_{11} = u_{22} =: c$, so $u_{21} = -u_{12} =: s$ and quickly show that $c$ and $s$ are sine and cosine of some angle $\varphi$.
What is left is the case when $u_{11} = -u_{22}$ (so $u_{12} = u_{21}$). In this case, just compute the eigenvalues (you have the formulas here) and you'll see that they are $1$ and $-1$, which is a contradiction with the fact (from the construction of the real Schur decomposition) that the blocks of order $2$ have complex conjugate pairs of eigenvalues.
