Professional Documents
Culture Documents
Reference
James F. Epperson (Revised Edition, 2007) - Chapter 6
Content
6.1 Introduction 6.2 Eulers Method 6.3 Mid-Point Method 6.4 Higher-Order Methods 6.5 Runge-Kutta Methods 6.6 Multistep Methods 6.7 System of ODEs
SEMESTER 1 2011/2012
6.1 Introduction Initial value problem (IVB) for ordinary differential equations (ODE). Say y = y (x ) . A first order ODE of y w.r.t. x is defined at an interval x [x0 , x n ] :
y = dy = f (x , y (x )), dx y (x 0 ) = y 0 .
(6.1)
For example: y' = f (x , y ) = 1 xy , y (0) = 0 or y' = f (x , y ) = 1 y , y (0) = 0 or y' = f (x , y ) = 1 x , y (0) = 0 . We want to find the unknown function y (x ) that solves the ODE (6.1) for all x > x0 and y (x 0 ) = y 0 .
6.2 Eulers Method To derive Eulers formula we use Taylors Theorem. Divide the interval of interest into n subintervals: x0 , x1 = x0 + h,K , x n = x n 1 + h At any point xi +1 = xi + h :
y (x i + h ) = y (x i ) + hy i ' (x i ) + 1 2 h yi" ( ) 2 1 = y (x i ) + hf (x i , y (x i )) + h 2 y i " ( ) 2
for some between xi and x i + h . We write in the form that is suitable for programming:
y i +1 = y i + hf (x i , y i ) + 1 2 h y i " ( ) . 2
(6.2)
Residual,
R (x , h ) = 1 2 h y i " ( ) . 2
SEMESTER 1 2011/2012
( )
Example 6.1 (JE Chapter 6 Example 6.6, page 331) Given y' + y = 1, Solution: Step 1
y' = f ( x , y ) = 1 y
From (6.2), the Eulers formula is
y i +1 = y i + hf (x i , y i ) = y i + h(1 y i )
Step 2 Choose step size h. Let us use h = 0.1 i.e. n = 10 . Step 3 Tabulate the results.
i +1
x i +1
y i +1
0 0+1 = 1 2 3 4 5 6 7 8 9 10
x0 = 0.0 y 0 = 0.0 Output from Eulers program y 1 = y 0 + h(1 y 0 ) = 0 + 0.1(1 0 ) x1 = x0 + h = 0.0 + 0.1
x 4 = 0.4000000 x 5 = 0.5000000
x 6 = 0.6000000
y 4 = 0.3439000 y 5 = 0.4095100
y 6 = 0.4685590
x7 = 0.7000000 x 8 = 0.8000001
x 9 = 0.9000001 x10 = 1.0000001
y 7 = 0.5217031 y 8 = 0.5695328
y 9 = 0.6125795 y 10 = 0.6513216
SEMESTER 1 2011/2012
Exact solution:
y ' = 1 y
dy =0 1 y = dx 0 y0 ln y
y y 0 =0
=x
x 0
y i +1 = y i + hf (x i +1 , y i +1 ) .
(6.3)
Equation (6.3) is an implicit method as opposed to (6.2) which is an explicit method. Solve (6.3) with Newtons method for nonlinear equations (Chapter 4). Eulers methods (forward or backward) are single-step methods. Algorithm 6.1 Given y 0 = initial value, x 0 = initial point, xn = final point, n = number of points.
h= x n x0 n
end
6.3 Mid-Point Method Main source of error in Eulers method is the usage of the derivative in the entire interval of interest. Mid-point or improved polygon method addresses this problem by using the derivative at the mid-point of the interval.
SEMESTER 1 2011/2012
Calculate y at mid-point:
y i + 1 = y i + f (x i , y i )
2
h . 2
(6.4)
)
)
(6.5)
(6.6)
6.4 Higher-Order Methods Eulers method is straight forward to implement but not accurate. Alternatively use higher-order Taylor expansion. But this requires more function evaluation (work) per step. For example, second-order Taylor expansion: y (x + h ) y (x ) + hy (x , y ) + h2 y (x , y ) 2 h2 y (x ) + hf (x , y ) + f (x , y ) 2
6.5 Runge-Kutta Methods Single-step methods. Widely used ODE solver. Expand Taylor series to higher orders: y (x + h ) = y (t ) + hy' (x ) + Second order method: y (x + h ) y (x ) + hy (x ) + h2 y (x ) . 2 h2 h3 y" (x ) + y (x ) + ... 2 6
SEMESTER 1 2011/2012
or y i +1 = y i + hy i + h2 y i . 2
(*)
f (x + h, y + hf ) f (x , y ) . h = y
( )
(**)
y i +1 = y i + hf (xi , y i ) +
(6.7)
where K1 = f (xi , y i ) and K 2 = f (xi + h, y i + hf (xi , y i )) . Equation (6.7) Runge-Kutta Order 2 (RK2) or Heuns method.
Example 6.3 (MH Chapter 9 Example 9.12, page 405) Given f = y' = 2xy 2 , y (0) = 1, x [0,0.5]. Use h = 0.25 . Solution: Tabulate the results.
SEMESTER 1 2011/2012
xi
x0 = 0 0.25 0.50
K1
0 -0.4395
K2
-0.5000 -0.6850
y i +1
y0 = 1 0.9375 0.7969
0 1 2 Exact solution: y (x ) =
1 1+ x 2
6.6 Multistep Methods Euler, RK are single-step methods. In the multistep methods, we need information more than the previous point to estimate the solution at the next point. Strategy: 1. Use single step methods to generate approximation at enough points to begin multistep method. 2. A good guess is suggested by an explicit method. 3. Then an implicit method used to solve y k +1 Hence explicit and implicit pair is called predictor corrector pair: a) Adam-Bashforth Predictor (explicit fourth-order) h y i +1 = y i + 55 y i' 59 y i' 1 + 37 y i' 2 9 y i' 3 . 24 b) Adam-Moulton Corrector (implicit fourth-order)
SEMESTER 1 2011/2012
y i +1 = y i +
Appilcation of Eulers method (Equation (6.2)) for solving a system of ODEs. Say we have two ODEs:
dy = f1 (x , y , z ) dx dz = f2 ( x , y , z ) dx
(6.9)
(6.10)
for x [a, b] , intial conditions: y (a ) = y 1 z(a ) = z1 and with y and z as the dependent variables and x as the independent variables. Using Eulers method (Equation (6.2)), the recursion relations to solve (6.9) and (6.10) simultaneously are:
xi +1 = xi + h
y i +1 = y i + hf1 (x i , y i , zi ) zi +1 = zi + hf2 (x i , y i , zi )
Example 6.5 (JE Chapter 6 Exercise 1(a), page 379) Given h = 1 4 . y 1 = 4 y 1 + y 2 , y 1 (0 ) = 1 y 2 = y 1 4 y 2 , y 2 (0 ) = 1 Solution: Step 1 According to Equations (6.12) and (6.13), y 1 = y and y 2 = z . The recursion relations are:
xi +1 = xi + h
y 1,i +1 = y 1,i + h y 1 (x i , y 1,i , y 2 ,i )
SEMESTER 1 2011/2012
y 2 ,i +1 = y 2 ,i + hy 2 (x i , y 1,i , y 2 ,i )
Step 2
i =0
x1 = x0 + h = 0 + 0.25 = 0.25
y 1,1 = y 1,0 + h y 1 (x 0 , y 1,0 , y 2 ,0 ) = 1 + 0 .25 y 1 (0,1,1) = 1 + 0 .25 ( 4 1) = 1 1.25 = 0 .25