Extracting special parts of a matrix function

45 views
Skip to first unread message

nils Frank

unread,
Mar 12, 2025, 4:50:48 AM3/12/25
to sympy
Hello everyone,
Hello everyone,
I have a function in the first row of a result matrix, and also in the second.

I'm separating the first row to write only the parts of it into a new matrix, for example, a multiplication by the second derivative of phi1. 
pic_result matrix.jpg

Unfortunately, there's no result, just square brackets. Can anyone help? Thanks in advance.

Sympy Code:
#Testmatrix 
C = d*sp.diff(phi1(t), t)+l*m*(2*g*sp.sin(phi1(t))+l*sp.sin(phi1(t)-phi2(t))*(sp.diff(phi2(t), t))**2+ l*sp.cos(phi1(t)-phi2(t))*sp.diff(phi2(t), t,t)+ 2*l*sp.diff(phi1(t), t,t))
D = sp.diff(phi2(t), t) + sp.diff(phi1(t), t)

Bw_Lag_Q_Test = sp.Matrix([[C], [D]])
Bw_Lag_Q_Test

erste_reihe_BW_Test = Bw_Lag_Q_Test.row(0)
erste_reihe_BW_Test

# Extract parts of  erste_reihe_BW_Test
erste_reihe_BW_Test = Bw_Lag_Q_Test.row(0)
Extract_0 = [term.coeff(sp.diff(phi1(t), t,t)) for term in erste_reihe_BW if term.has(sp.diff(phi1(t), t,t))]
Extract_0
pic_empty square bracket.jpg

thomas...@gmail.com

unread,
Mar 13, 2025, 5:10:59 PM3/13/25
to sy...@googlegroups.com

Could it be that this is not a matrix, but just an expression that requires multiple lines to display?

 

Tom

(Dr. Thomas S. Ligon)

thomas...@gmail.com

Frohnloher Str. 6a
81475 Muenchen
Germany
Tel. +49(89)74575075

 

From: 'nils Frank' via sympy <sy...@googlegroups.com>
Sent: Wednesday, March 12, 2025 9:51 AM
To: sympy <sy...@googlegroups.com>
Subject: [sympy] Extracting special parts of a matrix function

 

Hello everyone,
Hello everyone,
I have a function in the first row of a result matrix, and also in the second.

I'm separating the first row to write only the parts of it into a new matrix, for example, a multiplication by the second derivative of phi1. 



Unfortunately, there's no result, just square brackets. Can anyone help? Thanks in advance.

Sympy Code:
#Testmatrix 
C = d*sp.diff(phi1(t), t)+l*m*(2*g*sp.sin(phi1(t))+l*sp.sin(phi1(t)-phi2(t))*(sp.diff(phi2(t), t))**2+ l*sp.cos(phi1(t)-phi2(t))*sp.diff(phi2(t), t,t)+ 2*l*sp.diff(phi1(t), t,t))
D = sp.diff(phi2(t), t) + sp.diff(phi1(t), t)

Bw_Lag_Q_Test = sp.Matrix([[C], [D]])
Bw_Lag_Q_Test

erste_reihe_BW_Test = Bw_Lag_Q_Test.row(0)
erste_reihe_BW_Test

# Extract parts of  erste_reihe_BW_Test
erste_reihe_BW_Test = Bw_Lag_Q_Test.row(0)
Extract_0 = [term.coeff(sp.diff(phi1(t), t,t)) for term in erste_reihe_BW if term.has(sp.diff(phi1(t), t,t))]
Extract_0

--
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 sympy+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/sympy/53ab1baa-d5ad-4c03-b02d-6a55b8358ba0n%40googlegroups.com.

image001.jpg
image002.jpg
Reply all
Reply to author
Forward
0 new messages