Use the Euler formula to compute the numerical solution of \dot{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 \dot{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)=A e^{\lambda t}. Substitution of this assumed form into the equation \dot{x}=-3 x yields A \lambda e^{\lambda t}=-3 A e^{\lambda t }, or \lambda=-3, so that the solution is of the form x(t)=A e^{-3 t}. Applying the initial conditions x(0)=1 yields A=1. Hence the analytical solution is simply x(t)=e^{-3 t}.
Next, consider a numerical solution using the Euler method suggested by equation (1.91). In this case the constant a=-3, so that x_{i+1}=x_i+\Delta t\left(-3 x_i\right). Suppose that a very crude time step is taken (i.e., \Delta 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):
x_{i+1}=x_i+\Delta t\left(a x_i\right) (1.91)
\begin{aligned} & x_0=1 \\ & x_1=x_0+(0.5)(-3)\left(x_0\right)=-0.5 \\ & x_2=-0.5-(1.5)(-0.5)=0.25\\&\qquad\vdots \end{aligned}
forms the column marked “Euler.” The column marked “Exact” is the value of e^{-3 t} 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 \Delta 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 \Delta t=0.1. Note that it looks very much like the exact solution x(t)=e^{-3 t}.