I'd have a rather complex system of non linear ODEs and with a lot of help I've written an algorithm that solves them. I'd now like to compute the relative error, but I do not have a known solution to compare it with.
One thought was to compare my algorithm to MATLABs ode45 function (I wrote an RK4 method in python). However, I don't know what step size ode45 is using. And, my algorithm is in python, so I'd probably have to print to file and compare data in excel or something.
I have also read about "Approximate Relative Error", where you compare one step in the solution to the last. I don't intuitively understand how this depicts error. It just seems like it measures the smoothness of the estimate rather than any error.
I have also thought of decreasing step size and comparing the solution at a single point with two different step sizes.
I like my first idea best, because it's nice to have a "known" solution. Not sure if that is the most revealing approach, though.
If your derivative function is called
odesysand you have a time arraytspanthat contains the step times of the RK4 method, then you can use thescipypackage and use, in the main points, something likeI hope there is an
odesys(t,y)system function, vectoryto vector\dot y. If not, the code for any integration method becomes complex and error prone.To the first question,
ode45does not have one fixed step size, it has a step size controller that adapts the step size to the local behavior of the system. All values in-between are interpolated using a method-adapted polynomial interpolation. You can see these internal steps in matlabode45when giving the integration interval only by the end-points and pythonsolve_ivpby not specifying thet_evalparameter. Then the time and value list returned by the method contain those internal points.