8.5 Euler's Method: 8.5.1 Example

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Lecture Notes MA5470 Numerical Analysis 73

for some nearby point ξ. We say that the local truncation error is O(∆tn+1 ). An error of
this sort is present in each step of the numerical solution. The accumulation of all the many
local truncation errors gives rise to the global truncation error. Similarly, the global roundoff
error is the accumulation of local roundoff errors in prior steps. The total error is the sum
of the global truncation error and the global roundoff error. If the global truncation error is
O(∆tn ), we say that the numerical procedure is of order n.

8.5 Euler’s Method


The Taylor-series method with n = 1 is the Euler’s method. It looks like this:

∆t2 (2)
x(t + ∆t) = x(t) + ∆t f (t, x) + x (ξ)
2!
xi+1 = xi + ∆t fi (8.7)

where xi = x(ti ) and fi = f (ti , xi ).


(Notation : x(ti ) is the exact value of x at ti , xi is the corresponding numerically computed
value of x at ti .)
This formula doesn’t require any additional derivatives than required by the existence of the
solution. However, this advantage is offset by the necessity of taking small values of step
length ∆x to gain acceptable precision. Still, the method serves as a useful example and is
of great importance theoretically because existence theorems can be based on it.

8.5.1 Example
Using Euler’s formula xi+1 = xi +∆t fi approximate the solution of x′ = x−t2 +1, x(0) = 0.5.
at t = 2

Solution : Let us fix the step length ∆t = 0.5.

x0 = x(0.0) = 0.5
x1 = x(0.5) = x0 + ∆t(x0 − t20 + 1) = 0.5 + .5(.5 − 02 + 1) = 1.25
x2 = x(1.0) = x1 + ∆t(x1 − t21 + 1) = 1.25 + .5(1.25 − .52 + 1) = 2.25
x3 = x(1.5) = x2 + ∆t(x2 − t22 + 1) = 2.25 + .5(2.25 − 1.02 + 1) = 3.375
x4 = x(2.0) = x3 + ∆t(x3 − t23 + 1) = 3.375 + .5(3.375 − 1.52 + 1) = 4.4375

If the step length ∆t is changed to 0.2, and the Eulers method is repeated, the value of x(2)
becomes 4.8657845 with the error 0.4396874 as the exact value is 5.3054720.

8.5.2 Error bound for Euler method


Taylor series with n = 1 will give one error bound. Another sharper bound can be obtained
using the following results
74 Sanyasiraju V S S Yedida [email protected]

Lemma 1
For all x ≥ 1 and any positive m, we have 0 ≤ (1 + x)m ≤ emx .

Proof
Applying the Taylors Theorem with f (x) = ex , x0 = 0, and n = 1 gives
x2 ξ
ex = 1 + x + e
2
2
where ξ is between x and zero. Thus 0 ≤ 1 + x ≤ 1 + x + x2 eξ = ex , and, because 1 + x ≥ 0, we
have
0 ≤ (1 + x)m ≤ (ex )m = emx

Lemma 2
If s and t are positive real numbers, {ai }ki=0 is a sequence satisfying a0 ≥ − st , and

ai+1 ≤ (1 + s)ai + t

for each i = 0, 1, 2, ⋯, k − 1 then


t t
ai+1 ≤ e(i+1)s (a0 + ) −
s s

Proof
For a fixed integer i, the given inequality implies that

ai+1 ≤ (1 + s)ai + t
≤ (1 + s) ((1 + s)ai−1 + t) + t = (1 + s)2 ai−1 + (1 + (1 + s)) t
≤ (1 + s)3 ai−2 + (1 + (1 + s) + (1 + s)2 ) t
..
.
≤ (1 + s)i+1 a0 + (1 + (1 + s) + (1 + s)2 + ⋯ + (1 + s)i ) t
i
1 − (1 + s)i+1
= (1 + s)i+1 a0 + ∑(1 + s)j t = (1 + s)i+1 a0 + t
j=0 1 − (1 + s)

