How reliable is the approximate solution computed by ode45 with default 'Abstol' and 'Reltol' values (the analytic solution of the ode is unknown)?

7 views (last 30 days)
I stumbled upon some unexpected results while numerically solving a system of odes using the 'solve_ivp' function in Python. My aim was to reproduce the result which I have from MATLAB (ode45) in Python using the same rk4(5) method, But to my surprise I found a particular case ( for a particular set of parameters) where the two functions are giving different solution. All the parameter values, initial conditions, and 'Abstol' and 'Reltol' (1e-6 and 1e-3 respectevily) are same. Both solutions are giving periodic orbits but of different kind, that means the solutions are converging, therefore the integration is successful and some solution is reached, but why are they different? Are there two co-existing solutions? and why two softwares converging to different solutions? As I have no idea of the analytic solution of my system what can be said about the accuracy of the numerical methods?
Also It will be very helpful if someone can shed some light on the use of 'Abstol' and 'Reltol'. As I learned from various sources the 'Reltol' decides the number of correct digits. Does it mean the solution I am getting is correct upto third decimal place? The local error of RK4 is O(h^5), but ode45 computes solution with variable stepsize. Is that the reason we need to specify the 'Reltol' to have a universal control over the error? Or am I completely wrong about the understanding of 'Reltol'!
Though I have two different questions, but I think they may be related to give a plausible explanation about these discrepancies in result.
I am attaching few plots computed in MATLAB and Python for comparison. If you notice the Python plot you will see the solution is staying close to two regions for quite some time, I guess one of those is the MATLAB solution.
Any input here is welcome. Thanks in advance.

Answers (1)

Arun
Arun on 6 Oct 2023
Hi Rebeka,
I understand that the primary question is around “Reltol” (relative tolerance) and how it impacts the calculated values in case of ode45 method. Here are some details about “Reltol” that may be of help to you:
  • ‘‘Reltol’ (Relative Tolerance) represents the relative error tolerance for the solution. It quantifies the difference between the numerical solution and the exact solution.
  • In this case the value of ‘Reltol’ is 1e-3, indicating a relative tolerance of 0.001. Consequently, the solution is allowed to vary up to the third decimal place.
  • Indeed, possessing universal control over the error by ‘Reltol’ provides a more consistent and adaptive measure of error control. This capability allows the numerical integration algorithm to dynamically adjust the step size based on the local behaviour of the solution, thereby ensuring accurate results across varying scales.

Community Treasure Hunt

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

Start Hunting!