I am looking at the effect of the step size (h) on the size of the error for Euler's method. I am using the following ODE:
With the following conditions:
y(0) = 0, solving for x = pi
I get the errors shown below for each step size.
I checked my calculations were correct using this online calculator:
On the wikipedia page for Euler's Method (https://en.wikipedia.org/wiki/Euler_method#Global_truncation_error), it states that the error should be approximately proportional to h because it is a 1st order method, but in my data it is approximately proportional to h squared! This only happens for this particular ODE. The other ODEs I tested gave errors proportional to h squared, but I can't find any explanation for why this ODE is different.
Thank you for ay help!
It's been a while since I dealt with this sort of stuff, but I think that this is the likely explanation.
For the ode
\(\displaystyle y'=f(x,y) ,\)
the local truncation error is
which, for the given equation will be
Since we are working over the range 0 to pi, what will happen is that the errors to the left of pi/2 will, in some way, cancel out with the errors to the right of pi/2, (because the cosines will be equal in magnitude but opposite in sign).
That means that the truncation errors don't build up in the usual way. Looking at the truncation errors for each step will probably give a clearer picture.
A further thought.
Repeat your calculations for x = 0 to x = pi/2 and see if the errors behave as they should.