# Derivative of a registered function

**URL:** https://discourse.julialang.org/t/derivative-of-a-registered-function/69656
**Category:** Modelling & Simulations
**Tags:** modelingtoolkit, symbolics
**Created:** [October 13, 2021, 3:28am UTC](https://discourse.julialang.org/t/derivative-of-a-registered-function/69656 "2021-10-13T03:28:01Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![PikaPei](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pikapei/32/16872_2.png) [@PikaPei](https://discourse.julialang.org/u/PikaPei)
#### Post date: [October 13, 2021, 3:28am UTC](https://discourse.julialang.org/t/derivative-of-a-registered-function/69656/1 "2021-10-13T03:28:01Z")

</div>

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`:

```julia
using ModelingToolkit

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

f(x) = tanh(x)

```

```julia
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
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
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?

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [October 13, 2021, 4:04am UTC](https://discourse.julialang.org/t/derivative-of-a-registered-function/69656/2 "2021-10-13T04:04:23Z")

</div>

You have to define the derivative. [Derivatives and Differentials · Symbolics.jl](https://symbolics.juliasymbolics.org/dev/manual/derivatives/#Adding-Analytical-Derivatives-1)

---

<div class="post-metadata">

### Author: ![PikaPei](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pikapei/32/16872_2.png) [@PikaPei](https://discourse.julialang.org/u/PikaPei)
#### Post date: [October 13, 2021, 7:03am UTC](https://discourse.julialang.org/t/derivative-of-a-registered-function/69656/3 "2021-10-13T07:03:27Z")

</div>

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