Skip to article frontmatterSkip to article content

Euler’s method

Let a first-order initial-value problem be given in the form

u(t)=f(t,u(t)),atb,u(a)=u0.\begin{split} u'(t) &= f\bigl(t,u(t)\bigr), \qquad a \le t \le b,\\ u(a)& =u_0. \end{split}

We represent a numerical solution of an IVP by its values at a finite collection of nodes, which for now we require to be equally spaced:

ti=a+ih,h=ban,i=0,,n.t_i = a + ih, \qquad h=\frac{b-a}{n}, \qquad i=0,\ldots,n.

The number hh is called the step size.

Because we don’t get exactly correct values of the solution at the nodes, we need to take some care with the notation. From now on we let u^(t)\hat{u}(t) denote the exact solution of the IVP. The approximate value at tit_i computed at the nodes by our numerical methods will be denoted by uiu^(ti)u_i\approx \hat{u}(t_i). Because we are given the initial value u(a)=u0u(a)=u_0 exactly, there is no need to distinguish whether we mean u0u_0 as the exact or the numerical solution.

Consider a piecewise linear interpolant to the (as yet unknown) values u0,u1,u_0,u_1,\ldots, unu_n. For ti<t<ti+1t_i < t < t_{i+1}, its slope is

ui+1uiti+1ti=ui+1uih.\frac{u_{i+1} - u_{i}}{t_{i+1}-t_i} = \frac{u_{i+1}-u_i}{h}.

We can connect this derivative to the differential equation by following the model of u=f(t,u)u'=f(t,u):

ui+1uih=f(ti,ui),i=0,,n1.\frac{u_{i+1}-u_i}{h} = f(t_i,u_i), \qquad i=0,\ldots,n-1.

We could view the left-hand side as a forward-difference approximation to u(t)u'(t) at t=tit=t_i. We can rearrange the equation to get Euler’s method, our first method for IVPs.

Euler’s method marches ahead in tt, obtaining the solution at a new time level explicitly in terms of the latest value.

A basic implementation of Euler’s method is shown in Function 6.2.2.

6.2.1Local truncation error

Let u^(t)\hat{u}(t) be the exact solution of the IVP (6.2.1), and suppose that somehow we have access to it at t=tit=t_i, so that ui=u^(ti)u_i=\hat{u}(t_i). How good is ui+1u_{i+1} as an approximation to u^(ti+1)\hat{u}(t_{i+1})? The answer is revealed through a Taylor series:

u^(ti+1)[ui+hf(ti,ui)]=u^(ti+1)[u^(ti)+hf(ti,u^(ti))]=[u^(ti)+hu^(ti)+12h2u^(ti)+O(h3)][u^(ti)+hu^(ti)]=12h2u^(ti)+O(h3),\begin{split} \hat{u}(t_{i+1}) - \bigl[ u_i + hf(t_i,u_i) \bigr] &= \hat{u}(t_{i+1}) - \bigl[ \hat{u}(t_i) + hf\bigl(t_i,\hat{u}(t_i)\bigr) \bigr] \\ &= \bigl[ \hat{u}(t_i) + h \hat{u}'(t_i) + \tfrac{1}{2}h^2 \hat{u}''(t_i) + O(h^3) \bigr] - \bigl[ \hat{u}(t_i) + h\hat{u}'(t_i) \bigr] \notag \\ &= \tfrac{1}{2}h^2 \hat{u}''(t_i) + O(h^3), \end{split}

where we used the fact that u^\hat{u} satisfies the differential equation.

We now introduce some formalities.

Euler’s method is the particular case of (6.2.7) with ϕ(t,u,h)=f(t,u)\phi(t,u,h) = f(t,u), but we will see other one-step methods in later sections.

In close analogy with Convergence of finite differences, we define truncation error as the residual of (6.2.7) when the exact solution is inserted.

The following follows immediately from the definitions.

6.2.2Convergence

While the local truncation error is straightforward to calculate from its definition, it is not the quantity we want to know about and control.

At times the term global error may be interpreted as the max-norm of the global error vector, or as its final value.

By our definitions, the local error in stepping from tit_i to ti+1t_{i+1} is hτi+1(h)h\tau_{i+1}(h). To reach the time t=bt=b from t=at=a with step size hh, we need to take n=(ba)/hn=(b-a)/h steps. If we want to reach, say, t=(a+b)/2t=(a+b)/2, then we would have to take n/2n/2 steps, and so on. In fact, to reach any fixed time in the interval, we need to take O(n)=O(h1)O(n)=O(h^{-1}) steps. By expressing the local error with a factor of hh taken out, the LTE τ itself is accounting for the simple accumulation of error caused by taking O(n)O(n) steps.[1]

However, global error is not as simple as a sum of local errors. As explained in Theorem 6.1.2 and illustrated in Demo 6.1.5, each step causes a perturbation of the solution that can grow as tt advances. Thus, we have to account for the flow evolution of individual step truncation errors as well as their mere accumulation. That is the subject of the following theorem.

The theorem justifies one more general definition.

