Use the Euler formula to compute the numerical solution of x˙ = -3x, x(0) = 1 for various time increments in the time interval 0 to 4, and compare the results to the exact solution.
Table 1.4 Comparison of the Exact Solution of x˙ = -3x, x(0) = 1 to the Solution Obtained by the Euler Method with Large Time Step (Δt = 0.5) for the Interval t = 0 to 4 | ||||
Index | Elapsed
time |
Exact | Euler | Absolute
error |
0 | 0 | 1.0000 | 1.0000 | 0 |
1 | 0.5000 | 0.2231 | -0.5000 | 0.7231 |
2 | 1.0000 | 0.0498 | 0.2500 | 0.2002 |
3 | 1.5000 | 0.0111 | -0.1250 | 0.1361 |
4 | 2.0000 | 0.0025 | 0.0625 | 0.0600 |
5 | 2.5000 | 0.0006 | -0.0312 | 0.0318 |
6 | 3.0000 | 0.0001 | 0.0156 | 0.0155 |
7 | 3.5000 | 0.0000 | -0.0078 | 0.0078 |
8 | 4.0000 | 0.0000 | 0.0039 | 0.0039 |
Solution First, the exact solution can be obtained by direct integration or by assuming a solution of the form x(t)=Aeλt. Substitution of this assumed form into the equation x˙=−3x yields Aλeλt=−3Aeλt, or λ=−3, so that the solution is of the form x(t)=Ae−3t. Applying the initial conditions x(0)=1 yields A=1. Hence the analytical solution is simply x(t)=e−3t.
Next, consider a numerical solution using the Euler method suggested by equation (1.91). In this case the constant a=−3, so that xi+1=xi+Δt(−3xi). Suppose that a very crude time step is taken (i.e., Δt=0.5 ) and the solution is formed over the interval from t=0 to t=4. Then Table 1.4 illustrates the values obtained from equation (1.91):
xi+1=xi+Δt(axi) (1.91)
x0=1x1=x0+(0.5)(−3)(x0)=−0.5x2=−0.5−(1.5)(−0.5)=0.25⋮
forms the column marked “Euler.” The column marked “Exact” is the value of e−3t at the indicated elapsed time for a given index. Note that while the Euler approximation gets close to the correct final value, this value oscillates around zero while the exact value does not. This points out a possible source of error in a numerical solution. On the other hand, if Δt is taken to be very small, the difference between the solution obtained by the Euler equation and the exact solution becomes hard to see, as Figure 1.41 illustrates. Figure 1.41 is a plot of x(t) obtained via the Euler formula for Δt=0.1. Note that it looks very much like the exact solution x(t)=e−3t.