Ask Your Question
0

Solving for a matrix.

asked 2023-11-16 19:08:41 +0100

wizard7703 gravatar image

updated 2023-11-18 00:21:45 +0100

I have an m x n matrix A and an m x n matrix of variables X. I want to solve for all possible X such that AX^T = XA^T and A^TX = X^TA. Is there any nice way to do this?

I've tried using various commands like "Solve" but "solve_right" but it doesn't seem to be working. Here is my code so far.

A = matrix([[0,1],[1,0],[1,1]])

xrownum = A.nrows()
xcolnum = A.ncols()

X = matrix([[var("x_{}_{}".format(u,v), latex_name="a_{{{},{}}}".format(u,v)) for v in range(xcolnum)] for u in range(xrownum)]);
for i in range(xrownum):
    for j in range(xcolnum):
        if A[i,j] != 0:
            X[i,j] = 0
XAT = X*A.transpose()
AXT = A*X.transpose()
ATX = A.transpose()*X
XTA = X.transpose()*A

Of course, X = 0 will always work, but I am interested in knowing if it is the ONLY matrix which works.

edit retag flag offensive close merge delete

Comments

$A^TX = X^TA$ gives $n^2$ linear equations. Just solve the system of these equations with linear algebra. Checking whether $X=0$ is the only solution corresponds to checking whether the system has a trivial kernel.

Max Alekseyev gravatar imageMax Alekseyev ( 2023-11-16 20:33:25 +0100 )edit

Right, I am just unsure how to implement this in Sage. I am very new to the language and I would like to write a program which can do this computation for an arbitrary A.

wizard7703 gravatar imagewizard7703 ( 2023-11-16 20:35:17 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-11-16 20:57:52 +0100

Max Alekseyev gravatar image

updated 2023-11-18 01:00:13 +0100

Here is how we get the basis of the solutions to $\{ A^TX = X^TA, AX^T=XA^T \}$:

D1 = A.T*X - X.T*A
D2 = A*X.T - X*A.T
V = [x for x in X.list() if x]   # variables
M = Matrix([[d.coefficient(x) for x in V] for d in D1.list()+D2.list()])
B = [X.subs(zip(V,b)) for b in M.right_kernel().basis()]
assert all( A.T*x == x.T*A and A*x.T == x*A.T for x in B )
print(B)
edit flag offensive delete link more

Comments

Is there a way to solve this system of equations and the system of equation AX^T-XA^T = 0 in the same variables at the same time? Thanks for the help it seems like your code is solving the first part correctly

wizard7703 gravatar imagewizard7703 ( 2023-11-17 01:30:46 +0100 )edit

I'm not sure what you are asking for. Do you want a parametric solution or something else?

Max Alekseyev gravatar imageMax Alekseyev ( 2023-11-17 02:14:59 +0100 )edit

I want to find an X such that both AX^T = XA^T and A^TX = X^TA. These are not quite the same equations, but I want to account for all n^2 + m^2 many linear equations from this.

wizard7703 gravatar imagewizard7703 ( 2023-11-17 02:26:29 +0100 )edit

It's done same way - see updated answer.

Max Alekseyev gravatar imageMax Alekseyev ( 2023-11-17 03:03:29 +0100 )edit

Ah great. Thank you so much!

wizard7703 gravatar imagewizard7703 ( 2023-11-17 03:04:07 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2023-11-16 19:07:11 +0100

Seen: 299 times

Last updated: Nov 18 '23