MATLAB: Ode15s get stuck randomly

convergence problemode solverode15s

Hi,
I'm running into a weird problem with the ode15s solver. At the beginning my code was running perfectly well, but since a little while sometimes the ode15s solver get stuck either at a timestep in the middle of the run or even at the first iteration.
What I mean by stuck is that it takes a really really long time to finally end the time step. My wonder comes from the fact that I happened a few time that running the code with the exact same parameters as when stuck, but in a new folder and recopying the files one by one there, the code would run at a much more "reasonable" speed…
Have anyone run into that kind of issue or know where it could be coming from?
Thanks a lot,
Flavien

Best Answer

This sounds like a magic behaviour. But without any doubt Matlab acts deterministically. Different guesses:
  1. You think that you have started the integration with the same parameters, but accidently you didn't. Bugs happen.
  2. The function to be integrated contains discontinuities. This is outside the specifications of Matlab's integrators and must be caught by an event function. See http://www.mathworks.com/matlabcentral/answers/59582#answer_72047 . Then tiny variations of the input can cause a completely different output and runtime.
  3. The function contains calls to a subfunction, when it is stored in a specific folder. So a function in either the same folder or a private subfolder shadows a builtin oder user-defined function.
  4. It is not the integrator, which needs more time, but another task on the computer: E.g. when the input data are read from the disk and a sector is damaged, the reading will take much longer. Or the computer started the virus detection or hard disk defragmentation.
The solution is always the same: Use the debugger to find the differences between the versions running with different speeds. Check if the effect is reproducible.
Related Question