# Equation in Matrix

I have problem in center of Terwilliger Algebra. But, I will explain simple problem for simplicity my problem.

For example, I have matrix

A=Matrix([[a1,a2],[a3,a4]]);


and also I have

B1=Matrix([[1,0],[0,0]]);B2=Matrix([[0,1],[0,0]]);B3=Matrix([[0,0],[1,0]]);B1=Matrix([[0,0],[0,1]]);


These matrix have condition

AB=BA


for any B=B1,B2,B3,B4 If I solve it by hand, it is easy to get a1,a2,a3,a4. But how to do it by sage? Can sage solve it? Thanks

edit retag close merge delete

Sort by » oldest newest most voted

Here is one approach for this small scale problem.

var('a1,a2,a3,a4')

A=Matrix([[a1,a2],[a3,a4]]);
B1=Matrix([[1,0],[0,0]]);B2=Matrix([[0,1],[0,0]]);B3=Matrix([[0,0],[1,0]]);B1=Matrix([[0,0],[0,1]]);

M=A*B1
N=B1*A

eqtns=[M[i,j]==N[i,j] for i in [0,1] for j in [0,1]]
print eqtns
solve(eqtns,[a1,a2,a3,a4])

more

Thanks for your help. It is so helpful. Why do it use [0,1] on for i in [0,1] for j in [0,1]]. Can we save the solution? For example, if we type a2, it will show 0. Thanks

( 2015-08-25 08:01:32 -0500 )edit

The indices $i,j$ are the indices for your matrix. Sage begins these at 0. So, since these are 2 by 2 matrices, the indices of the entries are 0 and 1.

( 2015-08-25 09:29:19 -0500 )edit

For my example, the solution is [[a1 == r2, a2 == 0, a3 == 0, a4 == r1]]. So a2 and a3 must be 0 while a1 and a4 can be any real numbers. This is going to be tricky to substitute for a1,a2,a3,a4 since two of them are arbitrary.

( 2015-08-25 09:32:21 -0500 )edit