Lambdify getting error if expression is function of time

using SymPy
using PyCall
sp = pyimport("sympy")
@vars t
x = sp.Function("x")(t)
y = sp.Function("y")(t)
z = x^2+y^2
hz = lambdify(z,(x,y))
# hz = lambdify(z,(x,y))
hz(1,1)

It is a bit confusing what is desired here. As is you have three variables: t, x, and y and are passing in two values.

Maybe this is what you want:

julia> @syms t x() y()
(t, x, y)

julia> z = x(t)^2 + y(t)^2
 2       2   
x (t) + y (t)

julia> f = lambdify(z, (t, x, y))
#118 (generic function with 1 method)

julia> f(t, x, y)
 2       2   
x (t) + y (t)

julia> f(pi/4, sin, cos)
1.0

Thank you.
but if I try like this, I’m getting error. my whole code is written in this method. please provide solution.
Thank You.

using SymPy
using PyCall
sp = pyimport("sympy")
@vars t
x = sp.Function("x")(t)
y = sp.Function("y")(t)
z = x^2+y^2
hz = lambdify(z,(t,x,y))
hz(1,1,1)

even this one also getting error

using SymPy
@vars t
x = SymFunction("x")(t)
y = SymFunction("y")(t)
z = x^2+y^2
hz = lambdify(z,(x,y,t))
hz(1,1,1)

Sorry, lambdify doesn’t correctly identify the variables x(t) and y(t) in your approach. The unevaluated function approach allows a function to be passed in; in your approach your are trying to pass in a value of x(1) to be 1 making me unclear why you are using a function there.

I have done kinematics and dynamics in this format. can you suggest any other alternative for converting symbolic expression to numerical function.
Thanks.

You can use substitution. It is more flexible, but not as performant as creating a julia function.

Thanks :+1: