5
$\begingroup$

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.

New contributor
Vanja is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
$\endgroup$
3
  • 2
    $\begingroup$ What operation is [B,X]? What does not work? $\endgroup$ Commented 21 hours ago
  • 1
    $\begingroup$ I guess [B,X] is supposed to be the commutator bracket. In Mathematica code that would be B.X - X.B. $\endgroup$ Commented 21 hours ago
  • $\begingroup$ yes exactly, it is the commutator. I have edited the question to clarify the notation $\endgroup$
    – Vanja
    Commented 19 hours ago

3 Answers 3

6
$\begingroup$

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]
$\endgroup$
1
  • 3
    $\begingroup$ Awesome. This should be the accepted answer. $\endgroup$ Commented 16 hours ago
6
$\begingroup$

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.

$\endgroup$
3
  • 1
    $\begingroup$ nice thanks, I guess that the key is to use the flatten/arrayreshape. $\endgroup$
    – Vanja
    Commented 19 hours ago
  • $\begingroup$ Yeah, Flatten reinterprets the $5 \times 5$-matrices as $25$-vectors, D "linearizes" the system, and ArrayReshape undoes what Flatten did. $\endgroup$ Commented 16 hours ago
  • $\begingroup$ @Vanja No, no, no, you should rather accept I.M.'s answer! It is much better in all respects. $\endgroup$ Commented 15 hours ago
3
$\begingroup$

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}}}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.