ordinary differential equationssunil/ode.pdfordinary differential equations. to solve a differential...
TRANSCRIPT
Ordinary Differential Equations
Here we will look at some methods of solvingordinary differential equations.
To solve a differential equation of order n we need nboundary conditions.
If all the boundary conditions are specified at onepoint with call this an initial value problem.
If m boundary conditions are specified at andn-m at the other boundary then it is called aboundary value problem.Here we will discuss only initial value problems.
0x x=
We will start with first order equations ofthe form .
All the numerical methods for solvingdifferential equations require the function to be evaluated at a finite set ofpoints
. Here we have used the notation
' ( , )y f x y=
( , )n nx y
( , )f x y
( )n ny y x=
Euler's Method
If the point then we can Taylorexpand around to first orderin derivatives to write
This is the basic idea behind Euler'smethod, where in we write
1i ix x h
+= +
( )y xi
x x=
( ) ( ) ( , )i i i i
y x h y x h f x y+ = +
Though easy to program this method is not veryaccurate. The main reason is that the error made atany point is propagated to other points as well.
1
2
and the error
( , )
'' )2
i (s
n n n ny y hf x y Error
hE y
+= + +
= !
The error is of the order of second derivatives of . ( )y x
Predictor corrector method:
This is a method which improves on Euler ‘sscheme by an iterative scheme.
It involves two steps:
1) The predictor
2) The corrector
0 ( ) ( ) ( , )+ = +i i i i
y x h y x h f x y
0
1( ) ( ) ( ( , ) ( , ))2
++ = + +
i i i i i i
hy x h y x f x y f x y
Runge - Kutta method
The Runge - Kutta's methods obtain greateraccuracy, and at the same time avoid the need ofhigher derivatives, by evaluating the functionat selected points on each subinterval.
The order of Runge - Kutta formulae reflect thenumber of points at which the function isevaluated.
( , )f x y
We shall first consider a first-order initial valuedifferential equation of the form ' ( , )y f x y=
In a second order Runge - Kutta method, a formulaof the following form is sought
1 1 2n ny y ak bk
+= + +
where
1
2 1
( , )
( , )
n n
n n
k hf x y
k hf x h y k
=
= +! +"
(1)
We have to now have a scheme to find thecoefficients . On expanding in aTaylor series through terms of higher order weobtain
( , , , )a b ! "1( )
ny x
+
2 3
1
2
32 2 4
( ) ( ) '( ) ''( ) '''( ) ...2 6
( ) ( , ) ( )2
( 2 )6
n n n n n
n n n x y
xx xy yy x y y
h hy x y x hy x y x y x
hy x hf x y f ff
hf ff f f f f f f h
+= + + + +
= + + +
+ + + + + +!
On the other hand, using Taylor's expansion forfunctions of two variables we find that
21
2 2
1
2 231
1
( , )
( , )
2
( )2
n n
n n x
y xx
xy yy
kf x h y k
h
f x y hf
hk f f
kh k f f h
= +! +"
= +!
!+" +
"+! " + +#
where all derivatives are evaluated at ( , )n nx y
Substituting the expression for into (1) and alsosubstituting , we find uponarrangement in powers of h that
2k
1 ( , )n n
k hf x y=
2
1
2 23 2
4
( ) ( )
2 2
( )
n n x y
xx xy yy
y y a b hf bh f ff
bh f ff f f
h
+= + + + ! +"
# $! "+ +!" +% &
' (
+)
on comparing equations 1 and 2 for the powers of hwe have
1
1
2
a b
b b
+ =
! = " =
Since there are only three equations for the fourvariables there are many possible solutions. We willdiscuss only one of them here , given by
1
2
1
a b= =
! = " =
Example: Find the solution of the differentialequation from
using two point Runge -Kutta scheme. The boundary condition is .
2dy
ydx
= !
0 to 2x x= =
(0) 1y =
Runge - Kutta Method of order 4
Here we generate approximations using therecursion formula
1 1 2 3 4
1 ( 2 2 )
6n ny y k k k k
+= + + + +
1
2 1
3 2
4 3
( , )
1( , )
2 2
1( , )
2 2
( , )
n n
n n
n n
n n
k hf x y
hk hf x y k
hk hf x y k
k hf x h y k
=
= + +
= + +
= + +
Where
Higher order differential equationsSo far we have only looked at the first orderequations. We shall see how to extend thesetechniques to higher order initial value problems.
Suppose we have an equation of the form
with the boundary condition
from
2
20
d y dya cy dx
dx dx+ + + =
'
0( 0) and y ( 0)y x y x c= = = =
0 to 2x x= =
The boundary conditions are now
For a second order Runge - Kutta now we need twosets of equations
To solve this equation we will split it into a set offirst order differential equation as follows.
dyz
dx
dzaz cy xd
dx
=
= + +
0(0) and z(0)=cy y=
1 2
1 2
1( 1) ( ) ( ) (1)
2
1( 1) ( ) ( ) (2)
2
y y
z z
y n y n k k
z n z n k k
+ = + +
+ = + +
1
1
2 1
2 1 1
( )
( ) ( )
( )
( ( ) ) ( ( ) ) ( )
y
z
y z
z z y
k z n
k az n cy n xd
k z n hk
k a
w
z n hk c y n h d
th
k x h
i
=
= + +
= +
= + + + + +
the functions arecalculated in that order (you can see that thisorder is important!!)
Now how will you do this for a fourth orderRunge - Kutta??
1 1 2 2, , and
y z y zk k k k
Adaptive Step Size for Runge - Kutta
So far we had a fixed step size h to go from thestarting value to the final value of the independentvariable. How do we know what value to use for stepsize h ?. The algorithm is the following.
We choose an interval h , compute the value offrom by a single step. Half the value of h andcompute from by two of these halfsteps.
1 1ny y
+=
ny
1 2ny y
+= n
y
Problem: Solve the equation
using an adaptive step size Runge-Kutta algorithm.Use as the starting step size to go from
2 , (0) 1dy
x y ydx
= ! ! = !
.2h =
1 to 1x x= ! =
The error is then compared with a
predetermine error tolerance εa . If the errorthen the step size is doubled, if the step sizeis halved. The process is repeated tillchanges sign .
2 1
1
y y
y!
"=
a!
a! !<
a! !>
a! !"