ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 25 Apr 2018 18:23:53 -0500Sage wont solve simultaneous equationhttp://ask.sagemath.org/question/42174/sage-wont-solve-simultaneous-equation/I tried asking this question earlier, but my profile still says I have asked 0 questions. I have tried solving this problem in different ways, but this is the closest I have gotten;
var('a b c d e f g h i')
X=matrix(3,3,[[0,1,0],[0,0,1],[1,0,0]])
P=matrix(3,3,[[a,b,c],[d,e,f],[g,h,i]])
Pdagger=P.transpose()
Xdagger=X.transpose()
Q=X*Pdagger
B=Q.solve_left(X)
eqns=[]
xlist=[]
for i in range(0,3):
for j in range(0,3):
eqns.append(B[i][j])
xlist.append(X[i][j])
final=[]
for k in range(0,9):
final.append(eqns[k]==xlist[k])
show(final)
sol=solve(eqns,[a,b,c,d,e,f,g,h,i])
show(sol)
I know there is a solution to this problem, and it is the identity, $PXP^{\dagger}=X$.
But the output:
Error in lines 19-19
Traceback (most recent call last):
File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1013, in execute
exec compile(block+'\n', '', 'single') in namespace, locals
File "", line 1, in <module>
File "/ext/sage/sage-8.1/local/lib/python2.7/site-packages/sage/symbolic/relation.py", line 976, in solve
raise TypeError("%s is not a valid variable." % repr(i))
TypeError: 2 is not a valid variable.
There is also probably a much more efficient way of specifying the problem, but I don't understand why this wont work. I would like to extend this problem to larger matrices as well, so autonomy is welcomed. However, I would appreciate any advice just on getting this error fixed.PatrickLewisWed, 25 Apr 2018 18:23:53 -0500http://ask.sagemath.org/question/42174/Cannot solve system of simultaneous equationshttp://ask.sagemath.org/question/42173/cannot-solve-system-of-simultaneous-equations/I am trying to solve a particular problem, but my test solution for setting up the code isn't working. I have tried two ways - one, which just outputs the same equations, and the other, I'm unsure on how to solve this large list of equations which are unrealistic to type out.
First attempt
var('a b c d e f g h i')
X=matrix(3,3,[[0,1,0],[0,0,1],[1,0,0]])
P=matrix(3,3,[[a,b,c],[d,e,f],[g,h,i]])
Pdagger=P.transpose()
Xdagger=X.transpose()
L=P*X*Pdagger
This outputs $$\begin{pmatrix} ab+ac+bc & cd+ae+bf & cg+ah+bi \\\\ bd+ce+af & de+df+ef & fg+dh+ei \\\\ bg+ch+ai & eg+fh+di & gh+gi+hi \end{pmatrix}$$ I then make $L=X$, then type these equations element wise into the simultaneous equation solver;
equations=solve([a*b+a*c+b*c==0,c*d+a*e+b*f==1,c*g+a*h+b*i==0,b*d+c*e+a*f==0,d*e+d*f+e*f==0,f*g+d*h+e*i==1,b*g+c*h+a*i==1,e*g+f*h+d*i==0,g*h+g*i+h*i==0],a,b,c,d,e,f,g,h,i)
The output:
a*e + b*f == 1, d*e + d*f + e*f == 0, b*g + c*h + a*i == 1, c*g + a*h + b*i == 0, e*g + f*h + d*i == 0, f*g + d*h + e*i == 1, g*h + g*i + h*i == 0]
Second attempt;
Q=X*Pdagger
B=Q.solve_left(X)
eqn=[]
for i in range(0,3):
for j in range(0,3):
eqn.append(B[i][j])
This gives me a list of the equations, I then try the solver again;
solve([eqn[0]==0,...eqn[8]==0],a,b,c,d,e,f,g,h,i)
This just gives me an error:
(a, b, c, d, e, f, g, h, i)
Error in lines 13-13
Traceback (most recent call last):
File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1013, in execute
exec compile(block+'\n', '', 'single') in namespace, locals
File "", line 1, in <module>
File "/ext/sage/sage-8.1/local/lib/python2.7/site-packages/sage/symbolic/relation.py", line 976, in solve
raise TypeError("%s is not a valid variable." % repr(i))
TypeError: 2 is not a valid variable.
The hope is that I will be able to extend this to larger matrices, so autonomy is welcomed greatly. But I will happily take any advice given I'm at a completely lose end. It is worth noting that the solution to this problem; $$PXP^{\dagger}=X$ is the identity matrix. My understanding is that the first method cannot find a closed form? I have even tried specifying that a,b,c,d,e,f,g,h,i are all 0 or 1 and this has not helped. I believe my second method is more on the right track, however I cannot afford to manually type out the 9 non-linear equations that pop out from the matrix solver.PatrickLewisWed, 25 Apr 2018 18:01:09 -0500http://ask.sagemath.org/question/42173/How to solve a large list of simultaneous equationshttp://ask.sagemath.org/question/42172/how-to-solve-a-large-list-of-simultaneous-equations/I am trying to solve a particular problem, but my test solution for setting up the code isn't working. I have tried two ways - one, which just outputs the same equations, and the other, I'm unsure on how to solve this large list of equations which are unrealistic to type out.
First attempt
var('a b c d e f g h i')
X=matrix(3,3,[[0,1,0],[0,0,1],[1,0,0]])
P=matrix(3,3,[[a,b,c],[d,e,f],[g,h,i]])
Pdagger=P.transpose()
Xdagger=X.transpose()
L=P*X*Pdagger
This outputs $$\begin{pmatrix} ab+ac+bc & cd+ae+bf & cg+ah+bi \\\\ bd+ce+af & de+df+ef & fg+dh+ei \\\\ bg+ch+ai & eg+fh+di & gh+gi+hi \end{pmatrix}$$ I then make $L=X$, then type these equations element wise into the simultaneous equation solver;
equations=solve([a*b+a*c+b*c==0,c*d+a*e+b*f==1,c*g+a*h+b*i==0,b*d+c*e+a*f==0,d*e+d*f+e*f==0,f*g+d*h+e*i==1,b*g+c*h+a*i==1,e*g+f*h+d*i==0,g*h+g*i+h*i==0],a,b,c,d,e,f,g,h,i)
The output:
a*e + b*f == 1, d*e + d*f + e*f == 0, b*g + c*h + a*i == 1, c*g + a*h + b*i == 0, e*g + f*h + d*i == 0, f*g + d*h + e*i == 1, g*h + g*i + h*i == 0]
Second attempt;
Q=X*Pdagger
B=Q.solve_left(X)
eqn=[]
for i in range(0,3):
for j in range(0,3):
eqn.append(B[i][j])
This gives me a list of the equations, I then try the solver again;
solve([eqn[0]==0,...eqn[8]==0],a,b,c,d,e,f,g,h,i)
This just gives me an error:
(a, b, c, d, e, f, g, h, i)
Error in lines 13-13
Traceback (most recent call last):
File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1013, in execute
exec compile(block+'\n', '', 'single') in namespace, locals
File "", line 1, in <module>
File "/ext/sage/sage-8.1/local/lib/python2.7/site-packages/sage/symbolic/relation.py", line 976, in solve
raise TypeError("%s is not a valid variable." % repr(i))
TypeError: 2 is not a valid variable.
The hope is that I will be able to extend this to larger matrices, so autonomy is welcomed greatly. But I will happily take any advice given I'm at a completely lose end. It is worth noting that the solution to this problem; $$PXP^{\dagger}=X$ is the identity matrix. My understanding is that the first method cannot find a closed form? I have even tried specifying that a,b,c,d,e,f,g,h,i are all 0 or 1 and this has not helped. I believe my second method is more on the right track, however I cannot afford to manually type out the 9 non-linear equations that pop out from the matrix solver.PatrickLewisWed, 25 Apr 2018 17:53:15 -0500http://ask.sagemath.org/question/42172/how to create a matrix valued function?http://ask.sagemath.org/question/39606/how-to-create-a-matrix-valued-function/I'm trying to define a function g that takes two values and maps tem to a 2x2 matrix. What I've tried is
x,y = var('x,y');
g(x,y) = matrix(SR,2,2,[1,x,cos(y),x*y]);
but if I try to evaluate this function, the variables in the matrix are not evaluated:
sage: g(0,0)
[ 1 x]
[cos(y) x*y]
I expect the output to be
[ 1 0]
[ 1 0]
I also tried other variants bud did not succeed, e.g.
g(x,y) = matrix([[1,x],[x,y]])flawrThu, 16 Nov 2017 08:47:47 -0600http://ask.sagemath.org/question/39606/Equation in Matrixhttp://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
nur_hamidMon, 24 Aug 2015 19:24:56 -0500http://ask.sagemath.org/question/29351/