# Instability after reducing number of equations in DifferentialEquations.jl

**URL:** <https://discourse.julialang.org/t/instability-after-reducing-number-of-equations-in-differentialequations-jl/124133>\
**Category:** General Usage\
**Tags:** differentialequation\
**Created:** [December 23, 2024, 6:29pm UTC](https://discourse.julialang.org/t/instability-after-reducing-number-of-equations-in-differentialequations-jl/124133 "2024-12-23T18:29:48Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![diffeqslvr](https://avatars.discourse-cdn.com/v4/letter/d/f475e1/32.png) [@diffeqslvr](https://discourse.julialang.org/u/diffeqslvr)\
**Post date:** [December 23, 2024, 6:29pm UTC](https://discourse.julialang.org/t/instability-after-reducing-number-of-equations-in-differentialequations-jl/124133/1 "2024-12-23T18:29:48Z")

</div>

I have a large set of differential equations (O(10000)) which I try to solve using Tsit5() and DifferentialEquations.jl.

sol = solve(  
prob,  
Tsit5(),  
dtmax = 0.1,  
maxiters = 100000,  
progress = true,  
saveat = 0.01,  
)

I found a symmetry in the system, which allowed me to reduce the amount of equations. However, after some time, the symmetrized set of equations becomes unstable (see screenshot). Before that the dynamics looks the same as in the non-symmetrized case.

I do not understand this behavior - is the redundancy making the equations more stable?

I tried choosing alg\_hints = :auto to automatically choose a solver, but the execution time became very large and the instabilities remained.

 ![comparison](https://global.discourse-cdn.com/julialang/original/3X/0/6/060ec9e4dc561a89fc69c49ed32b8404b5335930.png)

---

<div class="post-metadata">

**Author:** ![yolhan\_mannes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yolhan_mannes/32/220485_2.png) [@yolhan\_mannes](https://discourse.julialang.org/u/yolhan_mannes)\
**Post date:** [December 23, 2024, 6:38pm UTC](https://discourse.julialang.org/t/instability-after-reducing-number-of-equations-in-differentialequations-jl/124133/2 "2024-12-23T18:38:49Z")

</div>

You can try the most accurate solvers(I like radauIIA5 but rosenbrock are also great) if that fails then you can try Sundial Fortran ones and if this fail too, it’s the model that may have something weird going one.

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [December 23, 2024, 6:41pm UTC](https://discourse.julialang.org/t/instability-after-reducing-number-of-equations-in-differentialequations-jl/124133/3 "2024-12-23T18:41:16Z")

</div>

Did you try to set `abstol` and `reltol` to a low value, e.g. 1e-6?

---

<div class="post-metadata">

**Author:** ![diffeqslvr](https://avatars.discourse-cdn.com/v4/letter/d/f475e1/32.png) [@diffeqslvr](https://discourse.julialang.org/u/diffeqslvr)\
**Post date:** [December 23, 2024, 6:53pm UTC](https://discourse.julialang.org/t/instability-after-reducing-number-of-equations-in-differentialequations-jl/124133/4 "2024-12-23T18:53:35Z")

</div>

Thanks for the quick reply! My equations are complex, and the solvers you suggested only work with real equations as far as I can see…  
Do you think it is worthwile to restructure my code such that I propagate real and imaginary part separately?

---

<div class="post-metadata">

**Author:** ![diffeqslvr](https://avatars.discourse-cdn.com/v4/letter/d/f475e1/32.png) [@diffeqslvr](https://discourse.julialang.org/u/diffeqslvr)\
**Post date:** [December 23, 2024, 6:57pm UTC](https://discourse.julialang.org/t/instability-after-reducing-number-of-equations-in-differentialequations-jl/124133/5 "2024-12-23T18:57:59Z")

</div>

Thanks for the quick reply! I set them 1e-6 but the instability is still there…

---

<div class="post-metadata">

**Author:** ![yolhan\_mannes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yolhan_mannes/32/220485_2.png) [@yolhan\_mannes](https://discourse.julialang.org/u/yolhan_mannes)\
**Post date:** [December 23, 2024, 7:15pm UTC](https://discourse.julialang.org/t/instability-after-reducing-number-of-equations-in-differentialequations-jl/124133/6 "2024-12-23T19:15:52Z")

</div>

how is `Rodas5(autodiff=false)` doing ? maybe later on for performance you can split depends on the solver you will need

---

<div class="post-metadata">

**Author:** ![diffeqslvr](https://avatars.discourse-cdn.com/v4/letter/d/f475e1/32.png) [@diffeqslvr](https://discourse.julialang.org/u/diffeqslvr)\
**Post date:** [December 23, 2024, 7:47pm UTC](https://discourse.julialang.org/t/instability-after-reducing-number-of-equations-in-differentialequations-jl/124133/7 "2024-12-23T19:47:23Z")

</div>

> [@yolhan\_mannes](#):
>
> `Rodas5(autodiff=false)`

It gets stuck at the beginning… Maybe there are too many equations?

---

<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:** [December 23, 2024, 9:23pm UTC](https://discourse.julialang.org/t/instability-after-reducing-number-of-equations-in-differentialequations-jl/124133/8 "2024-12-23T21:23:15Z")

</div>

Can you share the equations? This will be impossible to debug at a distance.

---

<div class="post-metadata">

**Author:** ![diffeqslvr](https://avatars.discourse-cdn.com/v4/letter/d/f475e1/32.png) [@diffeqslvr](https://discourse.julialang.org/u/diffeqslvr)\
**Post date:** [January 7, 2025, 11:24am UTC](https://discourse.julialang.org/t/instability-after-reducing-number-of-equations-in-differentialequations-jl/124133/9 "2025-01-07T11:24:20Z")

</div>

Hi sorry for the late reply I was on a Christmas holiday!

I have over 10 000 equations and quite a huge code base, so it is not easy to create a minimal working example… Are there no diagnostics that I can do?

---

<div class="post-metadata">

**Author:** ![Salmon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/salmon/32/22968_2.png) [@Salmon](https://discourse.julialang.org/u/Salmon)\
**Post date:** [January 7, 2025, 1:49pm UTC](https://discourse.julialang.org/t/instability-after-reducing-number-of-equations-in-differentialequations-jl/124133/10 "2025-01-07T13:49:42Z")

</div>

It seems to be a pretty problem specific issue, nonetheless a few questions that could maybe lead you to the solution:

- What do you mean by unstable? Does the solver terminate with an error or is the result merely different?
- Is there any way to reduce the number of equations without using symmetries? I.e. a numerical parameter, problem size etc that you can tune to make checking the problem a bit simpler?
- If you solve the unsymmetrized ODE, does your solution maintain the symmetry? I.e. at each time step you could check this explicitly: If the symmetry is not fully maintained, does this happen immediately at the beginning or is there perhaps a gradual increase in the error?
- If the symmetry is not kept, this could be due to numerical errors, in computing the derivative. An error of about `1e-14` would likely be simple floating point accuracy which may be harmless. If the derivative you compute strictly obeys symmetries, then I would not expect the choice of the ODE integrator to matter.
- If the symmetry is maintained also in your numerics, you can try to gradually move from the non-symmetric to the symmetric solution:

1. In the nonsymmetric part, compute the neccessary derivatives. Then set the symmetry equivalent ones explicitly to be equal to the nonsymmetric parts. Note that you keep the size of the ODE state array the same. If your numerics keep the symmetry this should still produce the same result.
2. If 1 is successful, you could try actually reducing the number of equations.

---

<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:** [January 7, 2025, 2:56pm UTC](https://discourse.julialang.org/t/instability-after-reducing-number-of-equations-in-differentialequations-jl/124133/11 "2025-01-07T14:56:51Z")

</div>

This still needs code to do any debugging.
