MATLAB Answers

What are reasons for ODE giving different results with the same parameters?

12 views (last 30 days)
Bernardo Hernandez
Bernardo Hernandez on 17 Oct 2019
Answered: Saket Chirania on 28 Jan 2021
I ran a certain ODE in April 2019 and got a certain result. The code I used and the results were saved using git for version control. I ran the same ODE now in October, with the same code which I pull from the repository, and the integration diverges after ~3% of the total time has been simulated.
The computer is the same (it has not been formatted, although I did install an Ubuntu partition on it), the MATLAB version is the same (R2017b) and the code is the same. Now, the ODE is somewhat ill-conditioned and I had experienced divergence before when modifying slightly some of its parameters, however I am sure from the version control that I am running exactly the same code as before.
I know that the most probable reason is that I am not running the same code, but I really cannot find the difference. Are there any other reasons this might be happening?

Answers (1)

Saket Chirania
Saket Chirania on 28 Jan 2021
Hello Bernardo,
The different results here are maybe because of round-off errors between different machines or operating system, which are to be expected and which MATLAB cannot account for, as it is based on the machine itself. Because of the formulation of the ODE these numerical errors propagate and lead to the large differences seen in the final result. A simple view of these sort of problems can be seen by ODEs that require non-negativity:
ODE solvers perform numerical approximations of the derivatives and use those to update the solutions for small enough timesteps to get accurate solutions. This means that the errors locally can be small but when aggregated together over the entire time vector large differences can appear from expected solutions. For stiff problems in particular choosing the right set of solvers and constraints to get the ‘right’ answer is not obvious and can require some experimentation, as it may in your case. I recommend experimenting further with the formulation of your problem if reducing the error tolerance is not an effective workaround.




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by