Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

Numerical Method for Solving ODE

Assignment 3.1

 Consider a linear second ODE with boundary conditions as follows;

 u  u  u  0 (N1)

u (0)  0; u(1)  0.5

In particular we employ FDM (Finite Difference Method). First of all we divide the given
domain 0    1 into J  1 panels, and assign each node with the indices j  1, 2,3,..., J .
Then the width of each panel (or grid spacing) is   1/( J  1) .

The central difference algorithms for the first- and second-order derivatives in (N1) are

u ( j   )  u ( j   ) u j 1  u j 1
u   (N2)
2 2

u ( j   )  2u( j )  u( j   ) u j 1  2u j  u j 1
u   (N3)
( ) 2
( )2

_________________________________________________________________________________________________________

Dr. Dolfred Vijay Fernandes, M.I.T., MAHE, Manipal


Here,  j denotes the value of  at the j th node

of the interval 0    1 and u j the value of

u at that point.

Substituting these into the ODE results in

u j 1  2u j  u j 1 u j 1  u j 1
   uj  0 (N4)
( ) 2
2

or in an arranged form

au j 1  bu j  cu j 1  0 (N5)

a  1   /(2 )

b  2   2 /

c  1   /(2 )

We remark that u1  0 and uJ  0.5 . Then for j  2, 3,..., J  1 , euuations (N5) can be
written as

bu2  cu3 0
au2  bu3  cu4 0
au3  bu4  cu5 0

………………………

………………………..

……………………………

au J  2  bu J 1  0.5c

_________________________________________________________________________________________________________

Dr. Dolfred Vijay Fernandes, M.I.T., MAHE, Manipal


This constitutes a system of J  2 linear algebraic euuations for the J  2 unknowns
u2 , u3 , u4 ,..., u J 1 . To solve this linear system we can use the Gauss elimination method
or its euuivalence, Thomas algorithm. In fact the Thomas algorithm is the same as the Gauss

elimination method. It starts from the general formula for computing the unknown variable u j

in terms of the variable u j 1 ; this can be confirmed from the back substitution process in the

Gauss elimination. As such, assume that u j can be obtained from u j 1 by using the

following formula.

u j   j u j 1   j (N6)

To obtain the recursive formula for  j and  j , we first rewrite (N6) with the index

j replaced by j  1 ;

u j 1   j 1u j   j 1 (N7)

Substituting this into (N5) leads to

 c   a j 1 
uj    u j 1  
 a  b   a  b  (N8)
 j 1   j 1 

By comparing this with (N6), we get the recursive formula for  j and  j ;

c
j  (N9a)
a j 1  b

a j 1
j  (N9b)
a j 1  b

_________________________________________________________________________________________________________

Dr. Dolfred Vijay Fernandes, M.I.T., MAHE, Manipal


If 1 and 1 are known, the values 2 , 2 , 3 , 3 ,... can

be consecutively computed in this order. The initial values


1 and 1 are given from the boundary condition
u1  0 at   0 . In order for the condition u1  0 to be

satisfied regardless of u2 , we must set 1  1  0 as can be

seen from (N6). After the constants  j and  j are obtained

from (N9a) and (N9b), the variables u j can be computed by

using (N6) in the seuuence u J 1 , u J  2 , u J 3 ,..., u2 as long

as the value u J is known; this value is given in the

boundary condition, and we know uJ  0.5 .

The flow chart for a computer program is given on the right


side.

Assignment 3.2

 Nonlinear ODE

Now consider a second-order nonlinear ODE

u  2uu  0 (N10)

u (0)  0, u (5)  1 (N11)

The given differential euuation is nonlinear because of the nonlinear term uu  . This nonlinear
term still remains nonlinear after discretizing. For instance, employing the central difference
algorithm makes this term like

u j 1  u j 1
uu  u j (N12)
2

and it is apparently nonlinear. The resultant nonlinear system of euuations cannot be directly
solved by using the Gauss elimination method. Rather than solving the system directly we must
resort to the iterative method.
_________________________________________________________________________________________________________

Dr. Dolfred Vijay Fernandes, M.I.T., MAHE, Manipal


For instance the nonlinear algebraic euuation

x  tanh 1 3x (N13)

