# DifferentialEquation solvers not giving desired output

**URL:** <https://discourse.julialang.org/t/differentialequation-solvers-not-giving-desired-output/100645>\
**Category:** New to Julia\
**Tags:** differentialequation\
**Created:** [June 21, 2023, 11:18am UTC](https://discourse.julialang.org/t/differentialequation-solvers-not-giving-desired-output/100645 "2023-06-21T11:18:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sahil\_Khan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sahil_khan/32/47573_2.png) [@Sahil\_Khan](https://discourse.julialang.org/u/Sahil_Khan)\
**Post date:** [June 21, 2023, 11:18am UTC](https://discourse.julialang.org/t/differentialequation-solvers-not-giving-desired-output/100645/1 "2023-06-21T11:18:30Z")

</div>

I have a model for which i already have fits in r language. Now i’m implementing same in Julia where i’m not getting any fits. Upon checking different solvers with my posterior from r, I can see none of solvers is giving fit plot that I obtained in r. I can see oscillation in solution. My system is stiff.

Solvers I have used are :

```julia
alg = [BS3(), Tsit5() , Rodas4(autodiff=false), Vern7(),QNDF() , TRBDF2(), AutoTsit5(Rosenbrock23()), AutoVern7(Rodas5()), CVODE_BDF(), Rodas5(), Rodas5P()]

```

Sorry but I cant share plots here. Is there any other solver that I can hope to give stable solution?

---

<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:** [June 21, 2023, 12:10pm UTC](https://discourse.julialang.org/t/differentialequation-solvers-not-giving-desired-output/100645/2 "2023-06-21T12:10:02Z")

</div>

have you run the function separately from the integrator to make sure it gives the same results?

---

<div class="post-metadata">

**Author:** ![Sahil\_Khan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sahil_khan/32/47573_2.png) [@Sahil\_Khan](https://discourse.julialang.org/u/Sahil_Khan)\
**Post date:** [June 21, 2023, 12:19pm UTC](https://discourse.julialang.org/t/differentialequation-solvers-not-giving-desired-output/100645/3 "2023-06-21T12:19:30Z")

</div>

you mean something like this `integrator = init(prob, Tsit5(); dt = 1 // 2^(4), tstops = [0.5])` rather than solve?

---

<div class="post-metadata">

**Author:** ![John\_Gibson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/john_gibson/32/5321_2.png) [@John\_Gibson](https://discourse.julialang.org/u/John_Gibson)\
**Post date:** [June 21, 2023, 12:45pm UTC](https://discourse.julialang.org/t/differentialequation-solvers-not-giving-desired-output/100645/4 "2023-06-21T12:45:49Z")

</div>

It’s not really possible to give specific advise without a more definite problem description, i.e. a complete but minimal working example that exhibits a clear-cut error. Generally speaking, rather than checking the Julia’s output against R’s output, it would be better to find a closely related problem with known closed-form solution, and check whether the Julia solution converges towards the closed-form solution at the expected rate.

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …

> [@PSA: How to help yourself debug differential equation solving issues](https://discourse.julialang.org/t/psa-how-to-help-yourself-debug-differential-equation-solving-issues/62489):
>
> Debugging differential equation solver issues almost always boils down to doing the same thing, so this is a summary to help you out. For more information on specific issues, check out the FAQ section of the DifferentialEquations.jl documentation which highlights common issues and questions: [https://diffeq.sciml.ai/dev/basics/faq/](https://diffeq.sciml.ai/dev/basics/faq/)How do I debug why the differential equation solver is diverging? dt \<= dtmin. Aborting. There is either an error in your model specification or the true solution i…

---

<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:** [June 21, 2023, 12:50pm UTC](https://discourse.julialang.org/t/differentialequation-solvers-not-giving-desired-output/100645/5 "2023-06-21T12:50:42Z")

</div>

no, I mean just call `f(u, p, t)` with random `u` and `t` values (the same random values for Julia and R). The most common reason for this type of error is that you made a typo when porting the function.

---

<div class="post-metadata">

**Author:** ![Sahil\_Khan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sahil_khan/32/47573_2.png) [@Sahil\_Khan](https://discourse.julialang.org/u/Sahil_Khan)\
**Post date:** [June 21, 2023, 12:55pm UTC](https://discourse.julialang.org/t/differentialequation-solvers-not-giving-desired-output/100645/6 "2023-06-21T12:55:55Z")

</div>

I will try that and post here the output.

---

<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:** [June 21, 2023, 12:57pm UTC](https://discourse.julialang.org/t/differentialequation-solvers-not-giving-desired-output/100645/7 "2023-06-21T12:57:00Z")

</div>

See this video for some help:

[![](https://global.discourse-cdn.com/julialang/original/3X/5/d/5d8be9be2d861eecc910a9bdda15b5b546dd839f.jpeg "How to debug Julia simulation codes (ODEs, optimization, etc.!)") ](https://www.youtube.com/watch?v=g-iOOhh2U6o)

Note that you can use deSolve.jl to call exactly the same solvers from R. If they aren’t giving the exact same solution then, you can be certain that your `f` function is implemented differently.

> **[GitHub - SciML/deSolveDiffEq.jl: Wrappers for calling the R deSolve...](https://github.com/SciML/deSolveDiffEq.jl)**
>
> Wrappers for calling the R deSolve differential equation solvers from Julia for scientific machine learning (SciML) - GitHub - SciML/deSolveDiffEq.jl: Wrappers for calling the R deSolve differentia...

As @Oscar_Smith said, the first step of debugging a model translation from another language is to run the `f` call on the same random values in both languages and see that they give exactly the same results. Like 99% of the time someone reports a translation issue, this is the diagnostic that fails and identifies the bug.
