I don't know Mathematica very well, I have an equation involving matrices of the following form: given two 5ドル\times5$ matrices $A,B$ where $B$ is nilpotent we want to find a matrix $X$ such that
k X + B.X-X.B + A = 0
for an integer $k$.
Is there a command solving such an equation?
I tried with Solve and LinearSolve, but it does not work.
3 Answers 3
You can use LyapunovSolve which solves a.x + x.b = c:
SeedRandom[1] ;
A = RandomReal[{-1, 1}, {5, 5}];
B = RandomReal[{-1, 1}, {5, 5}];
k = RandomReal[{-1, 1}];
a = k * IdentityMatrix[5] + B ;
b = - B ;
c = - A ;
LyapunovSolve[a,b,c]
-
3$\begingroup$ Awesome. This should be the accepted answer. $\endgroup$Henrik Schumacher– Henrik Schumacher2025年08月06日 16:01:46 +00:00Commented Aug 6 at 16:01
This is a linear equation in X, so you can solve it, in principle by writing out the system matrix and the right-hand side like this:
A = RandomReal[{-1, 1}, {5, 5}];
B = RandomReal[{-1, 1}, {5, 5}];
k = RandomReal[{-1, 1}, {5, 5}];
X = Array[x, {5, 5}];
matrix = D[Flatten[k X + B . X - X . B], {Flatten[X], 1}];
rhs = Flatten[-A];
solution = ArrayReshape[LinearSolve[matrix, rhs], {5, 5}]
Of course, there might be way more clever solutions to this. E.g., we have not exploited, yet, that B is nilpotent. Probably you are supposed to multiply with B a couple of times from the left and from the right so that several terms cancel and the remainder can be used to eliminate some variables in the matrix X. Maybe the Jordan decomposition might be helpful.
-
1$\begingroup$ nice thanks, I guess that the key is to use the flatten/arrayreshape. $\endgroup$Vanja– Vanja2025年08月06日 12:20:36 +00:00Commented Aug 6 at 12:20
-
$\begingroup$ Yeah,
Flattenreinterprets the 5ドル \times 5$-matrices as 25ドル$-vectors,D"linearizes" the system, andArrayReshapeundoes whatFlattendid. $\endgroup$Henrik Schumacher– Henrik Schumacher2025年08月06日 15:58:43 +00:00Commented Aug 6 at 15:58
Without using any matrix theory just straightly writing an equation.
A = RandomInteger[{-10, 10}, {5, 5}];
B = RandomInteger[{-10, 10}, {5, 5}];
k = RandomInteger[{-10, 10}];
(* solution *)
# /. Solve[k # + B . # - # . B + A == 0] &@Array[x, Dimensions[A]]
(* verification *)
k # + B . # - # . B + A & /@ %
{{{0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0},
{0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}}}
Explore related questions
See similar questions with these tags.
[B,X]? What does not work? $\endgroup$[B,X]is supposed to be the commutator bracket. In Mathematica code that would beB.X - X.B. $\endgroup$