0
$\begingroup$

new to the forum and here's the question I'm pondering on:

I'm trying to use FindInstance in Mathematica to solve a symbolic matrix equation with quite a few assumptions. For example, quite frequently I need to find commuting matrices: so given a matrix find general matrices that commute with it subject to a few constraints.

MWE: Let's say you have two matrices M and C. C is a matrix that is given to us. M is symbolic. I want to put in some assumptions and then solve for M. The assumptions relate different matrix elements of M and its not clear to me how to put in the assumptions (If its were just a single variable or two it wouldn't be that difficult.)

For example: 1. I first put in some assumptions in M for example make M symmetric and also some entries are known to be zero.

  1. After that I solve for the remaining elements:
FindInstance[M*C == C*M, 
   {Matrix variables go here}, For[ a = 1, a < 10, a = a + 1, 
  For[b = 1 , b < 10 , b = b + 1,  
   M[[a, a]] + M[[b, b]] >= 2*M[[a, b]]  ]], Integers]

I really don't think this is a nice way to include assumptions. Also I think if I had to include another assumption which would be M is made of positive integers, I guess I'd use another for loop.

So, in general, what's the suggested way to include multiple arguments for symbolic matrices?

$\endgroup$
  • $\begingroup$ Can you provide a simple example? $\endgroup$ – Carl Woll May 16 at 15:04
  • $\begingroup$ I edited the post a bit: for e.g. say solve for MC -CM = 0. The constraints being M is made of nonnegative integers say. $\endgroup$ – User4745 May 16 at 15:58
1
$\begingroup$

This is probably simpler than you need, but maybe the procedure will be useful. First, I picked an arbitrary c and a general mat.

c = {{1, 2}, {3, 3}};
mat = Array[m, {2, 2}];
Solve[c.mat == mat.c && mat == Transpose[mat], Flatten[mat], Integers]

Then solve for a symmetric matrix (via the constraint mat == Transpose[mat]) that commutes with c (via the c.mat == mat.c). You can replace Solve with FindInstance or with Reduce and get much the same thing. Hopefully you can see how to add in the constraints that you really want. For example,

Solve[c.mat == mat.c && mat == Transpose[mat] && mat[1, 2] == 10,
      Flatten[mat], Integers]

adds in the constraint that mat[1,2] has a particular value. If you want to constrain the elements of mat to all be non-negative you can add the condition:

Solve[c.mat == mat.c && mat == Transpose[mat] && 
       Min[mat] >= 0, Integers]
$\endgroup$
  • $\begingroup$ Pretty neat! Any idea of how to implement the "triangle inequality"? M[[a, a]] + M[[b, b]] >= 2*M[[a, b]] $\endgroup$ – User4745 May 16 at 20:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.