# Differentials in ModelingToolkit

I’m trying to find the derivative in ModelingToolkit.jl

This is how it was done in SymEngine

``````using SymEngine

x=symbols(:x)
diff(4x^3,x)
``````

would give 3x^2

How would I do the same thing in ModelingToolkit?

1 Like

See the first tutorial: https://mtk.sciml.ai/dev/tutorials/symbolic_functions/#Derivatives-1

4 Likes

Ok thanks I have it working one thing I noticed

``````using Latexify
using ModelingToolkit

@variables x
@derivatives δx'~ x
F(x)=(3x^2+x^3)/x
latexify(expand_derivative(δx(F)))
``````

produces an output containing the factor (x^-2) instead of dividing everything by (x^2), which is hardely an issue, except that it won’t latexify as a function.

I’m also not finding that simplification does much.

This expression should reduce to (2x+3).

1 Like

Please open an issue with simplifications you see fail. That is all about tweaking the heuristics, or training a neural network.

1 Like

I put an issue on GitHub. If it’s for AI I can do it with every problem that isn’t working.

Right now it’s rule-based, but next summer I hope we start training reinforcement learning and deploy it as one of the simplify options. Some papers suggest it can generally due better if you train it long enough

I can see that it would. I’d think most of the ones that exist are rule based, but it should be interesting to see how much gets together. I might offer to help if I have time to learn actual coding.