I’m trying to solve a system of differenial equations involving a piecewise function with NDSolve. I tried to define this function using Piecewise but the kernel keeps crashing. I also tried to express the function in terms of UnitStep and HeavisideTheta by means of SimplifyPWToUnitStep` but the crash still takes place. (More details on the system of equations and its numerical implementation can be found here: https://mathematica.stackexchange.com/questions/218704/kernel-crash-after-repeated-use-of-ndsolve)
Do you know if there is any other alternative or workaround that I could use in order to avoid this annoying crash?
Thanks for the reply. I tried to implement the modifications you suggested but the code still crashes. I can only solve the equations a few times before the crash. (Just to make it clear, the problem is that I need to use NDSolve several times and it always happens that after some iterations it crashes, hence the do loop you find in the link. However, it is true that if I just needed to solve the equations once, the code I provided would work just fine in general).