ich bin Python-Neuling und möchte aus teils mehrdimensionalen Differentialgleichungen ein Differentialgleichungssystem erstellen.
Was funktioniert hat, ist das:
Code: Alles auswählen
import sympy as syp
syp.init_printing()
#Matrices
AM = syp.MatrixSymbol('{A_{M}}', 2, 2)
LM = syp.MatrixSymbol('{L_M}', 2, 1)
BM = syp.MatrixSymbol('{B_M}', 2, 1)
C = syp.Matrix([[1, 0]])
#Variables
xMd = syp.MatrixSymbol('xhatdot_M', 2, 1)
xM = syp.MatrixSymbol('xhat_M', 2, 1)
uM = syp.MatrixSymbol('u_M', 1, 1)
x1d = syp.MatrixSymbol('xhatdot_1',1,1)
x2d = syp.MatrixSymbol('xhatdot_2',1,1)
x1 = syp.MatrixSymbol('xhat_1',1,1)
x2 = syp.MatrixSymbol('xhat_2',1,1)
#This is working
#Definition of the dynamics
eqMdyn = syp.Eq(((AM-LM*C) * xM + BM * uM), xMd)
#display(eqMdyn)
A, b = syp.linear_eq_to_matrix([eqMdyn], [xM, uM]) # until here, it is working
display(A)
Code: Alles auswählen
#This is not working due to nonlinearity error
eqMdyn = eqMdyn.subs(xMd, syp.BlockMatrix([[x1d],[x2d]]))
eqMdyn = eqMdyn.subs(xM, syp.BlockMatrix([[x1],[x2]]))
A, b = syp.linear_eq_to_matrix([eqMdyn], [x1, x2, uM])
display(A)
Code: Alles auswählen
#This is not working due to shape error
#Definition of the dynamics
eqMdyn = syp.Eq((AM * xM + BM * uM), xMd)
#display(eqMdyn)
A, b = syp.linear_eq_to_matrix([eqMdyn], [xM, uM]) # until here, it is working
Das hier ist jedoch nur ein Minimalbeispiel gewesen. Eigentlich möchte ich nur eqMdyn haben, sondern weitere Gleichungen, die ich dann damit zusammenfasse.