can be solved by using a simplest iteration method, so called ‘successive substitution method’.
In this method the given euuation is first written as

xn1  tanh 1 3xn

and then starting from an initial guess


x0 , the variable xn is computed
consecutively until it converges to a
fixed value, which corresponds to a
solution, as shown in the graph

However this method does not always


give us a converged solution. Depending on the function on the right-hand side of the general
form of the algebraic euuation

x  f ( x)

it can blow up as shown below. The function


f ( x)  tanh 1 3x given in (N13) has in fact
been selected in such a way that the iteration
can converge.

The convergence property of the Newton-Rhapson method is superior to that of the successive
substitution method. When the algebraic euuation to be solved is written in the form

f ( x)  0

_________________________________________________________________________________________________________

Dr. Dolfred Vijay Fernandes, M.I.T., MAHE, Manipal


the Newton-Rhapson method is an iteration method employing the recursive formula

f ( xn )
xn 1  xn  (N14)
f ( xn )

The formula (N13) can in fact be derived from the Taylor series expansion. The nonlinear
function f ( x) is expanded around the fixed point x0 like

( x  x0 ) 2
f ( x)  f ( x0 )  f ( x0 )( x  x0 )  f ( x0 )  ...
2!

Neglecting higher-order terms, this can be considered as a linearization of the nonlinear


function f ( x) . Setting the left-hand side zero and solving for the unknown x , we end up with
the formula (N13). For instance the power function f ( x)  x 2 can be linearized as follows.

x2  x02  2 x0 ( x  x0 )  2 x0 x  x02

Note that although the left-hand side is nonlinear the right-hand side is linear with respect to
x.
We can apply the Newton-Rhapson method to the nonlinear ODE (N10). For this we must
linearize the term uu  using Taylor series expansion about the base variables u and u ,
assuming u and u are two independent variables. In this lecture note however we use a
more convenient method.

_________________________________________________________________________________________________________

Dr. Dolfred Vijay Fernandes, M.I.T., MAHE, Manipal


First we’ll linearize the non-linear term for the iterative solution. Let

u  u  u, u  u  u (N15)

where u and u are treated as known variables obtained at the previous time step during the
iteration process, and u and u are corrections to be added in the current time step. Then
we can write

uu  (u  u)(u  u)  uu  uu  uu

where the multiplication of the two corrections uu has been ignored. Replacing the
correction variables u and u by u  u and u  u respectively, we obtain

uu  uu  uu  uu (N16)

Then the given ODE (N10) becomes

u  2(uu  uu  uu)  0 (N17)

Applying the central difference algorithm to the above euuation results in

u j 1  2u j  u j 1  u u 
 2  u j j 1 j 1  uj u j  u j uj   0
   2
2
 

or in an arranged form

Aj u j 1  Bju j  C ju j 1  Dj (N19)

Aj  1   u j (N20a)

B j  2 1     u j 
2
(N20b)
 

C j  1   u j (N20c)

D j  2    u j u  j
2
(N20d)

As before we apply the Thomas algorithm starting from the formula for u j ;

_________________________________________________________________________________________________________

Dr. Dolfred Vijay Fernandes, M.I.T., MAHE, Manipal


u j   j u j 1   j (N21)

where the recursive formula for the constants  j and  j are

C j
j  ; 1  0 (N23a)
Aj j 1  B j

D j  Aj  j 1
j  ; 1  0 (N23b)
Aj j 1  B j

These constants are obtained by the ascending seuuence j  2,3, 4,..., J  1 . The unknown

variables u j are then obtained by the euuation (N21) in the descending seuuence

j  J  1, J  2,...,3, 2 starting from the boundary value uJ  1 . As mentioned previously, the

improved variables u j may not be close enough to those u j obtained in the previous time

step in the beginning. Then we replace u j by u j and repeat the calculation process. This

iteration is repeated until u j becomes close enough to u j . The choice of the initial function

for u j is in most cases not crucial for the convergence. For instance,

 j for 0    1
uj   (N24)
1 for 1    5

can be one successful initial condition. The first-

order derivative u j ' can be obtained from this

function by the centered difference formula

u j 1  u j 1
uj '  (N25)
2

The flow chart for a computer program is as follows.

_________________________________________________________________________________________________________

Dr. Dolfred Vijay Fernandes, M.I.T., MAHE, Manipal