Therefore,
(1 + s)i+1 − 1 t t
ai+1 ≤ (1 + s)i+1 a0 + t = (1 + s)i+1 (a0 + ) −
s s s
Now using the Lemma 8.5.2 with x = 1 + s gives
t t
ai+1 ≤ e(i+1)s (a0 + ) −
s s
Lecture Notes MA5470 Numerical Analysis 75

Error in the Euler’s formula


Suppose f is continuous and satisfies a Lipschitz condition with constant L on D = {(t, x)∣, a ≤
t ≤ b and − ∞ < x < ∞} and that a constant M exists with x(2) ≤ M for all t ∈ [a, b], where
x(t) denotes the unique solution to the initial-value problem x′ = f (t, x), a ≤ t ≤ b, x(a) = α.
Let x0 , x1 , ⋯, xn be the approximations generated by Eulers method for some positive integer
n. Then, for each i = 0, 1, 2, ⋯, n,
∆tM L(ti −a)
∣x(ti ) − xi ∣ ≤ (e − 1) (8.8)
2L

Proof
When i = 0 the result is clearly true, since x(t0 ) = x0 = α. From the Taylor theorem, we have
∆t2 (2)
x(ti+1 ) = x(ti ) + ∆tf (ti , x(ti )) + x (ξ)
2
for i = 0, 1, ⋯, n − 1, and from the Euler’s formula,
xi+1 = xi + ∆tf (ti , xi )
Therefore,
∆t2 (2)
x(ti+1 ) − xi+1 = x(ti ) − xi + ∆t[f (ti , x(ti )) − f (ti , xi )] + x (ξ)
2
Hence
∆t2 (2)
∣x (ξ)∣
∣x(ti+1 ) − xi+1 ∣ ≤ ∣x(ti ) − xi ∣ + ∆t∣[f (ti , x(ti )) − f (ti , xi )]∣ +
2
Now f satisfies a Lipschitz condition in the second variable with constant L, and
∆t2 M
∣x(ti+1 ) − xi+1 ∣ ≤ (1 + ∆t L) ∣x(ti ) − xi ∣ +
2
∆t2 M
Referring to Lemma 2 and letting ai = ∣x(ti ) − xi ∣, s = ∆t L, t = 2 , we have,
∆t2 M ∆t2 M
∣x(ti+1 ) − xi+1 ∣ ≤ e(i+1)∆tL (∣x(t0 ) − x0 ∣ + )−
2∆tL 2∆tL
Because ∣x(t0 ) − x0 ∣ = 0 and (i + 1)∆t = ti+1 − t0 = ti+1 − a, this implies that
∆tM L(ti −a)
∣x(ti ) − xi ∣ ≤ (e − 1)
2L
for each i = 0, 1, ⋯, n − 1.

The weakness of the above result is the requirement that a bound be known for the sec-
ond derivative of the solution. Although this condition often prohibits us from obtaining a
realistic error bound, it should be noted that if ∂f ∂f
∂t and ∂x both exist, then the chain rule for
partial differentiation implies that
dx′ d ∂f ∂f
x(2) (t) = (t, x(t)) = f (t, x(t)) = + (t, x(t)) . f (t, x(t))
dt dt ∂t ∂x
Therefore, some times it is possible to obtain an error bound for x(2) (t) without explicitly
knowing x(t).
76 Sanyasiraju V S S Yedida [email protected]

Example
The solution to the initial-value problem x′ = x−t2 +1, 0 ≤ t ≤ 2, x(0) = 0.5, was approximated
in 8.5.1 using Eulers method with ∆t = 0.2. Use the error formula (8.8) to find a bounds for
the approximation errors and compare them with the actual errors.

Solution
Because f (t, x) = x − t2 + 1, we have ∂x (t, x)
∂f
= 1 for all x, so L = 1.

The exact solution is x(t) = (t + 1)2 − 0.5et ,


therefore, x(2) (t) = 2 − 0.5et and ∣x(2) (t)∣ ≤ 0.5e2 − 2, for all t ∈ [0, 2].

