Search code examples
pythonmathnumpysympycallable-object

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.


Solution

  • 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.