I have a fixed-step model (0.001s) in Simulink in which a second order ODE is effectively being set up, a free spring-mass-damper system (m=2, c=0.3, k=1, x0=0, x_dot_0=4).
I am studying the solvers and in particular the implementation of the fourth order Runge-Kutta method (ODE4). I have the analytical function generating the exact solution for comparison, and am finding that the ODE4 solver to be much more accurate over the first 50 seconds (50000 steps) of solution than a hand-implemented version coded once into an excel spreadsheet and again into a C++ application.
The Simulink model deviates by around 10^-14 from the exact solution, essentially the accuracy of the double precision value. A hand-implemented RK4 solution is getting only 10^-2 accurate.
Does anyone have experience with this and know what Simulink is doing to get accuracy beyond that which I can get by hand? I know it potentially uses sub-steps for greater accuracy though I have tested using 0.000001s steps and only got to 10^-5 accuracy and I am sure it can't be using anywhere near that step size.
It is possible I have not implemented the RK formula correctly.