ti 0.2 0.4 0.6 1.0 1.2 1.4 1.6 1.8 2.0


Actual error 0.02930 0.06209 0.09854 0.18268 0.23013 0.28063 0.33336 0.38702 0.43969
Error bound 0.03752 0.08334 0.13931 0.29117 0.39315 0.51771 0.66985 0.85568 1.08264

Bound for the step length ∆t


Let x(t) denote the unique solution to the IVP x′ = f (t, x), a ≤ t ≤ b, x(a) = α and x0 , x1 , ⋯,
xn be the approximations obtained using the Euler formula. If ∣δi < δ for each i = 0, 1, ⋯, n
and the error bound (8.8) is valid then

1 ∆tM δ
∣x(ti ) − xi ∣ ≤ ( + ) (eL(ti −a) − 1) + ∣δ0 ∣eL(ti −a) (8.9)
L 2 ∆t

for each i = 0, 1, ⋯, n. The error bound (8.5.2) is no longer linear in ∆t. In fact, since
limit ∆t tends zero, as ( ∆tM )
2 + ∆t tends to ∞, the error would expected to become large
δ

for sufficiently small values of ∆t. Calculus can be used to determine a lower bound for the
step size ∆t. Letting E(∆t) = ( ∆tM ) ′
2 + ∆t implies that E = 2 − ∆t2 .
δ M δ


• If ∆t < 2δ
M, then E ′ (∆t) < 0 and E(∆t) is decreasing.

• If ∆t > 2δ
M, then E ′ (∆t) > 0 and E(∆t) is increasing.

The minimal value of E(∆t) occurs when




∆t = (8.10)
M

Decreasing ∆t beyond this value tends to increase the total error in the approximation.
Normally, however, the value of δ is sufficiently small that this lower bound for ∆t does not
affect the operation of Eulers method.
Lecture Notes MA5470 Numerical Analysis 77

8.5.3 Problems
1. Use Eulers method to approximate the solutions for each of the following initial-value
problems. Also compare the actual error with error bound

(a) x′ = te3t − 2x, 0 ≤ t ≤ 1, x(0) = 0, with ∆t = 0.5 (Exact solution : x(t) = 51 te3t −
−2t )
25 e + 25 te
1 3t 1

(b) x′ = 1 + (t − x)2 , 2 ≤ t ≤ 3, x(2) = 1, with ∆t = 0.5 (Exact solution : x(t) = t + 1−t


1
)
(c) x′ = 1 + xt , 1 ≤ t ≤ 2, x(1) = 2, with ∆t = 0.25 (Exact solution : x(t) = t ln(t) + 2t)
(d) x′ = cos 2t + sin 3t, 0 ≤ t ≤ 1, x(0) = 1, with ∆t = 0.25 (Exact solution : x(t) =
2 sin 2t − 3 cos 3t + 3 )
1 1 4

(e) x′ = et−x , 0 ≤ t ≤ 1, x(0) = 1, with ∆t = 0.5 (Exact solution : x(t) = ln(et + e − 1))

(f) x′ = 1+x
1+t
, 1 ≤ t ≤ 2, x(1) = 2, with ∆t = 0.5 (Exact solution : x(t) = t2 + 2t + 6 − 1)

(g) x′ = −x + t x, 2 ≤ t ≤ 3, x(2) = 2, with ∆t = 0.25 (Exact solution : x(t) =

(t − 2 + 2e e−t/2 ) )
2

(h) x′ = sin 2t−2tx


t2 , 2 ≤ t ≤ 3, x(2) = 2, with ∆t = 0.25 (Exact solution : x(t) = 21 sin 2t −
3 cos 3t + 3 )
1 4

2. Given the IVP x′ = x + t + 1, 0 ≤ t ≤ 5, x(0) = 1, with exact solution x(t) = et + t.


