Math 2280 Section 002 [SPRING 2013] 1 Numerical Approximations

advertisement
MATH 2280-002
Lecture Notes: 01/23/2013
Math 2280 Section 002 [SPRING 2013]
1
Numerical Approximations
The sad truth is that most IVP of the form
dy
= f (x, y), y(x0 ) = y0 ,
dx
cannot be solved exactly or explicitly using elementary techniques. However, we can use three
numerical methods to approximate the solution to an ODE:
1. Euler’s method
2. Improved Euler’s method
3. Runge-Kutta method
We’ll be talking about the first of these methods today.
2
Euler’s Method
IDEA:
Play “connect-the-dots” with the slope field.
You begin at a point (x0 , y0 ) and pick a step size h. To get x1 , start at x0 and slide h units to the
right. To get y1 , follow the line with slope f (x0 , y0 ) passing through (x0 , y0 ) until you reach x1 ;
your y-coordinate will be y1 . Then repeat this process using (x1 , y1 ) as your starting point and find
(x2 , y2 ). Continue.
To apply Euler’s method on
dy
= f (x, y),
dx
y(x0 ) = y0 ,
carry out the following steps:
• Choose step size h.
• Start at (x0 , y0 ).
• Set x1 = x0 + h
(move horizontally h units).
• Set y1 = y0 + h · f (x0 , y0 )
(move vertically h · f (x0 , y0 ) units).
• Continue:
Set xn+1 = xn + h.
Set yn+1 = yn + h · f (xn , yn ).
This sort of algorithm is ideal for computers, but let’s work out an example by hand.
1
MATH 2280-002
Lecture Notes: 01/23/2013
Example. Use Euler’s Method with step size 0.2 to approximate the graph of the solution to
y 0 = y,
y(0) = 1
on the interval [0, 1]. Notice that we can solve this IVP (using separation of variables) to get that
y = ex . This will allow us to compare our approximation with the actual solution and judge how
effective Euler’s method is. Using .2 as our step size, we split [0,1] into 5 pieces (since 1−0
.2 = 5).
In other words, it will take 5 steps of our algorithm to compute our approximation.
I carry out each step of Euler’s method below. The red curve is the actual solution, and the blue
curve is our approximation.
STEP 1
x0 = 0
y0 = 1
x1 = 0 + .2 = .2
y1 = 1 + .2(1) = 1.2
STEP 2
x0 = 0
y0 = 1
x1 = .2
y1 = 1.2
x2 = .2 + .2 = .4
y2 = 1.2 + .2(1.2) = 1.44
2
MATH 2280-002
Lecture Notes: 01/23/2013
STEP 3
x0 = 0
y0 = 1
x1 = .2
y1 = 1.2
x2 = .4
y2 = 1.44
x3 = .4 + .2 = .6
y3 = 1.44 + .2(1.44) = 1.728
STEP 4
x0 = 0
y0 = 1
x1 = .2
y1 = 1.2
x2 = .4
y2 = 1.44
x3 = .6
y3 = 1.728
x4 = .6 + .2 = .8
y4 = 1.728 + .2(1.728) = 2.0736
STEP 5
x0 = 0
y0 = 1
x1 = .2
y1 = 1.2
x2 = .4
y2 = 1.44
x3 = .6
y3 = 1.728
x4 = .8
y4 = 2.0736
x5 = .8 + .2 = 1
y5 = 2.0736 + .2(2.0736) = 2.48832
3
MATH 2280-002
3
Lecture Notes: 01/23/2013
Errors
Euler’s method is less accurate for solutions with high curvature, leading to either an overestimation
or an underestimation.
CONCAVE UP
CONCAVE DOWN
underestimation
overestimation
One thing we notice about our example is that, the farther away we got from the point (x0 , y0 ), the
worse our approximation got. This is because the errors are cumulative in Euler’s method. Any error
introduced during the process will affect all later computations.
Question. What can we do to get a better approximation?
One thing we can do to improve our results is to choose a smaller step size. Next time we’ll modify
our algorithm itself to better accomodate solutions with high curvature.
4
Download