 # Derivative of a registered function

I want to compute some Jacobian matrix and get the numerical value.
However, if I registered the user-defined function, I can’t get the result.

For example, before `@register`:

``````using ModelingToolkit

@parameters t
D = Differential(t)
@variables x(t)

f(x) = tanh(x)
``````
``````julia> A = [f(x)]
1-element Vector{Num}:
tanh(x(t))

julia> jac = Symbolics.jacobian(A, [x])
1×1 Matrix{Num}:
1 - (tanh(x(t))^2)

julia> Symbolics.substitute.(jac, [x => 1])
1×1 Matrix{Num}:
0.41997434161402614

# the value above is what I want to get
``````

After `@register`:

``````julia> @register f(x)

julia> A = [f(x)]
1-element Vector{Num}:
f(x(t))

julia> jac = Symbolics.jacobian(A, [x])
1×1 Matrix{Num}:
Differential(x(t))(f(x(t)))

julia> Symbolics.substitute.(jac, [x => 1])
1×1 Matrix{Num}:
Differential(x(t))(0.7615941559557649)
``````

It seems that `Symbolics.expand_derivatives` is ineffective?

``````julia> Symbolics.expand_derivatives.(jac)
1×1 Matrix{Num}:
Differential(x(t))(f(x(t)))
``````

I didn’t find much information in the documentation, did I miss something?
Or how can I compute the derivative?

You have to define the derivative. Derivatives and Differentials · Symbolics.jl

Oh, I didn’t notice that. It works, thank you!