Approximate x(2) using Eulers method with ∆t = 0.5. Also determine the optimal
value of ∆t to use in computing x(2), assuming δ = 10−6 and that (8.10) is valid.

8.5.4 Delay Differential Equations


Delay differential equation is a differential equation with retarded argument. It arises in
some practical problems like population models and mixing problems often have this special
feature, which is that the value of x′ (t) is related to values of the function x at previous
values of t. For example,

x′ (t) = f (x(t − 1)), not x × (t − 1)

If we know the value of x at t1, the differential equation enables us to compute the value
of x′ (t). To integrate the differential equation starting at t = 0, we shall need the history of
x(t) starting at t = −1. Thus, the values of x(t) on the interval t ∈ [−1, 0] will have to be
supplied to us as initial values. An example of a specific and well-defined problem of this
type is

Numerical Illustration
Consider

x(t + ∆t) = x(t − 1), t ≥ 0, x(t) = t2 for − 1 ≤ t ≤ 0


78 Sanyasiraju V S S Yedida [email protected]

The second of these equations gives the needed initial values for x(t). If t is restricted to
the interval [0, 1], then t − 1 is in [−1, 0], and hence

x(t + ∆t) = x(t − 1) = (t − 1)2 , 0 ≤ t ≤ 1


x(0) = 0

This has the solution


1 1
x(t) = (t − 1)3 + , (0 ≤ t ≤ 1)
3 3
If the solution is to be continued into the next interval [1, 2], another step like the first can
be taken. Thus, for t in [1, 2], we have

1 1
x(t + ∆t) = x(t − 1) = (t − 2)3 + , 0 ≤ t ≤ 1
3 3
1
x(1) =
3

This has the solution


1 1 1
x(t) = (t − 2)4 + t − , (1 ≤ t ≤ 2)
2 3 12
The solution can be continued indefinitely to the right by similar calculations. For more
complicated equations, such as, x(t) = sin[x(t−1)3 ]+log[x(t)+t5 ]. The Taylor-series method
is complicated to such problems due to the determination of the derivatives. Consider, for
example,

x′ = 2x(t − 1) + x(t), t ≥ 0,
x(t) = t2 for − 1 ≤ t ≤ 0

To compute the solution on the interval [0, 1], assume we wish to use the Taylor series, with
step length ∆t, given by

∆t2 ′′ ∆t3 (3)


x(t + ∆t) = x(t) + ∆t x′ (t) + x (t) + x (t)
2 6

This formula requires

x′ = 2x(t − 1) + x(t) = 2(t − 1)2 + x(t)


x(2) = 2x′ (t − 1) + x′ (t) = 4(t − 2)2 + 2(t − 1)2 + x′ (t)
x(3) = 2x(2) (t − 1) + x(2) (t) = 8(t − 3)2 + 8(t − 2)2 + 2(t − 1)2 + x(2) (t)

The numerical solution produces values of x(t) at discrete points in the interval [0, 1]. At
the same time, we should store the values of x′ (t), x(2) (t), and x(3) (t) at these same discrete
points for use in the next interval. If we do not change the value of ∆t, we can proceed in
each interval in the same way using the appropriate saved values.
Lecture Notes MA5470 Numerical Analysis 79

8.5.5 Problems

1. Verify that the function x(t) = t4 solves the initial-value problem x′ = x, x(0) = 0.
2

Apply Taylor series method of order 1 and explain why the numerical solution differs
2
from the solution t4 .

2. Compute x(0.1) by solving the differential equation x′ = −tx2 , x(0) = 2 with the Taylor-
series method of order 2.

3. Compute x(0.01) by solving the differential equation x′ = x2 xet , x(0) = 1 with the
Taylor-series method of order 3.

4. Compute x(4.1) by solving the differential equation 5tx′ + x2 = 2, x(4) = 1 with the
Taylor-series method of order 2.

5. Apply the Taylor series method of orders (a) two and (b) four with number of points
as 5 to the IVP x′ = x − t2 + 1, 0 ≤ t ≤ 2, x(0) = 0.5.

You might also like