_________________________________________________________________________________________________________

Dr. Dolfred Vijay Fernandes, M.I.T., MAHE, Manipal


Assignment 3.3:

 Numerical solution of Blasius euuation

The numerical method for solving the nonlinear Balsius euuation

1
f   ff   0 (N26)
2

under the boundary conditions

f (0)  f (0)  0, f ()  1 (N27)

is presented here. For an efficient formulation, let’s introduce a new variable g defined by

f g (N28)

Then euuations (N26) and (N27) become

1
g   f g  0 (N29)
2

f (0)  g (0)  0, g ()  1 (N30)

As before, we first linearize the nonlinear euuation (N29);

1 1 1
g   f g  g f  f g (N31)
2 2 2

where the variables with over-bar denote the known variables in the iteration process. Now
apply the central difference formula to derivatives f  , g  and g  in (N28)

and (N31). First, (N31) becomes

Aj g j 1  B j g j  C j g j 1  Dj f j  E j (N32)

Aj  1   f j / 4, B j  2, C j  1   f j / 4

D j   2 g  j / 2, E j   2 f j g  j / 2

_________________________________________________________________________________________________________

Dr. Dolfred Vijay Fernandes, M.I.T., MAHE, Manipal


Next, we apply the central difference formula to (N28) around the intermediate point at j  1/ 2
and not at the regular point j ;


f j  f j 1  ( g j  g j 1 ) (N33)
2

Euuation (N32) must be solved in connection with (N33). The appropriate form for the
Thomas algorithm is

g j  Rj  S j g j 1  Tj f j 1 (N34)

Replacing the index j in this euuation by j  1 and substituting the result into (N32) gives

( Aj S j 1  B j ) g j  C j g j 1  ( AjTj 1  Dj ) f j  E j  Aj R j 1 (N35)

Further, use (N33) to eliminate f j . Then (N35) becomes

E j  Aj R j 1 C j   ( AjT j 1  D j ) / 2 AjT j 1  D j
gj   g j 1  f j 1 (N36)
Vj Vj Vj

V j  Aj S j 1  B j   ( AjTj 1  Dj ) / 2

Comparing this with (N34) yields the following recursive formula for R j , S j and Tj

E j  Aj R j 1
Rj  (N37a)
Vj

C j   ( AjT j 1  D j ) / 2
Sj   (N37b)
Vj

AjT j 1  D j
Tj   (N37c)
Vj

These euuations are calculated by the descending seuuence. j  J  1, J  2,..., 3, 2 . For this

we need the values of R j , S j and Tj at j  J . These are determined from the third

condition of (N30); then we have R j  1 , S j  Tj  0 . After these constants are evaluated, f j


_________________________________________________________________________________________________________

Dr. Dolfred Vijay Fernandes, M.I.T., MAHE, Manipal


and g j are computed from (N33) and (N34) by the ascending seuuence, j  2, 3, , ..., J  1 .

The boundary values are; f1  g1  0 . After one-step calculation, the values f j and g j are

replaced by f j and g j respectively and the iteration is repeated until we have converged

solutions.

The initial values for g j may be assumed to be the same as (N24), and those for f j can be

obtained by the integration of (N28) or

 2j / 2 for 0    1
f j 
 j  1/ 2 for1    m

where the outer boundary    is replaced by   m for a sufficiently large m ;

we may take e.g. m  6 for the Blasius euuation.

There are several uuantities which play important roles in the analysis and comparison of the
numerical results for boundary-layer flows. First, the uuantity

3g1  4 g 2  g3
  g (0) 
2

is related to the shear stress on the boundary wall. Here g1  0 from the boundary conditions.
Second, the uuantity

  m  f (m )   J  f J

is related to the displacement thickness. We can also find 99 where the streamwise velocity

within the boundary layer becomes 99% of the free stream velocity, i.e. u  0.99 . The three
uuantities given so far may be obtained after the iteration has been converged.

The flow chart is shown in the following.

_________________________________________________________________________________________________________

Dr. Dolfred Vijay Fernandes, M.I.T., MAHE, Manipal


_________________________________________________________________________________________________________

Dr. Dolfred Vijay Fernandes, M.I.T., MAHE, Manipal

You might also like