Maybe this way: define a supporting *Gsym* for the symbolic version of the
matrix *G*:
In [1]: U = MatrixSymbol("U", 2, 2)
In [2]: D = MatrixSymbol("D", 2, 2)
In [3]: G = Matrix([[0, 1], [-1, 0]])
In [4]: Gsym = MatrixSymbol("Gsym", 2, 2)
Now create your matrix multiplication expression:
In [5]: expr = Sum(U[i, l]*Gsym[l, m]*D[j, m], (l, 0, 1), (m, 0, 1))
In [6]: expr
Out[6]:
1 1
___ ___
╲ ╲
╲ ╲ U[i, l]⋅Gsym[l, m]⋅D[j, m]
╱ ╱
╱ ╱
‾‾‾ ‾‾‾
m = 0 l = 0
In [7]: expr.doit()
Out[7]: U[i, 0]⋅Gsym₀₀⋅D[j, 0] + U[i, 0]⋅Gsym₀₁⋅D[j, 1] + U[i, 1]⋅Gsym₁₀⋅D[j
, 0] + U[i, 1]⋅Gsym₁₁⋅D[j, 1]
Now create a replacement dictionary (replacing symbols in *Gsym* with their
numeric values):
In [8]: repl_dict = {Gsym[i]: G[i] for i in range(len(G))}
In [9]: repl_dict
Out[9]: {Gsym₀₀: 0, Gsym₀₁: 1, Gsym₁₀: -1, Gsym₁₁: 0}
Perform the replacement:
In [10]: expr.doit().subs(repl_dict)
Out[10]: U[i, 0]⋅D[j, 1] - U[i, 1]⋅D[j, 0]
Unfortunately the matrix module still needs some fixes, but I hope that you
can use this trick to overcome the current limitations.
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/63431ddd-8d20-4413-b34c-848df87c795b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.