Let \begin{align} y'(t) &= -150y(t)+49-150t, ~~~t\in[0,1]\\ y(0) &= 1/3+0.1 \end{align} I've know the solution: $y(t) = 0.1·e^{-150t}-t+1/3$.
I'm testing a couple different numerical methods to determine which is the best (i.e., Euler's forward/backward, trapezoidal, Runge-Kutta, Heun). Can anyone help me determine the stability for the Heun method?
Heun's method: $\begin{align}y_{n+1}&=y_n+h\phi(t_n,y_n,h)\\[0.3em]\phi(t,u,h) &= \tfrac{1}{2}[f(t,u)+f(t+h,u+hf(t,u))]\end{align}$
Stability of explicit Runge-Kutta methods around a fixed point or a slow moving equilibrium is obtained when $Lh\sim 1$ with $L$ the $y$-Lipschitz constant and $h$ the step size. The exact constant on the right side depends on the order of the method, usually it is between 1 and 5. For first and second order methods that is only a guideline as the stability region does not contain a semi-circle around the origin in the negative complex half-plane.
For the Heun method and any other second-order two-stage explicit Runge-Kutta method, the stability region is given by $$ |0.5z^2+z+1|\le1, $$ with $z=\lambda h$ and $\lambda$ ranging over all the eigenvalues of the Jacobian near the equilibrium.
In the given equation the one eigenvalue is real, and the inequality $-1\le 0.5x^2+x+1\le 1$ is satisfied over $[-2,0]$. Thus qualitatively correct results, bounded with a trend to falling, can be expected for $150h<2$. For solutions that fall nearly as fast as the exact solution one needs a substantially smaller step size $h$. (Which is not really visible in the experiment as the true value is practically zero,
2e-23, while the floating-point accuracy gives zero at level1e-16. One would have to try at $t=0.1$ or $t=0.2$.)To get a practical feeling for this, just solve the given task for various step sizes over the integration interval from $0$ to $1/3$, and compare how the values fall to zero, as $y(1/3)=0.1e^{-50}$ is a really small number, relative to the initial value and floating point precision.
with the results
As the stability region suggests, $0<h<\frac2{150}$ are valid choices in the table above, giving results close to zero. Sensible results that are practially zero as floating point numbers (and relative to the initial value) are only obtained for about $h<\frac{1.5}{150}$.