ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 25 Aug 2015 09:32:21 -0500Equation in Matrixhttps://ask.sagemath.org/question/29351/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
Mon, 24 Aug 2015 19:24:56 -0500https://ask.sagemath.org/question/29351/equation-in-matrix/Answer by calc314 for <p>I have problem in center of Terwilliger Algebra. But, I will explain simple problem for simplicity my problem.</p>
<p>For example, I have matrix </p>
<pre><code>A=Matrix([[a1,a2],[a3,a4]]);
</code></pre>
<p>and also I have</p>
<pre><code>B1=Matrix([[1,0],[0,0]]);B2=Matrix([[0,1],[0,0]]);B3=Matrix([[0,0],[1,0]]);B1=Matrix([[0,0],[0,1]]);
</code></pre>
<p>These matrix have condition</p>
<pre><code>AB=BA
</code></pre>
<p>for any <code>B=B1,B2,B3,B4</code>
If I solve it by hand, it is easy to get <code>a1,a2,a3,a4</code>. But how to do it by sage? Can sage solve it? Thanks</p>
https://ask.sagemath.org/question/29351/equation-in-matrix/?answer=29352#post-id-29352Here 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])Mon, 24 Aug 2015 20:23:03 -0500https://ask.sagemath.org/question/29351/equation-in-matrix/?answer=29352#post-id-29352Comment by calc314 for <p>Here is one approach for this small scale problem.</p>
<pre><code>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])
</code></pre>
https://ask.sagemath.org/question/29351/equation-in-matrix/?comment=29360#post-id-29360For 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.Tue, 25 Aug 2015 09:32:21 -0500https://ask.sagemath.org/question/29351/equation-in-matrix/?comment=29360#post-id-29360Comment by calc314 for <p>Here is one approach for this small scale problem.</p>
<pre><code>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])
</code></pre>
https://ask.sagemath.org/question/29351/equation-in-matrix/?comment=29359#post-id-29359The 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.Tue, 25 Aug 2015 09:29:19 -0500https://ask.sagemath.org/question/29351/equation-in-matrix/?comment=29359#post-id-29359Comment by nur_hamid for <p>Here is one approach for this small scale problem.</p>
<pre><code>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])
</code></pre>
https://ask.sagemath.org/question/29351/equation-in-matrix/?comment=29356#post-id-29356Thanks 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. ThanksTue, 25 Aug 2015 08:01:32 -0500https://ask.sagemath.org/question/29351/equation-in-matrix/?comment=29356#post-id-29356