1 | initial version |
It is hard to understand what happens behind, but the following works:
vars = var('a b c d e f g h u')
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, u]])
Pdagger = P.transpose()
Xdagger = X.transpose() # not needed
Q = X * Pdagger
B = Q.solve_left(X)
R = range(0,3)
eqns = [ B[i][j] for i in R for j in R ]
xlist = [ X[i][j] for i in R for j in R ]
final = [ B[i][j] == X[i][j] for i in R for j in R ]
sols = solve(final, vars)
# show(sol)
for sol in sols:
print sol
and i have some comments:
i
is a variable... ok, no problem we overwrite that $\sqrt {-1}$, then please do not redefine it in a loop as a number. (This would have been a second alarm while reusing i
...) Nobody does this, so this atypical error cannot be seen at a first glance. In our case this brings the error as follows. After the last i
-loop this "global variable" has the value $2$, and we try to solve a system of equations, where one of the equation variables is the constant $2$. The error message is also misleading. eqns
, when it does not collect equations, but rather entries of a matrix. The solve
of these "equations" will be hardly detected with bare eyes as an error.eqns
and xlist
are not needed. The wording for xlist
is also not proper. Something like X_entries
would reflect the provenience, but we do not need this new variable, the matrix X
already has the information.Please understand that these "critics" are just kind advices, at any rate not offensive, in my case, knowing these as i started programming in python would have been a real benefit.