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 attempt for a little example I worked on paper:
import numpy as np
import scipy
from sympy import *
A = np.array([[-2, 1, 1],[3, -3, 0], [1, 0, -1]])
X = np.array([["a", "b", "c"], ["d", "e", "f"], ["g", "h", "i"]])
Q = np.zeros_like(L)
var('a b c d e f g h i L S')
A = Matrix([[-2, 1, 1],[3, -3, 0], [1, 0, -1]])
X = Matrix([[a, b, c], [d, e, f], [g, h, i]])
M = A.multiply(X) - X.multiply(A)
M
I can't figure out a way to "extract" the coefficients of the matrix M. If I could do this, then I would have the coefficient matrix of a homogeneous system of linear equations and maybe then I could get a non-trivial solution or all the possible solutions to this problem.