# Using SymPy.jl with two variables

**URL:** <https://discourse.julialang.org/t/using-sympy-jl-with-two-variables/94148>\
**Category:** General Usage\
**Created:** [February 6, 2023, 4:22pm UTC](https://discourse.julialang.org/t/using-sympy-jl-with-two-variables/94148 "2023-02-06T16:22:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Firstname\_Lastname](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/firstname_lastname/32/34201_2.png) [@Firstname\_Lastname](https://discourse.julialang.org/u/Firstname_Lastname)\
**Post date:** [February 6, 2023, 4:22pm UTC](https://discourse.julialang.org/t/using-sympy-jl-with-two-variables/94148/1 "2023-02-06T16:22:50Z")

</div>

I ran the following code

```julia
using SymPy
@syms x y
f(x,y) = cos(x - y)
df(x,y) = sympy.diff(f(x,y),x)
df(0,pi/2) # it is supposed to be 1, but an error occurs

```

Please help me to resolve this problem.

Thank you.

---

<div class="post-metadata">

**Author:** ![Sevi](https://avatars.discourse-cdn.com/v4/letter/s/c67d28/32.png) [@Sevi](https://discourse.julialang.org/u/Sevi)\
**Post date:** [February 6, 2023, 4:45pm UTC](https://discourse.julialang.org/t/using-sympy-jl-with-two-variables/94148/2 "2023-02-06T16:45:09Z")

</div>

Do one of the following:

- remove the arguments from the definition of `df`, so write `df = sympy.diff(f(x,y),x)` instead of `df(x,y) = sympy.diff(f(x,y),x)`
- call `df(x,y)(0,pi/2)` instead of `df(0, pi/2)`

The reason it fails is because you are creating a _Julia function_ that takes two arguments `x, y` and evaluates the expression on the right hand side. So `df(0, 1)` would try to do `sympy.diff(f(0,1),0)` which is not what you want I suppose.

Instead, SymPy already returns an object from `diff` which can be called with the remaining variables.
