Ich versuche, einige symbolische Berechnungen in Python mit Sympy zu tun. Ich definiere daher einige Skalar- und Matrixsymbole. Allerdings sieht die Druckausgabe in der Konsole eher hässlich aus, ich möchte sie kompakter haben. Genauer gesagt, habe ich ein Skalarsymbol dt
, das in eine Matrix Fd
eingesteckt ist. Wenn ich die Transponierung von Fd
drucke, werden die Einträge, die dt
enthalten, als transpose(dt)
gedruckt. Hier ist mein Code:Unterdrücken Sie die Transponierung eines Symbols in Sympy-Ausgabe, wenn das Symbol ein Skalar ist
#!/usr/bin/python
from sympy import *
dt = Symbol('dt')
A = MatrixSymbol('A',3,3)
B = MatrixSymbol('B',3,3)
C = MatrixSymbol('C',3,3)
D = MatrixSymbol('D',3,3)
E = MatrixSymbol('E',3,3)
F = MatrixSymbol('F',3,3)
Ct = MatrixSymbol('Ct',3,3)
I = Identity(3)
O = ZeroMatrix(3,3)
Fd = BlockMatrix([[I, dt*I, A, B, -Ct*(dt*dt)/2], [O, I, C, D, -Ct*dt], [O, O, E, F, O], [O, O, O, I, O], [O, O, O, O, I]])
print "======================="
print "Fd = "
print Fd
print "======================="
Fdt = Fd.T
print "======================="
print "Fdt = "
print Fdt
print "======================="
Und dies ist die Ausgabe:
=======================
Fd =
Matrix([
[I, dt*I, A, B, (-dt**2/2)*Ct],
[0, I, C, D, (-dt)*Ct],
[0, 0, E, F, 0],
[0, 0, 0, I, 0],
[0, 0, 0, 0, I]])
=======================
=======================
Fdt =
Matrix([
[ I, 0, 0, 0, 0],
[ (dt*I)', I, 0, 0, 0],
[ A', C', E', 0, 0],
[ B', D', F', I, 0],
[(-transpose(dt)**2/2)*Ct', (-transpose(dt))*Ct', 0, 0, I]])
=======================
Ich möchte eine kompaktere Ausgabe haben (da ich einige weitere Matrix-Multiplikationen tun wird), wo dt
tatsächlich erkannt wird als ein Skalarsymbol (und daher wird keine Transponierung gedruckt). Hat jemand eine Ahnung wie man das macht?
Tatsächlich Einstellung 'Komplex = true' macht es Arbeit. Dies scheint ein unerwünschtes Verhalten zu sein. Ich habe ein Problem (https://github.com/sympy/sympy/issues/10959) dafür geöffnet. – asmeurer