0
$\begingroup$

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')

enter image description here

enter image description here

$\endgroup$
2
$\begingroup$

This is apparently the difference between $e^x$ and $(1+h)^{x/h}$ 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.

For $x=100$ and $h=0.5$ one gets the value 1.6529199107882081e+35, with $h=0.05$ the value is 2.3911022046137546e+42, which about fits the observed difference in magnitude. The exponential value is 2.6881171418161356e+43.

$\endgroup$
6
  • $\begingroup$ Thank you once again!! So, the common sense that is always better to put time-step smaller is not true? $\endgroup$ – Quiet_waters Dec 11 '20 at 18:19
  • 1
    $\begingroup$ 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. $\endgroup$ – Lutz Lehmann Dec 11 '20 at 19:09
  • $\begingroup$ thank you very much! $\endgroup$ – Quiet_waters Dec 11 '20 at 23:51
  • $\begingroup$ 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. $\endgroup$ – Quiet_waters Dec 12 '20 at 13:26
  • 1
    $\begingroup$ That is the difference between theoretical results and numerical considerations. In the theory there is no floating point noise, as the numbers are real numbers with no restrictions on mantissa length. $\endgroup$ – Lutz Lehmann Dec 12 '20 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.