We could restate Theorem 6.2.1 as saying that the global error has the same order of accuracy as the LTE. Note, however, that the O(hp)O(h^p) convergence hides a leading constant that grows exponentially in time. When the time interval is bounded as h0h\to 0, this does not interfere with the conclusion, but the behavior as tt\to\infty contains no such guarantee.

Euler’s method is the ancestor of the two major families of IVP methods presented in this chapter. Before we describe them, though, we generalize the initial-value problem itself in a crucial way.

6.2.3Exercises

  1. ✍ Do two steps of Euler’s method for the following problems using the given step size hh. Then, compute the error using the given exact solution.

    (a) u=2tu, u(0)=2; h=0.1; u^(t)=2et2u' = -2t u, \ u(0) = 2;\ h=0.1;\ \hat{u}(t) = 2e^{-t^2}

    (b) u=u+t, u(0)=2; h=0.2; u^(t)=1t+3etu' = u + t, \ u(0) = 2;\ h=0.2;\ \hat{u}(t) = -1-t+3e^t

    (c) tu+u=1, u(1)=6, h=0.25; u^(t)=1+5/tt u' + u = 1, \ u(1) = 6, \ h = 0.25;\ \hat{u}(t) = 1+5/t

    (d) u2u(1u)=0, u(0)=1/2, h=0.25; u^(t)=1/(1+e2t)u' - 2u(1-u) = 0, \ u(0) = 1/2, \ h = 0.25; \ \hat{u}(t) = 1/(1 + e^{-2t})

  2. ⌨ For each IVP, solve the problem using Function 6.2.2. (i) Plot the solution for n=320n=320. (ii) For n=102kn=10\cdot2^k, k=2,3,,10k=2,3,\ldots,10, compute the error at the final time and make a log-log convergence plot, including a reference line for first-order convergence.

    (a) u=2tu, 0t2, u(0)=2; u^(t)=2et2u' = -2t u, \ 0 \le t \le 2, \ u(0) = 2;\ \hat{u}(t) = 2e^{-t^2}

    (b) u=u+t, 0t1, u(0)=2; u^(t)=1t+3etu' = u + t, \ 0 \le t \le 1, \ u(0) = 2;\ \hat{u}(t) = -1-t+3e^t

    (c) (1+t3)uu=t2, 0xt3, u(0)=1; u^(t)=[1+(2/3)ln(1+xt3)]1/2(1+t^3)uu' = t^2,\ 0 \le xt \le 3, \ u(0) =1;\ \hat{u}(t) = [1+(2/3)\ln (1+xt^3)]^{1/2}

    (d) u2u(1u)=0, 0t2, u(0)=1/2; u^(t)=1/(1+e2t)u' - 2u(1-u) = 0, \ 0 \le t \le 2, \ u(0) = 1/2; \ \hat{u}(t) = 1/(1 + e^{-2t})

    (e) v(1+x2)v=0, 1x3, v(1)=1, v^(x)=e(x3+3x4)/3v' - (1+x^2) v = 0, \ 1 \le x \le 3, \ v(1) = 1, \ \hat{v}(x) = e^{(x^3+3x-4)/3}

    (f) v+(1+x2)v2=0, 0x2, v(0)=2, v^(x)=6/(2x3+6x+3)v' + (1+x^2) v^2 = 0, \ 0 \le x \le 2, \ v(0) = 2, \ \hat{v}(x) = 6/(2x^3+6x+3)

    (g) u=2(1+t)(1+u2), 0t0.5, u(0)=0, u^(t)=tan(2t+t2)u' = 2(1+t)(1+u^2), \ 0 \le t \le 0.5, \ u(0) = 0, \ \hat{u}(t) = \tan(2t + t^2)

  3. ✍ Here is an alternative to Euler’s method:

    vi+1=ui+hf(ti,ui),ui+1=ui+hf(ti+h,vi+1).\begin{split} v_{i+1} &= u_i + h f(t_i,u_i),\\ u_{i+1} &= u_i + hf(t_{i}+h,v_{i+1}). \end{split}

    (a) Write out the method explicitly in the general one-step form (6.2.7) (i.e., clarify what ϕ is for this method).

    (b) Show that the method is consistent.

  4. ✍ Consider the problem u=kuu'=ku, u(0)=1u(0)=1 for constant kk and t>0t>0.

    (a) Find an explicit formula in terms of hh, kk, and ii for the Euler solution uiu_i at t=iht=ih.

    (b) Find values of kk and hh such that ui|u_i|\to\infty as ii\to\infty while the exact solution u^(t)\hat{u}(t) is bounded as tt\to\infty.

  5. ✍ Prove the fact, used in the proof of Theorem 6.2.1, that 1+xex1+x\le e^x for all x0x\ge 0.

  6. ✍ Suppose that the error in making a step is also subject to roundoff error ϵi+1\epsilon_{i+1}, so that the total local error per unit step is Chp+ϵi+1h1Ch^p+\epsilon_{i+1} h^{-1}; assume that ϵi+1ϵ|\epsilon_{i+1}| \le \epsilon for all ii and that the initial condition is known exactly. Generalize Theorem 6.2.1 for this case.

Footnotes
  1. Another point of view is that we can of course make local errors smaller by chopping hh in half, but then we have to take twice as many steps. The important quantity, then, is local error per unit step length, which is how τ is defined.