# Would it be worth it to move to DifferentialEquation.jl?

**URL:** <https://discourse.julialang.org/t/would-it-be-worth-it-to-move-to-differentialequation-jl/110297>\
**Category:** Numerics\
**Tags:** differentialequation\
**Created:** [February 16, 2024, 3:01pm UTC](https://discourse.julialang.org/t/would-it-be-worth-it-to-move-to-differentialequation-jl/110297 "2024-02-16T15:01:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lrnv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lrnv/32/19373_2.png) [@lrnv](https://discourse.julialang.org/u/lrnv)\
**Post date:** [February 16, 2024, 3:01pm UTC](https://discourse.julialang.org/t/would-it-be-worth-it-to-move-to-differentialequation-jl/110297/1 "2024-02-16T15:01:19Z")

</div>

Hey,

I have an application that is taking a bit long, but looking at profview i am wondering if it would be actually worth it to move it to DE.jl. Here are the specifics:

- I have a pre-setted grid with a lot of time points (around 4000) on which I am solving the equation. I cannot change the grid.
- at each time point, I then have to solve a non-linear equation that depends on the previous solves.
- Most (90%) of my runtime is in solving this equation each time with `Roots.find_zero()`, using the previous value as a starting point.

I included a small dataset together with the code in this gist : [Differential equation solving -- example · GitHub](https://gist.github.com/lrnv/9348ea35ab1df09ae2a67131c9351080). The code itself is about 100 lines long.

Do you think DE.jl will do a much better job ? If so, how should i reformat this so that it takes it ?

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [February 16, 2024, 3:27pm UTC](https://discourse.julialang.org/t/would-it-be-worth-it-to-move-to-differentialequation-jl/110297/2 "2024-02-16T15:27:29Z")

</div>

It looks like you are currently using Implicit Euler. You could likely get a roughly 10x speedup by switching since it would make it trivially easy to use higher order methods (e.g. FBDF). all you need to do to port it is rewrite `equation` to the form `equation(u, p, t)` where `u` is a state vector, `p` is any time independent parameters, and `t` is the current time. The function should return du/dt for each u.

---

<div class="post-metadata">

**Author:** ![lrnv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lrnv/32/19373_2.png) [@lrnv](https://discourse.julialang.org/u/lrnv)\
**Post date:** [February 16, 2024, 3:31pm UTC](https://discourse.julialang.org/t/would-it-be-worth-it-to-move-to-differentialequation-jl/110297/3 "2024-02-16T15:31:47Z")

</div>

so the huge dataset would go in `p` ? Can you point me to the part of the docs that actually shows how to use implicit euler with hand-picked time points ? My first goal would be to reproduce the results i already have before trying other methods.

Even if I am not sure other methods would be interesting, since the final `du/dt` is actually piecewise constant (the jump times are my time frame).

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [February 16, 2024, 3:37pm UTC](https://discourse.julialang.org/t/would-it-be-worth-it-to-move-to-differentialequation-jl/110297/4 "2024-02-16T15:37:01Z")

</div>

wait, if `du/dt` is piecwise constant, can’t you use explicit euler and skip the nonlinear solve completely?

---

<div class="post-metadata">

**Author:** ![lrnv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lrnv/32/19373_2.png) [@lrnv](https://discourse.julialang.org/u/lrnv)\
**Post date:** [February 16, 2024, 3:39pm UTC](https://discourse.julialang.org/t/would-it-be-worth-it-to-move-to-differentialequation-jl/110297/5 "2024-02-16T15:39:23Z")

</div>

Well it still depends on u. Hum… Maybe it is not piecewise constant then, but my approximation of it might be.

More precisely : it is a non-linear function of u that is defined piecewise.
