简体   繁体   中英

trouble with sympy solve with mathematical equation (python)

I have 8 lists of variables (each identical size). For each element of the list I wish to create a new list that is the result of a mathematical solution involving the variables.

Here is my code using 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)))

However, when I try to run the code, I keep getting the error:

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

How do I fix this? I've never gotten the error "'Add' object is not callable" before.

Thanks for your help.

Looks to me like you're simply missing a * :

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)))
                      ^

and turning a multiplication of (1-x) by (Rl+Xl*1J) into a function call.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM