Reputation: 377
Consider three (complex) square matrices A
, X
, and B
, that form a generally underdetermined linear system
A @ X - X @ A == B
The system is to be solved for X
. I would like to use, e.g., the lstsq
functions of numpy
or scipy
to find a particular solution for X
.
Note that in my case, A
and B
are Hermitian, and thus the solution X
is necessarily anti-Hermitian.
It is of course always possible to use a custom least squares minimization, but is there a way to use existing linear algebra solvers to solve this directly?
Upvotes: 1
Views: 77
Reputation: 377
Thanks to @Reinderien in the comments for the solution idea. Scipy has a solve_sylvester
function specifically for this problem, namely,
import scipy
X = scipy.linalg.solve_sylvester(A, -A, B)
This could use optimizations for my case, but it will work well enough. Unfortunately, the function does not seem to support batching.
EDIT AND WARNING: As ThomasIsCoding points out in the comments, there might be issues with using the Bartels-Stewart algorithm (on which solve_sylvester
is based) in my particular case. I checked that it worked in a very simple case. But then, in a very complicated case, it gave me nonsense. So tread carefully. I don't have time to investigate further at the moment.
Upvotes: 2