Given a matrix A, find all matrices such that AB = BA
问题 Given a square matrix A, find all matrices X such that AX = XA. This is a particular case of a Sylvester equation (one of the form AX + XB = Q) when A = B and Q is the zero matrix. I know SciPy has a solver for this type of equations, however, since the zero matrix is always a solution to my equation, this solver just gives me this trivial solution. There are infinite solutions to the equation AX = XA, so I'm actually looking for a way to find a basis of the space of solutions. Here's my