Hi, this is my first post here. I am new to using Symbolics.jl (coming from a MATLAB background) and have a couple questions regarding Differential and Symbolics.jacobian. I am using a Mac, and the Pluto environment:
@variables x y
f1(x,y) = x + sin(y)
f2(x,y)= y + cos(x)
J(x,y) = Symbolics.jacobian([f1(x,y), f2(x,y)], [x, y])
# Pluto cell outputs J(x,y) = [1 cos(y); -sin(x) 1]
The type of J(x,y)
is Matrix{Num}
, witch is confusing because I expected it to be a matrix of functions of x,y. Furthermore, evaluating J(1,2)
returns a zero matrix instead of what i expect: [1 cos(1); -sin(2) 1]
.
A similar problem also occurred using Symbolic.jl Differential:
@variables x y
D = Differential(x)
f(x,y) = x^3+sin(y+x)
df(x,y) = expand_derivatives(D(f(x,y)))
df(1,2)
The cell returns 0, instead of` 3+cos(3)
. df(x,y)
correctly outputs as 3x^2+cos(x+y)
but again, the type of df(x,y)
is Num. My best guess is that in Julia, f(1,2) is evaluated first (1+sin(3)
) then the derivative is applied to the constant and thus equals zero. But the order of operations here seem counterintuitive.
Why does this happen? Is there any way to somehow take the derivative of f, and store it as a function in df such that I can call it like df(1,2)