Beruflich Dokumente
Kultur Dokumente
GENERAL CONSIDERATIONS
The modelling of unsteady-state processes often lead to ODEs with time as the independent variable. In other cases, the independent variable may be a spatial co-ordinate as in the steady-state treatment of tubular or columnal systems such as plug flow and trickle-bed reactors, packed adsorption and absorption towers or even tubular heat exchangers. In general, for an nth order ODE, n conditions are needed to completely solve the problem. If ALL these n specifications are provided at the same value of the independent variable, say, t or x, for all dependent variables, then the ODE is said to be an INITIAL VALUE PROBLEM. While this may imply that the value of t or x is supposed to be the starting point in the system (e.g. t=0 or x=0), there is no mathematical incongruity if the value of t or x is the endpoint or some other physically admissible point in the independent variable range.
Prof. A.A. Adesina, ChSE, UNSW 2
(7 .1 )
at x = x0
y = y0
OR
y ( x0 ) = y0
The Euler method, one of the earliest techniques for solving ODE stipulates that, if we can represent the LHS of Eqn (7.1) by its first forward finite difference, then at any position, i, we have,
(7.2)
but from our previous discussion on finite difference operators, we can write, (7.3)
3
Euler methods
Euler assumed a truncation of the series in Eqn (7.3) after the 1st term, thus,
y i = hD y i + O ( h 2 ) y i +1 = y i + hD y i + O ( h 2 )
(7.4) (7 .5 )
yi +1 = yi + hf ( xi , yi ) + O ( h 2 )
(7.6)
It is evident that this method is only marginally accurate since the error is of order h2.
Prof. A.A. Adesina, ChSE, UNSW 4
Euler methods
If we use the backward finite difference approximation, we can write,
yi = yi +1 yi = yi +1
(7.7)
h 2 D 2 yi +1 h 3 D 3 yi +1 yi +1 = hDyi +1 + ............. 2 6 so that combining with Eqns (7.1) & (7.2) we secure, yi +1 = yi + hf ( xi +1 , yi +1 ) + O ( h 2 )
Prof. A.A. Adesina, ChSE, UNSW
(7.9)
(7.10)
5
Euler methods
Eqn (7.10) is commonly called the implicit Euler method because it involves the calculation of the function, f, at the unknown value of yi+1. We observe that the error in Eqn (7.10) is also of the order of h2. In principle, implicit equations cannot be solved individually but must be set up as sets simultaneous algebraic equations. If these are linear, then we can use any of the techniques we have encountered before (say, generalised inverse matrix approach) to deliver a solution. However, if they are nonlinear, we may use the Jacobian method for solving the set of nonlinear algebraic equations. Regardless, the computation may be time-consuming depending on how many integration steps we need to do. Euler simplified this problem by using Eqn (7.6) to predict yi+1 and then employing this predicted value to get a corrected estimate from Eqn (7.10).
Prof. A.A. Adesina, ChSE, UNSW 6
Euler methods
Eqns (7.6) and (7.10) constitute the Euler predictor-corrector pair and is more accurate because it has an error of order h3 (which can be readily shown by adding Eqns (7.3) & (7.9)). Thus, the Euler Predictor-Corrector method is:
(7.11a) (7.11b)
As a result, the Euler Predictor-Corrector method is preferred over the explicit or implicit method for the purpose of computation.
Runge-Kutta Methods
The Runge-Kutta methods are arguably the most widely used integration techniques for solving ODEs with initial conditions (IVP-ODEs). Although the formal derivation for each method is similar to the Euler method in the sense that we take advantage of particular approximations of the Taylor series expansion of the differential operator (cf. Lecture notes on Finite Difference operators as recalled in Eqns (7.3) & (7.9)), we will NOT provide formal derivations here but simply summarise the necessary equations to be used for each RK method as displayed in the Tables below.
Table 1: Summary of Runge-Kutta integration formulas (2nd-4th order) Order Formula for yi+1 of the RK Method Second 1 y i +1 = y i + ( k1 + k 2 ) 2 Third
yi +1 1 = y i + ( k1 + 4 k 2 + k 3 ) 6
Fourth
yi +1
1 = y i + ( k1 + 2 k 2 + 2 k 3 + k 4 ) 6
h k k 2 = hf x i + , y i + 1 2 2 k 3 = hf ( x i + h , y i + 2 k 2 k 1 = hf ( x i , y i )
O(h5)
h k k 2 = hf x i + , y i + 1 2 2 h k k 3 = hf x i + , y i + 2 2 2 k 4 = hf ( x i + h , y i + k 3 )
Table 2: Runge-Kutta-Gill integration formulas Order Formula for yi+1 Formula for RK constants of the RK Method Runge k1 = hf ( xi , yi ) 1 1 1 = + + + + + y y k k k k 2 1 2 1 i +1 i 1 2 3 4 Kutta6 2 2 k = hf x + h , y + k1 Gill i 2 2 i 2
h x + i 2, k3 = hf k k y + 2 1 1 + 2 2 2 i 2 2 xi + h, k4 = hf k k 3 2 y + 2+ 2 i 2 2
The Runge-Kutta-Gill method is the most widely used 4th order method and the constants are selected to reduce the amount of storage required in the solution of a large number of simultaneous 1st order ODEs. We will discuss application of RK methods to set of ODEs later.
Prof. A.A. Adesina, ChSE, UNSW 10
Order Formula for yi+1 Formula for RK constants of the RK Method Fifth k = hf ( xi , yi ) 1 yi+1 = yi + (7k1 + 32k3 + 12k4 + 32k5 + 7k6 ) 1 90 h k k2 = hf xi + , yi + 1 2 2
h 3k k k3 = hf xi + , yi + 1 + 2 2 16 16 k h k4 = hf xi + , yi + 3 2 2 3h 3k 6k 9k k5 = hf xi + , yi 2 + 3 + 4 4 16 16 16 k 4k 6k 12k 8k k6 = hf xi + h, yi + 1 + 2 + 3 4 + 5 7 7 7 7 7
11
k3 k2 0 .1 k 2 k1
(7 .1 2 )
After each integration step, then the step-size, h, should be decreased (to probably half its current value).
Prof. A.A. Adesina, ChSE, UNSW 12
Illustrative example
Let us find the solution to the IVP
dy = y + 2x 1 (E1.1) dx with y(0)=1.0 over the interval 0 x 1 using 4th order RK method
In this case, clearly,
f ( x, y) = y + 2 x 1
We divide the interval into 10 steps so that x0=0.0, x1=0.1..x10=1.0 with h=0.1. Thus, y(x00=1.0. Using the iterative formulas given on Table 1, we get,
Prof. A.A. Adesina, ChSE, UNSW 13
Results of the 4th order Runge-Kutta methods for the Illustrative Example xi
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
R-K
1.0 1.01034164 1.04280472 1.09971619 1.18364811 1.29744053 1.44423485 1.62750244 1.85107803 2.11920166 2.43655777
R-K-G
1.0 1.01034164 1.04280472 1.09971619 1.18364811 1.29744148 1.44423580 1.62750340 1.85107994 2.11920357 2.43656063
Exact value of yi
1.0 1.01034260 1.04280663 1.09971809 1.18365002 1.29744339 1.44423676 1.62750530 1.85108185 2.11920643 2.43656349
14
Predictor-Corrector Methods
The Runge-Kutta methods are single-step methods and are good for solving IVP because they self-starting. However, they may be plagued with instabilities for highly stiff ODEs which require small step-size to overcome numerical instabilities. Predictor-Corrector methods are preferred for such situations because they deliver more stable results. They are, however, nonself-starting and are regarded as multi-step techniques. The most common PC methods are summarised below.
15
Corrector Equation
Error involved
O(h2)
h = + y y ( i+1)Cor i 2( fi+1 + fi )
O(h5) h ( yi+1)Cor = yi1 + 3( fi+1 + 4 fi + fi1) O(h5) h ( yi+1)Cor = yi + 24( 9 fi+1 +19 fi 5 fi1 + fi2 )
O(h7)
Note that: fi = f(xi, yi); fi+1 = f(xi+1, yi+1) etc, in the Table above
Prof. A.A. Adesina, ChSE, UNSW 16
Predictor-Corrector Methods
How many times do we iterate on the Corrector equation? Typically, we employ a termination criterion to determine when to stop. For example, we can use:
m = 1,2,....
(7.12)
where m indicates the number of iterations performed so far on yi+1 using the Corrector Equation and is the tolerance factor, a small positive number, typically, 10-4 or smaller.
17
Worked Example
Use the Milnes 4th order PC method to solve
dy = 0.1( x + y )0.8 (E1) dx with y(1.0)=3.0 over the range x=1.0 to 2.0
Solution
f ( x , y ) = 0.1( x + y )0.8
Assume h=0.1, then let us calculate the 1st three points (y1,y2,y3) by the single-step method of 4th order R-K technique since the PC is NOT self-starting. Recall that we need, yi-3 to use the Milnes P-C method.
Prof. A.A. Adesina, ChSE, UNSW 18
Starting with the 4th order RK method and using y(1) =3.0; we have, x0=1.0 and y0=3.0
19
At the 4th integration step, we now turn to the 4th order Milnes PC. Hence,
P r : y4 = y0 + f 1 = 0.311042 f 2 = 0.318939 f 3 = 0.326834 y 4 = 3.0 + 0.4 (0.622084 + 0.653668 0.318939 ) = 3.127 58 3 h C or : y 4 = y 3 + ( f 4 + 4 f 3 + f 2 ) 3 f 4 = f ( x 4 , y 4 ) = 0.1(1.4 + 3.12758 ) 0.8 = 0.334728 4h ( 2 f 3 f 2 + 2 f1 ) 3
y 4 ,0 = 3.09449 +
0.1 (1.961 00 ) = 3.1598 6 3 1st iteration step of th e C orrector E q u ation f 4 = f ( x 4 , y 4 ,0 ) = 0.1(1.4 + 3.15986 ) 0.8 = 0.336636 h ( f + 4 f3 + f2 ) 3 4 0. 1 (1.96291) = 3.15992 = 3.09449 + 3 C h eck for con verge n c e y 4 ,1 = y 3 + y 4 ,1 y 4 ,0 y 4 ,0 L et u s assu m e th at = 1 0 -4 3.15992 3.15986 = 1.8988 10 5 10 4 3.15986
20
dz n 2 d n 2 y = = f n 2 ( x , z 1 , z 2 , ..... z n ) z n 1 = (7.17) dx dx n 2 dz d n1 y (7.18) z n = n 1 = = f n 1 ( x , z 1 , z 2 , ..... z n ) dx dx n 1 Introducing these equations into the original equation, w e receive dz n d n y dy d n 1 y ( , , ,... g x y = = )= f n ( x , z 1 , z 2 , ..... z n ) dx dx n dx dx n 1 (7.19)
21
k1n h k11 k12 k2 j = hf j xi + , zi1 + , zi 2 + ,....zin + 2 2 2 2 k2n h k21 k22 k3 j = hf j xi + , zi1 + , zi 2 + ,....zin + 2 2 2 2
Prof. A.A. Adesina, ChSE, UNSW
m ax Re( i ) SR = m in R e( i )
(7.25)
Where is are the eigenvalues of the ODE system and max |Re(i)| is the real part of the maximum eigenvalue of the system. In general, if a). SR is about an order of magnitude (10,20, etc), the system is NOT stiff. b). SR is about three orders of magnitude (1000, 2000, etc) the system is STIFF c). SR is about six orders of magnitude (106, etc), the system is VERY STIFF. The eigenvalues are obtained from the matrix of the coefficients of the set of ODEs.
Prof. A.A. Adesina, ChSE, UNSW 23
f y xi
(7.27)
where can vary in magnitude at each step of the integration. f is NEGATIVE at some point in the range of integration. Eqn (7.26) will be stiff if y Thus, the solution will be unstable.
Prof. A.A. Adesina, ChSE, UNSW 24
-2 h 0 0 < h < , for < 0; -2 h 0, for > 0 -1.077 h 0 -2 h 0 -2.5 h 0 -2.785 h 0 -5.7 h 0 -1.285 h 0
25
For a set of n simultaneous ODEs, we can obtain the eigenvalues from the Jacobian matrix of the functions, fi written;
f1 f1 f1 ....... y y2 yn 1 f 2 f 2 f 2 ........ y y yn 2 1 J = . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . f n f f n ........ n y1 y2 yn
26
27
Example problem
Solve
d 2y = x 2 dx
+ xy + y
dy = 0.5 at x =1.0 dx
28
Solution Let
dy = f1 ( x , y , z ) dx d2y dz = = x 2 + xy + y 2 = f2 ( x, y, z ) 2 dx dx z=
Assume h = 0.5. From the initial conditions x 0 = 1 .0 , y 0 = 4 .0 , z 0 = 0 .5 1st R-K constants k 1 1 = h f 1 ( x 0 , y 0 , z 0 ) = 0 . 5 x 0 . 5 = 0 .2 5
k 1 1 = h f 2 ( x 0 , y 0 , z 0 ) = 0 . 5 (1 + 4 + 1 6 ) = 1 0 .5 0
29
h k 21 k 22 , y 0 + , z0 + ) 2 2 2 = 0 . 5 [ (1 . 2 5 ) 2 + 5 . 4 3 7 5 x 1 . 2 5 + ( 5 . 4 3 7 5 ) 2 ] = 1 8 .9 6 2 9 = hf2 ( x
0
31
, z
+ k
32
+ h = 1 .5 + k + k
41 31 32
= 7 .2 1 6 8 = 1 9 .4 6 2 9
0
k
42
= 0 .5 x 1 9 .4 6 2 9 = 9 .7 3 1 4 5 + h, y
0 2
= hf2 (x
+ k
31
, z
+ k
32
= 0 .5 [ ( 7 .2 1 6 8 ) = 3 2 .5 7 8 7 y =
+ 1 . 5 x 7 . 2 1 6 8 + (1 . 5 ) 2 ]
1 [ k 11 + 2 k 21 + 2 k 31 + k 41 ] = 3 .6 9 4 1 8 6 1 z = [ k 12 + 2 k 22 + 2 k 32 + k 42 ] = 1 7 .4 5 6 5 6 y (1 ) = y 0 + y = 7 . 6 9 4 1 8 z
(1 ) (1 )
= z
0 0
+ z = 1 7 .9 5 6 5
x = x + h = 1 .5 We will now use x(1), y(1), and z(1) as the starting point for the computation of x ( 2 ) , y ( 2 ) , a n d z ( 2 ) .
30
2nd R-K constants k k h k 21 = hf1 ( x (1) + , y (1) + 11 , z (1) + 12 ) 2 2 2 h x (1) + = 1.75 2 k y (1) + 11 = 12.1833 2 k z (1) + 12 = 36.2044 2 k 21 = 0.5 x 36.2044 = 18.1022
k 22 = hf 2 ( x (1) +
k 3 2 = h f 2 ( x (1 ) + = 1 5 6 .3 8 6
h k k , y (1 ) + 2 1 , z (1 ) + 2 2 ) 2 2 2 2 = 0 . 5 [ (1 . 7 5 ) + 1 . 7 5 x 1 6 . 7 4 5 3 + (1 6 . 7 4 5 3 ) 2 ]
(1 )
+ k 3 1 , z (1 ) + k 3 2 )
x (1 ) + h = 2 . 0 y
(1 )
+ k 31 = 3 9 .7 9 7 3
z (1 ) + k 3 2 = 1 7 4 . 3 4 2 k 41 = 0 .5 x 1 7 4 .3 4 2 = 8 7 .1 7 1 k 4 2 = h f 2 ( x (1 ) + h , y
(1 )
+ k 3 1 , z (1 ) + k 3 2 )
= 0 .5 [( 2 ) 2 + 2 x 3 9 .7 9 7 3 + (3 9 .7 9 7 3 ) 2 ] = 1 6 6 7 .4 2 y = 1 [ k 11 + 2 k 21 + 2 k 31 + k 41 ] = 3 2 .7 6 6 1 [ k12 + 2 k 22 + 2 k 32 + k 42 ] = 3 6 6 .9 4 8 z = 6 y ( 2 ) = y (1 ) + y = 4 0 . 4 5 4 2 z ( 2 ) = z (1 ) + z = 3 8 4 . 9 0 4 x ( 2 ) = x (1 ) + h = 2 . 0
at x = 2.0, y = 40.4542
32