Problem Lambdifying atan function

Hi Folks,

Apology if this is not the appropriate location for this post. Also, I am not much of a computer programmer so I also apologize for any incorrect terminology in the following.

I have run across a problem that Julia’s “lambdify()” command will not convert Python’s symbolic function “atan2(x,y)” back into the Julia function “atan(x,y)”. As an example, consider the following lines of Julia code that I have written:

using SymPy

x = symbols(“x”)

f_x = atan(sin(x),cos(x))

Lambdify the symbolic expression f_x and evaluate at value x = 3/2*pi:

nf_x = lambdify(f_x,[x,x])(3/2pi,3/2pi)

What happens when I run this example (in either Julia-1.1 or Julia-1.4) is that Julia throws up a message “ERROR: LoadError: UndefVarError: atan2 not defined”. I can see that in the SymPy.jl package, there is a line in the mathfuns.jl script that finds the Julia function “atan” as missing and adds the line

Base.atan(y::Sym, x) = sympy.atan2(y,x)

in order to be able to convert the Julia function into a SymPy compatible code. I am guessing that there is something missing in the “lambdify.jl” script that prevents the conversion of the Python “atan2(x,y)” into a Julia function.

If anyone has a fix to this problem, it would be GREATLY appreciated. Thanks.

NOTE: the “3/2pi” should have a multiplication symbol in between the 2 and pi but it is not showing up properly here.

atan2 does not seem to be in the fn_maps dictionary of SymPy.jl. You can use:

jf_x = lambdify(f_x, fns = Dict("atan2"=>:atan))
nf_x = jf_x(3/2pi)

Also, see Please read: make it easier to help you on how to highlight code (as you had issues displaying it correctly).

1 Like

Thanks fgerick! I was able to get this to work in my much larger expressions with a minor tweak. I am uber-grateful for you very prompt response.

1 Like