用数学方程式解决问题(python)

时间:2015-04-27 01:51:28

标签: python math numpy sympy callable-object

我有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

我该如何解决这个问题?我从来没有收到错误&#34;&#39;添加&#39;对象不可调用&#34;之前。

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

在我看来,你只是错过了*

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)进行函数调用。

相关问题