Search code examples
pythonsymbolssympysolver

sympy error 'Symbol' object is not callable


I am trying to solve an equation for r when given values for x and y. to do this I am using the solve ability of sympy. the code that I have is

import numpy as np
import matplotlib.pyplot as plt
from sympy import solve
from sympy import Symbol
from sympy import acos,sin

x=2
y=-2
r=Symbol("r",real=True)
solve(r(acos(1.0-(y/r)))-sin(acos(1.0-(y/r)))-x)

when I run the code it gives me the error

'Symbol' object is not callable
line 10, in <module>
    solve(r(acos(1.0-(y/r)))-sin(acos(1.0-(y/r)))-x)

the reason I import numpy and matplotlib is that I will use them later in my code. Thanks for any help.


Solution

  • The error directs you toward what to look for: a Symbol that is being called. In Python syntax this is a Symbol followed by pair of parentheses with one or more arguments between them. You probably intended to multiply by r in the first argument of the expression:

    >>> solve(r(acos(1.0-(y/r)))...
               ^__make that r*acos(1.0-(y/r))...
    

    An editor that highlights matching parentheses (like the online editor of Python code at repl.it) can be helpful in these circumstances. Parentheses are either grouping or, when following a Python name, acting as the delimiters for the arguments being passed to a function.