Click to add title

advertisement
Numerical
Analysis
Lecture 40
Chapter 7
Ordinary
Differential
Equations
Introduction
Taylor Series
Euler Method
Runge-Kutta Method
Predictor Corrector
Method
RUNGAKUTTA
METHODS
We considered the IVP
dy
 f (t , y ),
y (tn )  yn
dt
We also defined
k1  hf (tn , yn ),
k2  hf (tn   h, yn   k1 )
and took the weighted
average of k1 and k2 and
added to yn to get yn+1
We obtained
W1  W2  1,
W2 ( ft   ff y ) 
ft  ff y
2
Implying
W1  W2  1,
1
W2  W2  
2
We considered two cases,
Case I We choose W2 = 1/3,
then W1 = 2/3 and     3/ 2.
1
yn 1  yn  (2k1  k2 )
3
k1  hf (t , y),
3 
 3
k2  hf  t  h, y  k1 
2 
 2
Case II: We considered
W2 = ½, then W1 = ½ and
    1.
Then
k1  k2
yn 1  yn 
2
k1  hf (t , y),
k2  hf (t  h, y  k1 )
The fourth-order R-K
method was described as
1
yn 1  yn  (k1  2k2  2k3  k4 )
6
where
k1  hf (tn , yn )
k1 
h

k2  hf  tn  , yn  
2
2

k2 
h

k3  hf  tn  , yn  
2
2

k4  hf (tn  h, yn  k3 )
PREDICTOR –
CORRECTOR
METHOD
Milne’s Method
It is a multi-step method
where we assume that the
solution to the given IVP is
known at the past four
equally spaced point t0, t1, t2
and t3.
Alternatively, it can also be
written as
4h
28 4
y4  y0 
(2 y1  y2  2 y3 )  h y0
3
90
This is known as Milne’s
predictor formula.
Similarly, integrating the
original over the interval t0 to
t2 or s = 0 to 2 and repeating
the above steps, we get
h
1
4
y2  y0  ( y0  4 y1  y2 )  h y0
3
90
which is known as Milne’s
predictor formula.
In general, Milne’s predictorcorrector pair can be written
as
4h

P : yn 1  yn 3  (2 yn  2  yn 1  2 yn ) 

3

h
C : yn 1  yn 1  ( yn 1  4 yn  yn 1 ) 

3
Adam-Moulton Method
It is another predictorcorrector method, where we
use the fact that the solution
to the given initial value
problem is known at past
four equally spaced points
tn, tn-1, tn-2, tn-3.
The task is to compute the
value of y at tn+1.
Let us consider the
differential equation
dy
 f (t , y )
dt
Integrating between the
limits tn to tn+1, we have

tn1
tn
tn1
dy
dt   f (t , y )dt
tn
dt
That is,
yn1  yn  
tn1
tn
f (t , y)dt
To carry out integration, we
proceed as follows. We
employ Newton’s backward
interpolation formula, so that
s ( s  1) 2
f (t , y )  f n  sf n 
 fn
t

t
n
2
s
h
s ( s  1)( s  2) 3

 fn 
6
After substitution, we obtain
s ( s  1) 2
yn 1  yn    f n  sf n 
 fn
tn
2
s ( s  1)( s  2) 3
s( s  1)( s  2)( s  3) 4

 fn 
 fn 
6
24
tn1

 dt
Now by changing the variable
of integration (from t to s), the
limits of integration also
changes (from 0 to 1), and
thus the above expression
becomes
s ( s  1) 2
yn 1  yn  h   f n  sf n 
 fn
0
2
s( s  1)( s  2) 3
s ( s  1)( s  2)( s  3) 4

 fn 
 fn 
6
24
1

 ds
Actual integration reduces
the above expression to
1
5 2
3 3
251 4 

yn1  yn  h  f n  f n   f n   f n 
 fn 
2
12
8
720


Now substituting the
differences such as
f n  f n  f n1
2 fn  fn  2 fn1  fn2
3 fn  fn  3 fn1  3 fn2  fn3
Equation simplifies to
h
251 4
yn 1  yn  (55 f n  59 f n 1  37 f n  2  9 f n 3 ) 
h f n
24
720
Alternatively, it can be
written as
h
251 4




yn 1  yn  55 yn  59 yn 1  37 yn  2  9 yn 3  
h yn
24
720
This is known as Adam’s
predictor formula.
The truncation error is
4
(251/ 720)h yn .
To obtain corrector
formula, we use Newton’s
backward interpolation
formula about fn+1 instead
of fn.
We obtain
s( s  1) 2
 f n 1
1
2
s ( s  1)( s  2) 3
s ( s  1)( s  2)( s  3) 4

 f n 1 
 f n 1 
6
24
yn 1  yn  h 
0
 f n1  sf n1 

 ds
Carrying out the integration
and repeating the steps, we
get the corrector formula as
h
19  4

yn1  yn   9 yn 1  19 yn  5 yn 1  yn 2   
 h yn 1
24
 720 
Here, the truncation error is
19 20 h yn1.
4
The truncation error in Adam’s
predictor is approximately
thirteen times more than that
in the corrector, but with
opposite sign.
In general, Adam-Moulton
predictor-corrector pair can
be written as
h

