# Block diagonalization of matrix via congruence transformation

I have multiple square (and mostly also symmetric) matrices $A_n$ with various dimensions $n$ and I know that some of them are related to each other via a congruence transformation $PA_nP^T = \text{diag}(A_i,A_j,\dots)$ where $i + j + \dots = n$. The right hand side is given by a block diagonal combination of the given matrices. The elements of all matrices involved are integers. Is there an algorithm which allows me to easily calculate the transformation matrix $P$?

• You could maybe rewrite multiplying w. $P^{-1}$: $A_nP^T = P^{-1}D$ and observing $P^{-1}((P^T)^T-P)=0$ followed by alternatingly solving least squares problems for $P^{-1}, P$ and $D$ where non-diagonal entries are punished the more off diagonal they lie. I have tried the approach for diagonalization $A = PDP^{-1}$ and it works there so I don't see why it would not work. – mathreadler Jul 2 '17 at 15:09