An example of the Euler method

advertisement
Numerical differentiation - Euler’s Method
An example of the Euler method
For the first numerical example we will choose a problem to which
we know the answer. The initial value problem described by
y 0 = 1 − 2xy
y(0) = 0
has a solution
y(x) = e−x
2
Z x
0
(1)
2
exp−t dt
(2)
which is known as Dawson’s Integral. Here we solve Equation(1)
numerically and see how the values compare with the analytic solutions.
Using Euler’s method the values of y(x) are tabulated for x ∈
[0, 0.5], with h = 0.1. Recall the Euler formula
yn+1 = yn + hf (x, y)
and f (x, y) in this problem is 1 − 2xy.
y1 =
=
=
y2 =
=
=
y0 + 0.1f (x0, y0)
0 + 0.1(1 − 2(0)(0))
0.1
y1 + hf (x1, y1)
0.1 + 0.1(1 − 2(0.1)(0.1))
0.198
and so on until x = 0.5 ie. 5 steps. Comparing these numerical
results with the analytic ones (got by substituting in Equation(2))
gives the table
xn
0.0
0.1
0.2
0.3
0.4
0.5
yn
y(xn )
(numerical result) (analytic result)
0.00000
0.00000
0.10000
0.09934
0.19800
0.19475
0.29008
0.28263
0.37268
0.35994
0.44287
0.42444
Download