Math 2280 Section 002 [SPRING 2013] 1 Numerical Approximations

advertisement
MATH 2280-002
Lecture Notes: 01/24/2013
Math 2280 Section 002 [SPRING 2013]
1
Numerical Approximations
Let F be an antiderivative Rof a function f . In calculus, if I wanted to calculate F (xn ) given F (x0 ),
x
I would compute F (x0 ) + x0n f (x)dx since, by the fundamental theorem of calculus,
Z
xn
f (x)dx = F (x0 ) + (F (xn ) − F (x0 )) = F (xn ).
F (x0 ) +
x0
Rx
Now remember that x0n f (x)dx is the area between f (x) and the x-axis, from x0 to xn . I can
estimate this area using Riemann sums. I have several choices for Riemann sums – rectangular rule,
trapezoidal rule, or Simpson’s rule. Trapezoidal rule does a better job of approximating the area
under the curve than rectangular rule, but Simpson’s rule performs the best of all three. As the
lengths
R xn of the subintervals of [x0 , xn ] for your Riemann sum go to 0, your Riemann sum converges
to x0 f (x)dx, regardless of the rule you choose.
The three numerical methods we’ll learn to estimate the solution to
dy
= f (x, y),
dx
y(x0 ) = y0 .
are essentially just the three ways we learnt how to calculate Riemann sums back in calculus. Euler’s
method is just left rectangular rule. Improved Euler’s method is just trapezoidal rule, and finally,
the Runge-Kutta method is just Simpson’s rule.
2
Improved Euler’s Method
IDEA:
Average slope to reduce errors in estimation.
Just as in Euler’s method 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 a certain slope k passing through
(x0 , y0 ) until you reach x1 ; your y-coordinate will be y1 . What’s new about this method is how we
pick k. In Euler’s method, we just chose k to be f (x0 , y0 ). In improved Euler’s method, we get k
by averaging the slope at (x0 , y0 ) and at the point returned by Euler’s method.
To apply improved Euler’s method on
dy
= f (x, y),
dx
y(x0 ) = y0 .
carry out the following steps:
Choose a step size h and start at the point (x0 , y0 ).
Set k1 = f (x0 , y0 ) = slope at (x0 , y0 ).
Set x1 = x0 + h = next x-coordinate given by Euler’s method
Set u1 = y0 + h · k1 = next y-coordinate given by Euler’s method.
1
MATH 2280-002
Lecture Notes: 01/24/2013
Set k2 = f (x1 , u1 ) = slope at (x1 , u1 ).
Set k = 21 (k1 + k2 ) = average of slopes.
Set y1 = y0 + h · k.
Continue.
Euler’s method would return (x1 , u1 ) as the next point on our graph, but the improved Euler’s
method returns (x1 , y1 ) instead. By adding some additional steps to our algorithm, we’ll see much
better results.
3
Runge-Kutta Method
IDEA:
Use weighted average of slopes to reduce errors.
We’ll take the idea of using an average of slopes and improve on it by computing “midpoint” slopes
and giving them more weight in the average.
To apply improved Euler’s method on
dy
= f (x, y),
dx
y(x0 ) = y0 .
carry out the following steps:
Choose a step size h and start at (x0 , y0 ).
Set k1 = f (x0 , y0 )
Set k2 = f (x0 + h2 , y0 + h2 k1 )
Set k3 = f (x0 + h2 , y0 + h2 k2 )
Set k4 = f (x0 + h, y0 + h · k3 )
Set k = 61 (k1 + 2k2 + 2k3 + k4 )
Set x1 = x0 + h
Set y1 = y0 + h · k
Runge-Kutta returns (x1 , y1 ) as the next point on our graph; now we just continue with the new
starting point (x1 , y1 ).
4
An Example
In the following example, we’ll use all three methods with the same step size to approximate the
solution to the same IVP. Pay attention to how much better each consecutive method approximates
the value of the solution at x = 1.625.
2
MATH 2280-002
Lecture Notes: 01/24/2013
Example. Use Euler’s Method with step size 0.625 to approximate the graph of the solution to
y 0 = y + x4 ,
y(1) = 1.
We can solve this linear DE exactly either using integrating factors (and integration by parts) or
Maple.
EULER’S METHOD
y 0 = y + x4 ,
y(1) = 1
Step Size: h = .625
x0 = 1
y0 = 1
k = f (x0 , y0 ) = 1 + 14 = 2
x1 = 1 + .625 = 1.625
y1 = 1 + .625(2) = 2.25
y(1.625) = 4.47977 (actual value)
IMPROVED EULER’S METHOD
y 0 = y + x4 ,
y(1) = 1
Step Size: h = .625
x0 = 1
y0 = 1
x1 = 1 + .625 = 1.625
k1 = f (1, 1) = 1 + 14 = 2
u1 = 1 + .625 · 2 = 2.25
k2 = f (1.625, 2.25) = 2.25 + 1.6254
= 9.2229
k = 21 (2 + 9.2229) = 5.61145
y1 = 1 + .625(5.61145) = 4.50716
y(1.625) = 4.47977 (actual value)
3
MATH 2280-002
Lecture Notes: 01/24/2013
RUNGE-KUTTA METHOD
y 0 = y + x4 ,
y(1) = 1
Step Size: h = .625
x0 = 1
y0 = 1
k1 = f (1, 1) = 1 + 14 = 2
k2 = f (1 + .625
, 1 + .625
k1 )
2
2
= 1.625 + 1.31254 = 4.59254
k3 = f (1 + .625
, 1 + .625
k2 ) = 5.40271
2
2
k4 = f (1 + .625, 1 + .625k3 ) = 11.3496
k = 61 (k1 + 2k2 + 2k3 + k4 ) = 5.55669
x1 = 1 + .625 = 1.625
y1 = 1 + .625(5.55669) = 4.47293
y(1.625) = 4.47977 (actual value)
4
Download