Order of convergence in Euler's method

1.1k Views Asked by At

I am writing a program to find order of convergence of the Euler's method for finding numerical solution of ODE with given initial condition. The formula to estimate the order of convergence is given by $q=\frac{\log(\frac{e_{new}}{e_{old}})}{\log(\frac{h_{new}}{h_{old}})}$ where $e_{new}=|\text{actual value}-\text{numerical value with } h_{new} \text{ step size } |$, $e_{old}=|\text{actual value}-\text{numerical value at } h_{old}\text{ step size}|$ $h_{new}=\text{step size at }(i+1)^{th} \text{stage}$,$h_{old}=\text{step size at }(i)^{th} \text{stage}$. I made a Matlab program to estimate the order but for smaller step size this estimate is becoming zero or negative values and it is nowhere near 1 which is the order of convergence of Euler method. I am unable to find a mistake. Is my formula right or am I doing something wrong?