(2) Trying to model a simple second order ODE: Why time-step smaller is not better

This question is related with this other question: Trying to model a simple second order ODE.

On this other question, I get some useful comments on why the simulations are so terrible.

However, I have another question: Why time-step smaller is not better? Thank you in advance.

h=0.05 %h=0.5;
max=100;
np=max/h;
u=[];
y=[];
u(1)=0;
u(2)=-h^2/2-h;
y(1)=0;
y(2)=-h^2/2-h;
x=[0:h:max];
for i=3:np+1;
u(i)=u(i-1)*(h+2)+u(i-2)*(-h-1)+h^2*x(i);
y(i)=-(x(i))^2/2-(x(i));
end
close all
plot(x,u)
hold on
plot(x,y,'r')


This is apparently the difference between $$e^x$$ and $$(1+h)^{x/h}\approx e^x·e^{-hx/2+O(xh^2)}$$ for different values of $$h$$. The latter is the term that occurs directly in solving the recursive inequalities for the global error, for small $$h$$ this converges to the exponential.
Due to the choice of the starter values $$u_1,u_2$$ and the shift in the $$x$$ sequence, the exponential term in the numerical solution is of size $$h(1+h)^{x/h}$$.
For $$x=100$$ and $$h=0.5$$ one gets the value 8.2645995539410405e+34, with $$h=0.05$$ the value is 1.1955511023068773e+41, which about fits the observed values. As reference, the exponential value $$e^x$$, $$x=100$$, is 2.6881171418161356e+43.
• What you see here is a reduction from ludicrous to gigantic, so not really a difference. In the range of really small step sizes you get an error contribution from floating point roundings of size $\mu/h$ which will dominate the truncation error at some point. For RK4 this gives an optimal step size of $Lh=0.001$ in the usual double number data type, for higher order methods that is even larger. Smaller than that really does get increasingly worse, not really wrong as with large step sizes, but no gain for the increased effort. Commented Dec 11, 2020 at 19:09
• I am sorry if I bother once again, but I have the last doubt: Convergence condition says that for all node tn we must have $|y_n−u_n|≤C(h)$, where $\lim_{h\to0}C(h)=0$. Euler and central differences are convergent (and consistent) methods, I mean, for each method the truncation error must be $\tau$ s.t. $\lim_{h\to0}\tau(h)=0$. However, as we see, $\lim_{h\to0}C(h)\neq0$ (as you say, 'smaller than that really does get increasingly worse'). So, what is the error on thought? Thank you once again and sorry by bothering. Commented Dec 12, 2020 at 13:26