P : yn 1  yn   55 yn  59 yn 1  37 yn  2  9 yn 3  

24

h

C : yn 1  yn   9 yn 1  19 yn  5 yn 1  yn  2 

24
Example
Using Adam-Moulton
predictor-corrector method,
find the solution of the initial
value problem dy  y  t , y(0)  1
2
dt
at t = 1.0, taking h = 0.2.
Compare it with the analytical
solution.
Solution
In order to use Adam’s P-C
method, we require the
solution of the given
differential equation at the
past four equally spaced
points, for which we use R-K
method of 4th order which is
self starting.
Thus taking t0 =0, y0 = 1,
h = 0.2, we compute
k1 = 0.2, k2 = 0.218,
k3 = 0.2198, k4 = 0.23596,
and get
1
y1  y0  (k1  2k2  2k3  k4 )  1.21859
6
Taking t1 = 0.2,
y1 = 1.21859, h = 0.2,
we compute k1 = 0.23571,
k2 = 0.2492,
k3 = 0.25064, k4 = 0.26184,
and get
1
y2  y1  (k1  2k2  2k3  k4 )  1.46813
6
Now, we take t2 = 0.4,
y2 = 1.46813, h = 0.2, and
compute k1 = 0.2616,
k2 = 0.2697,
k3 = 0.2706, k4 = 0.2757
to get
1
y3  y (0.6)  y2  (k1  2k2  2k3  k4 )  1.73779
6
Thus, we have at our disposal
y0  y (0)  1
y1  y (0, 2)  1.21859
y2  (0.4)  1.46813
y3  y (0.6)  1.73779
Now, we use Adam’s P-C
pair to calculate y (0.8) and
y (1.0) as follows:
h
P : yn 1  yn   55 yn  59 yn 1  37 yn  2  9 yn 3 
24
h
C : yn 1  yn   9 yn 1  19 yn  5 yn 1  yn  2 
24
Thus
h
y  y3   55 y3  59 y2  37 y1  9 y0 
24
p
4
(1)
From the given differential
equation, we have
2

y  y t .
Therefore, y  y  t 2  1.0
0
0
0
y1  y1  t  1.17859
2
1
y2  y2  t  1.30813
2
2
y3  y3  t  1.37779
2
3
Hence, from Eq. (1), we get
y (0.8)  y4p  1.73779 
0.2
 75.77845  77.17967  43.60783  9 
24
 2.01451
Now to obtain the corrector
value of y at t = 0.8, we use
h
y  y (0.8)  y3   9 y4  19 y3  5 y2  y1 
24
c
4
c
(2)
But,
9 y4  9( y4p  t42 )  9[2.01451  (0.8)2 ]  12.37059
Therefore,
y4  y c (0.8)  1.73779 
 2.01434
0.2
12.37059  26.17801  6.54065  1.17859 
24
(3)
Proceeding similarly, we get
h
y  y (1.0)  y4   55 y4  59 y3  37 y2  9 y1 
24
p
5
p
Noting that y4  y4  t  1.3743,
2
4
we calculate
y5p  2.01434 
0.2
 75.5887  81.28961  48.40081  10.60731
24
 2.28178
Now, the corrector formula
for computing y5 is given by
h
y  y (1.0)  y4   9 y5  19 y4  5 y3  y2 
24
c
5
c
(4)
But,
p
2

9 y5  9  y5  t5   11.53602
Thus, finally we get
y5  y (1.0)  2.01434 
 2.28393
0.2
11.53602  26.17801  6.54065  1.17859 
24
(5)
The analytical solution can be
seen in the following steps.
dy
 y  t 2
dt
After finding integrating
factor and solving, we get
d 1
ye  e  t t 2
dt
Integrating, we get
ye    e t dt   t d (e )  t e  2te  c
t
t 2
That is,
2
t
2 t
c
y  t  2t  2   t
e
2
Now using the initial
condition, y(0) = 1,
we get c = – 1.
t
Therefore, the analytical
solution is given by
y  t  2t  2  e
2
t
from which, we get
y(1.0)  5  e  2.2817
Convergence
and Stability
Considerations
The numerical solution
of a differential equation
can be shown to
converge to its exact
solution, if the step size
h is very small.
The numerical solution of
a differential equation is
said to be stable if the
error do not grow
exponentially as we
compute from one step to
another.
Stability consideration are
very important in finding
the numerical solutions of
the differential equations
either by single-step
methods or by using multistep methods.
However, theoretical analysis
of stability and convergence
of R -K methods and P –C
methods are highly involved
and obtain numerically stable
th
solution using 4 order R – K
method to the simple problem
y’ = Ay gives us stability
condition as -2.78<Ah
In practice, to get numerically
stable solutions to similar
problems, we choose the
value of h much smaller than
the value given by the above
condition and also check for
consistency of the result.
Another topic of interest which
is not considered, namely the
stiff system of differential
equations that arises in many
chemical engineering systems,
such as chemical reactors,
where the rate constants for the
reactions involved are widely
different.
Most of the realistic stiff
DE do not have analytical
solutions and therefore
only numerical solutions
can be obtained.
However, to get numerically
stable solutions, a very small
step size h is required, to use
either R-K methods or P – C
methods.
More computer time is
required
Numerical
Analysis
Lecture 40
Download