簡體   English   中英

獲取 Sympy 方程中項的系數

[英]Getting coefficients of terms in Sympy equation

我有以下代碼。 我正在尋找planeL變量的 a,b,c,d 項。 當我打印方程時,我可以看到它是: Eq(14*x + 12*y + 8*z - 102, 0)

我希望得到 14、12、8 和 -102

任何幫助表示贊賞。 謝謝你。

t = sympy.Symbol('t')
s = sympy.Symbol('s')
x = sympy.Symbol('x')
y = sympy.Symbol('y')
z = sympy.Symbol('z')

L = sympy.Matrix([2*t+5, -t+4, -2*t-2])
K = sympy.Matrix([-2*s+3, 5*s-5,-4*s+4])
dirL = sympy.Matrix([2,-1,-2])
dirK = sympy.Matrix([-2,5,-4])
normV = dirL.cross(dirK)
print("The normal vector to the two planes: ", normV)

L0 = L.subs(t,0)
K0 = K.subs(s,0)
print("L0: ", L0, "K0: ", K0)

#Calculating the equation of the planes

planeL = sympy.Eq(normV[0]*(x-L0[0])+normV[1]*(y-L0[1])+normV[2]*(z-L0[2]),0)
planeK = sympy.Eq(normV[0]*(x-K0[0])+normV[1]*(y-K0[1])+normV[2]*(z-K0[2]),0)
print("planeL: ", planeL, "planeK: ", planeK)

將以下內容添加到代碼的末尾

print(sympy.Poly(planeL, x,y,z).coeffs())

output:

[14, 12, 8, -102]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM