Thank you!
Except the first line, where I use using ModelingTools
, everything else ran smoothly. Thanks!
There is a little bit more codes than using SymPy
.
Here is the example code using SymPy
:
julia> using SymPy
julia> x, y = symbols("x, y", real = true)
(x, y)
julia> f(x, y) = x^2 + y
f (generic function with 1 method)
julia> @time diff(f(x, y), x)
0.625819 seconds (215.81 k allocations: 10.815 MiB)
2⋅x
julia> @time diff(f(x, y), x)
0.001549 seconds (41 allocations: 1.281 KiB)
2⋅x
julia> @time diff(f(x, y), x)
0.001116 seconds (41 allocations: 1.281 KiB)
2⋅x
And on my old machine the method of using ModelingToolset
is slower:
julia> using ModelingToolkit
julia> f( (x,f) ) = x^2 + y
f (generic function with 1 method)
julia> vars = @variables x, y
(x, y)
julia> ex = f(vars)
x ^ 2 + y
julia> @derivatives D'~x
((D'~x),)
julia> d1 = D(ex)
derivative(x ^ 2 + y, x)
julia> @time expand_derivatives(d1)
29.517026 seconds (9.08 M allocations: 462.105 MiB, 1.26% gc time)
2x
julia> @time expand_derivatives(d1)
0.008669 seconds (6.03 k allocations: 202.188 KiB)
2x
julia> @time expand_derivatives(d1)
0.007397 seconds (6.03 k allocations: 202.188 KiB)
2x
julia> @time expand_derivatives(d1)
0.007210 seconds (6.03 k allocations: 202.188 KiB)
2x
@Seif_Shebl, by the way, I do not know enough, but your example codes do not use SymEngine.
My initial question was how @ChrisRackauckas used SymEngine and ModelingToolset to speed up computation.
My small comparison shows that SymPy is faster. Is this expected?