ordinary differential equationssunil/ode.pdfordinary differential equations. to solve a differential...

20
Ordinary Differential Equations Here we will look at some methods of solving ordinary differential equations. To solve a differential equation of order n we need n boundary conditions. If all the boundary conditions are specified at one point with call this an initial value problem. If m boundary conditions are specified at and n-m at the other boundary then it is called a boundary value problem. Here we will discuss only initial value problems. 0 x x =

Upload: others

Post on 16-Nov-2020

31 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: Ordinary Differential Equationssunil/ODE.pdfordinary differential equations. To solve a differential equation of order n we need n boundary conditions. If all the boundary conditions

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=

Page 2: Ordinary Differential Equationssunil/ODE.pdfordinary differential equations. To solve a differential equation of order n we need n boundary conditions. If all the boundary conditions

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=

Page 3: Ordinary Differential Equationssunil/ODE.pdfordinary differential equations. To solve a differential equation of order n we need n boundary conditions. If all the boundary conditions

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+ = +

Page 4: Ordinary Differential Equationssunil/ODE.pdfordinary differential equations. To solve a differential equation of order n we need n boundary conditions. If all the boundary conditions

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

Page 5: Ordinary Differential Equationssunil/ODE.pdfordinary differential equations. To solve a differential equation of order n we need n boundary conditions. If all the boundary conditions

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

Page 6: Ordinary Differential Equationssunil/ODE.pdfordinary differential equations. To solve a differential equation of order n we need n boundary conditions. If all the boundary conditions

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=

Page 7: Ordinary Differential Equationssunil/ODE.pdfordinary differential equations. To solve a differential equation of order n we need n boundary conditions. If all the boundary conditions

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)

Page 8: Ordinary Differential Equationssunil/ODE.pdfordinary differential equations. To solve a differential equation of order n we need n boundary conditions. If all the boundary conditions

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

+= + + + +

= + + +

+ + + + + +!

Page 9: Ordinary Differential Equationssunil/ODE.pdfordinary differential equations. To solve a differential equation of order n we need n boundary conditions. If all the boundary conditions

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

Page 10: Ordinary Differential Equationssunil/ODE.pdfordinary differential equations. To solve a differential equation of order n we need n boundary conditions. If all the boundary conditions

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

+= + + + ! +"

# $! "+ +!" +% &

' (

+)

Page 11: Ordinary Differential Equationssunil/ODE.pdfordinary differential equations. To solve a differential equation of order n we need n boundary conditions. If all the boundary conditions

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= =

! = " =

Page 12: Ordinary Differential Equationssunil/ODE.pdfordinary differential equations. To solve a differential equation of order n we need n boundary conditions. If all the boundary conditions

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 =

Page 13: Ordinary Differential Equationssunil/ODE.pdfordinary differential equations. To solve a differential equation of order n we need n boundary conditions. If all the boundary conditions

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

+= + + + +

Page 14: Ordinary Differential Equationssunil/ODE.pdfordinary differential equations. To solve a differential equation of order n we need n boundary conditions. If all the boundary conditions

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

Page 15: Ordinary Differential Equationssunil/ODE.pdfordinary differential equations. To solve a differential equation of order n we need n boundary conditions. If all the boundary conditions

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= =

Page 16: Ordinary Differential Equationssunil/ODE.pdfordinary differential equations. To solve a differential equation of order n we need n boundary conditions. If all the boundary conditions

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=

Page 17: Ordinary Differential Equationssunil/ODE.pdfordinary differential equations. To solve a differential equation of order n we need n boundary conditions. If all the boundary conditions

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

=

= + +

= +

= + + + + +

Page 18: Ordinary Differential Equationssunil/ODE.pdfordinary differential equations. To solve a differential equation of order n we need n boundary conditions. If all the boundary conditions

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

Page 19: Ordinary Differential Equationssunil/ODE.pdfordinary differential equations. To solve a differential equation of order n we need n boundary conditions. If all the boundary conditions

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

Page 20: Ordinary Differential Equationssunil/ODE.pdfordinary differential equations. To solve a differential equation of order n we need n boundary conditions. If all the boundary conditions

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! !"