# How to know if the solution given by Runge Kutta is good?

We're trying to solve a nonlinear ODE problem using the Runge-Kutta method (4th order). How to see how accurate the solution is?

Since we don't know the exact solution, there is nothing to compare the numerical solution to. We thought about decreasing the step size and comapring solutions for varying step sizes, but I don't think that makes sense since different step sizes give vectors of different lengths as solutions.

Basically, we solved a system of nonlinear ODEs using Runge-Kutta, and don't know how good the solution is. Any suggestions?

• First idea that comes to my mind: If you inject your solution into the ODE and take the norm (integral of the absolute value over your range), maybe it will give you a way to compare your different solutions ? Feb 25 '20 at 8:06

You can compute a second numerical solution with half the step size or double the step size. Then you will have solution points with differing accuracy at the same time points and can compute their difference which will fully consist of the method error.

To be more precise, apply Richardson extrapolation. That is, assume the error for the numerical solution with step-size $$h$$ is of the form $$E(t,h)=y_h(t)-y(t)=C(t)h^p+O(h^{p+1}).$$ Then comparing to the solution with twice the step-size gives for the difference $$y_{2h}(t)-y_h(t)=E(t,2h)-E(t,h)=C(t)(2^p-1)h^p+O(h^{p+1}).$$ This allows to compute the leading error term and thus a refined error estimate as $$E_R(t,h)=\frac{y_{2h}(t)-y_h(t)}{(2^p-1)}+O(h^{p+1})$$ as estimate of the current error. Similar applies for using the solution with half the step-size.

• Thank you. So, when I divide the step by two, it makes sense to compare the points that are shared? So, if I calculate two solutions with steps dt and dt/2, I can use every other point from the finer solution to compare it with the one where the step is dt? Feb 25 '20 at 11:02
• Yes, exactly that. Depending on the language used, what array operations are available, this can be done rather easily, like in matlab or python-numpy. Feb 25 '20 at 11:47

With the given data use "polyfit" and "polyder" to fit a polynomial into the solution and check to see if your data satisfy the differential equation well enough.

If the error is within your tolerance then the numerical solution is acceptable.

• Is this a standard technique? I've never heard of doing this before. Feb 25 '20 at 8:14
• If I understand this, I should use the points that Runge-Kutta determined to fit a polynomial, and then see how these polynomials fit the ODE? How to determine if the polynomial is good? Feb 25 '20 at 10:57
• No, this is wrong. In this situation, the error can grow exponentially over time. A simple example is given by $x'(t) = \lambda x(t)$. If, say, $y'(t) = \lambda y(t) + \epsilon$ and $y(0) = x(0)$, then the error $e(t) = x(t) - y(t)$ satisfies $e'(t) = \lambda e(t) - \epsilon$. It follows that $e(t) = \epsilon(1-e^{\lambda t})/\lambda$. Feb 25 '20 at 11:16
• Using the "dense output" interpolation, you actually get a third degree polynomial for each RK4 step that is 4th order accurate (only the computed next point is 5th order accurate). One could use this polynomial to extrapolate the next step and examine the error to the actual RK4 step. Feb 25 '20 at 11:53