For given two real-symmetric matrices $A$ and $B$, both are of size $M \times M$, I'm trying to find two matrices $C_1$ (size $M\times N_1$) and $C_2$ (size $M\times N_2$) such that $$ AC_1 = C_1\Lambda_1 + C_2S^\top\\ BC_2 = C_1S + C_2\Lambda_2 $$ where $\Lambda_1$, $\Lambda_2$ are diagonal matrices of size $N_1 \times N_1$ and $N_2 \times N_2$, respectively. $S$ is a matrix of size $N_1 \times N_2$, $N_1 + N_2 < M$. The column vectors of $C_1$ and $C_2$ are orthonormal, i.e., $$ C_1^\top C_1 = I_{N_1N_1}\\ C_2^\top C_2 = I_{N_2N_2}\\ C_1^\top C_2 = 0_{N_1N_2} $$ If $A$ commutes with $B$, i.e., $AB = BA$, the solution is straightforward, one can diagonalize $A$ or $B$ and use $N_1 + N_2$ number of eigenvectors to construct $C_1$ and $C_2$, in which case $\Lambda_1$ and $\Lambda_2$ correspond to the eigenvalues and $S$ is simply a zero matrix. My question is, if $A$ does not commute with $B$, how to solve for $C_1$ and $C_2$?
This question arises from a constrained optimization problem where I want to find $C_1$ and $C_2$ to minimize the following quantity: $$ {\rm Tr}(C_1^\top AC_1) + {\rm Tr}(C_2^\top BC_2) $$ subject to the orthonormality constraints. The Lagrangian is $$ \mathcal{L} = {\rm Tr}(C_1^\top AC_1) + {\rm Tr}(C_2^\top BC_2) - {\rm Tr}(\Lambda_1(C_1^\top C_1 - I)) - {\rm Tr}(\Lambda_2(C_2^\top C_2 - I)) - {\rm Tr}(S^\top(C_1^\top C_2)) $$ where $\Lambda_1$, $\Lambda_2$, and $S$ are Lagrangian multipliers. The equations in the original question pop up naturally when setting the gradient of $\mathcal{L}$ to zero and realize that the unitary transformation $C_1 \rightarrow C_1U$ does not change Tr$(C_1^\top AC_1)$ (such that $\Lambda_1$ can be made diagonal), and so does it for $C_2$.
I think the question from the optimization view can be harder than solving the linear equations because even in the case where $AB = BA$, one still needs to sort the eigenvalues of $A$ and $B$ and find a way to pick up the correct states. For this reason, I want to make this post focus mainly on the linear algebra part.