簡體   English   中英

用數學方程式(python)解決sympy問題

[英]trouble with sympy solve with mathematical equation (python)

我有8個變量列表(每個大小相同)。 我希望為列表中的每個元素創建一個新列表,該列表是包含變量的數學解決方案的結果。

這是我使用Sympy的代碼:

from sympy.solvers import solve
from sympy import Symbol
x = Symbol('x')
m = []
for a,b,c,d,e,f,g,h in zip(uAFOURIERL,IAFOURIERL,IBFOURIERL,ICFOURIERL,uAFOURIERR,IAFOURIERR,IBFOURIERR,ICFOURIERR):
    m.append(solve(a-(x*(Rl+Xl*1J)*b+x*(Rr+Xr*1J)*c+x*(Rr+Xr*1J)*d)-(e-((1-x)(Rl+Xl*1J)*f+(1-x)*(Rr+Xr*1J)*g+(1-x)*(Rr+Xr*1J)*h))*math.e**(alpha*1J)))

但是,當我嘗試運行代碼時,我不斷收到錯誤消息:

TypeError                                 Traceback (most recent call last)
<ipython-input-7-b428f6d803d8> in <module>()
    725 m = []
    726 for a,b,c,d,e,f,g,h in zip(uAFOURIERL,IAFOURIERL,IBFOURIERL,ICFOURIERL,uAFOURIERR,IAFOURIERR,IBFOURIERR,ICFOURIERR):
--> 727     m.append(solve(a-(x*(Rl+Xl*1J)*b+x*(Rr+Xr*1J)*c+x*(Rr+Xr*1J)*d)-(e-((1-x)(Rl+Xl*1J)*f+(1-x)*(Rr+Xr*1J)*g+(1-x)*(Rr+Xr*1J)*h))*math.e**(alpha*1J)))
    728 
    729 

TypeError: 'Add' object is not callable

我該如何解決? 我從來沒有收到錯誤“添加對象不可調用”的錯誤。

謝謝你的幫助。

在我看來,您只是缺少一個*

for a,b,c,d,e,f,g,h in zip(uAFOURIERL,IAFOURIERL,IBFOURIERL,ICFOURIERL,uAFOURIERR,IAFOURIERR,IBFOURIERR,ICFOURIERR):
    m.append(solve(a-(x*(Rl+Xl*1J)*b+x*(Rr+Xr*1J)*c+x*(Rr+Xr*1J)*d)-
             (e-((1-x)*(Rl+Xl*1J)*f+(1-x)*(Rr+Xr*1J)*g+(1-x)*(Rr+Xr*1J)*h))*math.e**(alpha*1J)))
                      ^

並將(1-x)(Rl+Xl*1J)的乘積轉換為函數調用。

暫無
暫無

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

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