# Numerically determining convergence order of Euler's method

I need to numerically determine the convergence order of Euler's method for various step-sizes. I am unsure how to go about doing this.

Here is the question:

Problem statement: $\frac{dy}{dt}=\alpha t^{\alpha - 1}, y(0)=0$, where $\alpha > 0$. Use Euler's method to solve the initial value problem for $\alpha = 2.5,1,5,1.1$ with stepsize $h=0.2,0.1,0.05$. Determine numerically the convergence orders of the Euler method for these problems.

I have created an Excel spreadsheet with all of the relevant information tabulated (using Excel formulas), with columns $i, t_i=a+ih, a, b, \alpha, N, w_i, y(t_i), |y(t_i)-w_i|$ where:

$i=$ ith step in iteration

$t_i$= time at ith step

$a=$ initial time value

$b=$ final time value

$\alpha=$ constant in problem

$N=$ number of subintervals

$w_i=$ approximation to solution at ith step

$y(t_i)=$ true solution at ith step

$|y(t_i)-w_i|=$ Magnitude of error

Now, since I cannot estimate the error $\kappa$ from just one integration as the error term is approximately of the form $error_{t=b}(h) = Ah^{\kappa}$, one step size is not adequate to estimate $\kappa$. But if I do a log plot of the error and step size, the slope of the best line will give the required estimate of $\kappa$, which should be close to 1.

My question is how can I do the log plot of the error and step size in Excel 2013? I understand the math behind all this, but don't know how to implement it.

Thanks.

• For each $\alpha$, don't you just have three data points to plot? The error is cumulative, more or less, so plot $\log h$ against $\log |y(t_i) - w_i|$ where $t_i = 1$, or whatever the endpoint of your interval is. Nov 20 '13 at 1:47
• What do you mean three data points? What are they? Also, doesn't $t_i$ change depending on $i$, so why are you saying "endpoint of interval"?
– user5427
Nov 20 '13 at 1:52
• For each $\alpha$, you have three step sizes: $h = 0.2,0.1,0.05$ . With smaller step sizes, more steps are required to reach the same time $t=1$. So you can measure the error in solving the initial value problem, not at $t=0$ where the error is zero for all step sizes, but at the other end of your time interval, say $t_i = T$ if you are solving over $[0,T]$. Nov 20 '13 at 2:00
• Hmm... I'm running into problems on how to plot in Excel. Do you think you could give me a hand?
– user5427
Nov 20 '13 at 2:51
• Yes, let me go ahead and post an Answer, summarizing the approach, and I'll include a note about different methods giving different slopes. Nov 20 '13 at 15:12

The task is using Excel to illustrate rate of convergence for Euler's method applied to three ordinary differential equations:

$$\frac{dy}{dt} = \alpha t^{\alpha - 1} \text{ for } \alpha = 2.5,1.5,1.1$$

with initial conditions $y(0) = 0$, by varying the step size $h = 0.2,0,1,0.05$. The astute Reader will spot that these IVPs are really simple integrations, and since the exact solution $t^{\alpha}$ is available by definite integration, say to $y(1)=1$ for comparison, we can columnate the three data sets in Excel as $\log h$ versus the log of "errors" $E = |y_h(t_i)-1|$ at $t=1$ (or some other convenient endpoint).

It's not hard to find instructions on the web for how to get Excel to combine a best fit line with a "scatter plot" of data. Note that the step sizes $h$ here are in geometric progression, so after taking logarithms we'll have equally spaced arguments.

The slope of the line gives us the order of convergence of the method, i.e. the exponent by which error $E$ varies with step size $h$. While the local truncation error of (forward) Euler's method behaves like $O(h^2)$, with smaller $h$, proportionally more steps are required to reach the same endpoint. Thus the global truncation error behaves only like $O(h)$.

Now the modified Euler method does more work and should obtain a better rate of convergence, analogous to using higher order accurate quadrature rules. The local truncation error of the modified (midpoint) Euler method is $O(h^3)$ and its global truncation error is thus $O(h^2)$.

You report getting slopes for the log-log plot of modified Euler method solution of about $0.5$, but this should be more like $2$. I suspect a numerator/denominator confusion has crept into the line fitting. If not then there's something wrong with how the modified Euler method was implemented. Its rate of convergence should improve on the basic Euler method.

• Ok. The only way I could change the $1/2$ into $2$ is by plotting x vs. y instead of y vs. x (interchanging the axes). Because I'm pretty sure that all the calculations and values are correct, unless you would like to inspect them.
– user5427
Nov 20 '13 at 15:52
• The x should be $\log h$ and the y should be $\log E$. Now that I look carefully at your Chart, I can see these were indeed reversed (the step sizes $h$ are the same for all three data sets, and equally spaced, but this is only true of the vertical coordinates there). Since 1/1 is 1, I didn't notice this the first time around! Nov 20 '13 at 15:55
• Wait a second, I'm getting slopes as 2.2548, 1.8183, 1.3876. These are not close to 2. My data set shows improvement over Euler's method in all categories though. What's going wrong?
– user5427
Nov 20 '13 at 16:10
• It's a good observation. If you look at the error analysis (via Taylor series), you'll notice that the extra order of convergence comes at a cost of involving a higher order derivative. Now the exact solution $y=t^{\alpha}$ for $\alpha \gt 1$ has a smooth first derivative, but what about the higher derivatives? So modified Euler method draws a contrast among values for $\alpha$, esp. in a neighborhood of $t=0$, where basic (forward) Euler treated them about equally well. Nov 20 '13 at 16:38