Existence of non-trivial solution of Sylvester equation.

I'm trying to solve a special case of Sylvester equation
in my case it looks like $$A*X=X*B$$ so it can be written in form $$A*X+X*(-B)=C$$ where C consist of all 0 items.

I tried to solve it in Mathematica with LyapunovSolve but it give me all =0 trivial solution.

So I want to check if there is non-trivial solution exist. It seems I find out how to test matrices A,B for non-trivial solution(but I'm not sure) if resultant equals to 0, then such solution exist.$$resultant(det(A-λE),det(B-λE),λ)=0$$ I tried real matrices for example A matrix (0 -1 300 1 0 0 0 0 1) B matrix (-0.4009 -1.0787 446.1463 1.6180 0.8875 -159.2272 0.0003 0.0029 1) but there is maybe a problem because B matrix was defined experimentally and it has some small errors, with these matrices I have resultant -6.79 , but due to errors I don't know may be it close enough to 0?

the question is: can you write condition of existence of non-trivial solution of Sylvester equation not in abstract form but in particular formula, preferably in Mathematica.

Also I don't understand why Mathematica gives me only trivial solution, when I trying to solve this equation with parameters for example I tried

am = {{a11, a12, a13}, {a21, a22, a23}, {a31, a32, a33}}

bm = {{b11, b12, b13}, {b21, b22, b23}, {b31, b32, b33}}

cm = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}

LyapunovSolve[am,bm,cm]

gives me all =0 also I tried to multiply matrices and get 9 equations and solve them with function Solve which also give me all =0.

-

A Sylvester equation like $$AX + X(-B) = 0$$ can be written as $$(I_n \otimes A - B \otimes I_n) \operatorname{vec} X = 0$$ so it has a non-trivial solution if and only if $I_n \otimes A - B \otimes I_n$ has a non-trivial null space. An equivalent condition to having a non-trivial null space is having zero as an eigenvalue.

If $\lambda$ is an eigenvalue of $A$ and $\mu$ an eigenvalue of $B$, $\lambda - \mu$ is an eigenvalue of $I_n \otimes A - B \otimes I_n$, and all eigenvalues of $I_n \otimes A - B \otimes I_n$ is on this form. Thus $I_n \otimes A - B \otimes I_n$ has zero as an eigenvalue if and only if $A$ has an eigenvalue $\lambda$ and $B$ has an eigenvalue $\mu$ such that $\lambda - \mu = 0$.

Thus, to see if $AX - XB = 0$ has a solution, you can calculate the spectrums $\sigma(A), \sigma(B)$ and then see if for any $\lambda \in \sigma(A)$ you have $-\lambda \in \sigma(B)$. You can probably write this in some clever way in Mathematica, e.g. calculate the spectrums, multiply one of them with $-1$ and check for overlaps (at the moment I do not have access to Mathematica so I can not test any code.)

The resultant of two polynomials $P$ and $Q$ is zero iff $P$ and $Q$ have a common root, so your thinking seems to be correct. However, you seem to have missed that you should calculate $\det(-B - \lambda E)$, not $\det(B - \lambda E)$.

-
In Mathematica, NullSpace[KroneckerProduct[IdentityMatrix[n], A]-KroneckerProduct[B, IdentityMatrix[n]]] –  Guess who it is. Aug 6 '12 at 11:02
NullSpace[KroneckerProduct[IdentityMatrix[n], A]-KroneckerProduct[B, IdentityMatrix[n]]] gives me {} even if I use matrices with params.resultant(det(A−λE),det(-B−λE),λ) doesn't give me 0, but maybe this is because of matrix B contains an error.How can I obtain set of B matrices if I know A matrix and condition of non-trivial solution is satisfied ? –  mrgloom Aug 6 '12 at 13:07
@mrgloom, by my argument above, the nullspace being trivial and the resultant being non-zero is equivalent to the the equation $AX-XB =0$ having no solution. If your $A$ is known, any $B$ having at least one eigenvalue equal to $-\lambda$ where $\lambda$ is an eigenvalue of $A$, will yield an equation with a non-trivial solution. Especially, if $A$ is singular, any singular $B$ will do. –  Calle Aug 6 '12 at 13:25
Furthermore, I find it highly unlikely for $AX-XB = 0$ to have a non-trivial solution if you have any errors or some kind of noise in your matrix $B$. –  Calle Aug 6 '12 at 13:28
maybe there is another method to solve this type of equation approximately\numericaly due to errors? I have 1st img which is distorted with unknown perspective transform M, then I rotate plane which I foto and I have 2nd foto with RotM transform, then I can get tranform(with small errors) beetween fotos L, so I get equation RotM=M*L but I don't understand if it has solution. –  mrgloom Aug 6 '12 at 13:57