# NUMERICAL METHODS IN CIVIL ENGINEERING 504 301

Document Sample

```					            PART 7
Ordinary Differential Equations
ODEs
Ordinary Differential Equations
Part 7
• Equations which are composed of an unknown
function and its derivatives are called
differential equations.
dv    c              v - dependent variable
g v
dt    m              t - independent variable

• Differential equations play a fundamental role in
engineering because many physical phenomena
are best formulated mathematically in terms of
their rate of change.
Ordinary Differential Equations
• When a function involves one dependent
variable, the equation is called an ordinary
differential equation (ODE).

•A partial differential equation (PDE) involves
two or more independent variables.
Ordinary Differential Equations

Differential equations are also classified as to
their order:
1. A first order equation includes a first derivative as
its highest derivative.

dy
- Linear   1st   order ODE            y  f (x )
dx
dy
- Non-Linear      1st   order ODE     f ( x, y )
dx
Ordinary Differential Equations

2. A second order equation includes a second
derivative.
2
d y      dy
- Linear 2nd order ODE         2
 p  Qy  f (x )
dx       dx
- Non-Linear 2nd order ODE
2
d y              dy
2
 p ( x, y )  Q ( x, y )  y  f ( x )
dx               dx
• Higher order equations can be reduced to a system
of first order equations, by redefining a variable.
Ordinary Differential Equations
Runge-Kutta Methods
This chapter is devoted to solving ODE of the
form:
dy
 f ( x, y )
dx
• Euler’s Method
dy
dy  f ( x, y )
 f(
dx
dx
solution
Solution :
Solution
yy1  yii  f ( xii , yii))h
ii1
y               y h
Runge-Kutta Methods

dy
 f ( x, y )
dx
Solution :
dy
yi 1  yi  (fx(,xy,)yi )  h
 f        i
dx
Solution :
yi 1  yi  f ( xi , yi )  h
Euler’s Method: Example
Obtain a solution between x = 0 to x = 4
with a step size of 0.5 for: dy
 2 x  12 x 2  20 x  8.5
3

dx
Initial conditions are: x = 0 to y = 1

ulerSolution: yi 1  yi  f ( xi , yi )  h
Solution :
y (0.5)  y (0 )  f (0,1).(0.5)
 1.0  8.5 x0.5  5.25
y (1.0 )  y (0.5)  f (0.5,5.25).(0.5)
 5.25  ( 2(0.5)3  12(0.5) 2  20(0.5)  8.5).(0.5)  5.875
y ( 2.0 )  y (1.0 )  f (1.0,5.875).(0.5)
 5.25  ( 2(1.0 )3  12(1.0 ) 2  20(1.0 )  8.5).(0.5)  5.125
Euler’s Method: Example
• Although the computation captures the general trend
solution, the error is considerable.
• This error can be reduced by using a smaller step size.
System of Ordinary Differential
Equations
dy1
   f1 ( x, y1 , y2 , y3 ,...... yn )
dx
dy2
   f 2 ( x, y1 , y2 , y3 ,...... yn ) The solution is
dx                                           finding y1, y2,y3,…yn
dy3
   f 3 ( x, y1 , y2 , y3 ,...... yn )
dx
......
dyn
   f 3 ( x, y1 , y2 , y3 ,...... yn )
dx
Euler’s Method: Example
Obtain a solution between x= 0 & 4 (step size of 0.5)
Initial conditions are: x = 0 ; y1= 4 & y2 = 6
dy1
 0.5 y1
dx
dy2
 4  0.3 y2  0.1 y1
dx
uler Solution: yi 1  yi  f ( xi , yi )  h
Solution :
y1 (0.5)  4  [0.5  (4)]  0.5  3
y2 (0.5)  6  [4  0.3(6 )  0.1(4 )]  0.5  6.9
X                     y1          y2
0                    4           6
0.5                  3           6.9
1                    2.25        7.715
1.5                  1.687       8.44525
2                    1.265628    9.094087
Improvements of Euler’s method
• A fundamental source of error in Euler’s
method is that the derivative at the beginning
of the interval is assumed to apply across the
entire interval.

• Simple modifications are available:
– Heun’s Method
– The Midpoint Method
– Ralston’s Method
Runge-Kutta Methods
• Runge-Kutta methods achieve the accuracy of a Taylor series
approach without requiring the calculation of higher derivatives.
y i 1  y i   (x i , y i , h )h
  a1k 1  a2 k 2        an k n         Increment function
(representative slope
a ' s  constants
over the interval)
k 1  f (x i , y i )
k 2  f (x i  p1h , y i  q11k 1h )
k 3  f (x i  p 3h , y i  q 21k 1h  q 22 k 2 h )

k n  f (x i  p n 1h , y i  q n 1k 1h  q n 1,2 k 2 h     q n 1,n 1k n 1h )
p ' s and q ' s are constants
Runge-Kutta Methods
•  Various types of RK methods can be devised by employing
different number of terms in the increment function as
specified by n.
1. First order RK method with n=1 is Euler’s method.

2. Second order RK methods:
yi 1  yi  (a1k1  a2 k 2 )h
k1  f ( x i , yi )
k 2  f ( xi  p1h, yi  q11k1h)
•   Values of a1, a2, p1, and q11 are evaluated by setting the
second order equation to Taylor series expansion to the
second order term.
Runge-Kutta Methods
• Three equations to evaluate the four unknowns
constants are derived:

a1  a2  1
1
a 2 p1        A value is assumed for one of the
2     unknowns to solve for the other
1     three.
a2 q11 
2
Runge-Kutta Methods
1           1
a1  a2  1, a 2 p1  , a2 q11 
2           2

• We can choose an infinite number of values for a2,there
are an infinite number of second-order RK methods.
• Every version would yield exactly the same results if the
solution to ODE were quadratic, linear, or a constant.
• However, they yield different results if the solution is
more complicated (typically the case).
 f ( x, y )
Solution :
dx
Runge-KuttaSolution : 1  Methods                  2
yi 1  yi  ( k1  k 2 )  h
Three of the most commonly used methods3are: 1 3
dy                                                     1
 f ( x, y )                     yi  1  yi  ( k1  k 2 )  h
dx 1  yi  (a1k1  a2 k 2 )dy k1  f ( xi , 2 i )
yi                             h                       y     2
 f ( x, y )
• Huen f ( x: , yi ) with a SinglekCorrector yi )=1/2)
k1  Method
Solution
dx 1  f ( xi , (a2 3             3
dy f ( x 1p h, y1  q Solution : f ( xi  h, yi  k1h )
i
k2
k 21  yi (i x, yk1  i k 2 )11h1hk  f ( x  h4 ( y  k 4 ) 
yi       f  ( 1)               k ) 2dy                  ), i 1h
i
dx              2      2        yi 1  yi  2f( x, y )
k h
k1  f ( xi , yi )              k  f
dx
• The Midpoint Method (a12= 1)( xi , yi )
Solution :
k 2  f ( xi  h ), ( yi  k1h )      Solution :
dyi 1  yi  k 2  h
y  f ( x, y )                                1

1
k 2  f ( xi  h, yi 1 k1h2 )
yi 1 2yi  ( k1  k 2 )  h
2
dx
k1  f ( xi , yi )                                   3    3
• Raltson’s: Method (a2= 2/3) k1  f ( xi , yi )
Solution
1 1 h2 y  1 k h )
yi 1  yi ( x(  1  , k 2 )  h 1 k 2  f ( xi  h, yi  k1h )
k2  f  i k                                         3       3
i
3 2 3             2                    4       4
y
Runge-Kutta Methods
• Heun’s Method:
Involves the determination
dy
of two derivatives for the                             f(xi+h,yi+k1h)
dy f ( x, y )                        f(xi,yi)
dx  ( the
interval fat x, y )initial point
dx                                         xi           xi+h
x
and the end point.
Solution ::
Solution
11 1 1                y
y                  h
yiyi11 yii  (( k1   k2 )k 2 )  h
                    k1                                                ea
22 2 2
k1  ff ( xi ,, yi ))
k       (x y
k 2  f ( xi  h ), ( yi  k1h ) 
1           i    i                                 Slope: 0.5(k1+k2)
k 2  f ( xi  h ), ( yi  k1h )                                        x
xi           xi+h
Heun’s Method - Example
Obtain a solution between x=0 & 4 (step size = 0.5) for:
dy
 2 x  12 x  20 x  8.5
3      2

dx
Initial conditions are: x = 0 to y = 1,use Heun’s method
Huen ' s Method : yi 1  yi  0.5(k1  k2 )  h

Chapter 25
Runge-Kutta Methods                    y

• Midpoint Method:
Uses Euler’s method t predict a
dy
value  f (at ,the midpoint of
dy of y x y )
dx f ( x, y )                                     f(xi+h/2,yi+k1h/2)
f(xi,yi)
the interval:
dx                                                                   x
Solution :                                   xi     xi+h/2
Solution :  k  h
yi  1  yi   2
 i 2)
yk1 fy( x ,ky  h
i
y
1       i   i
k1  f ( xi , yi )1      1                                          ea
k 2  f ( xi 1 h, yi 1 k1h )
k 2  f ( xi  2h, yi  2k1h )
2       2                           Slope: k2
x
Chapter 25         xi            xi+h
Midpoint Method (Example 25.6, P705)
Obtain a solution between x=0 & 4 (step size = 0.5) for:
dy
 2 x  12 x  20 x  8.5
3      2

dx
Initial conditions are: x = 0 to y = 1,use Midpoint method

Chapter 25
dy
Runge-Kutta Methods
dy  f ( x, y )                           y
dx  f ( x, y )
Ralston’s Method:
•dx
Solution :
Solution :
1    2                                     f(xi+ 3/4 h,
yi 1  yi  ( 1 1  2 2 )  h
k   k
yi 1  yi  ( k1  k 2 )  h
3     3                   f(xi,yi)
xi
yi+3/4k1h)

k1  f ( xi , yi )3    3                                xi+3/4h       x
k1  f ( xi , yi )
3      3
k 2  f ( xi  h, yi  k1h )              y

k  f (x     43 h, y  3 k h )
4                                             ea
2         i         i           1
4        4
Slope:
(1/3k1+2/3k2)
Chapter 25
xi          xi+h        x
Chapter 25   24
Runge-Kutta Methods
3. Third order RK methods
1
yi 1  yi  (k1  4k 2  k3 )h
1
yi 1  yi  6(k1  4k 2  k3 )h
where            6
 f(
k where x , y )
1         i   i
k1  f ( x i , yi )
1          1
k 2  f ( xi  h, yi  k1h)
12h, y  1 k2 )
k 2  f ( xi                1h
k3  f ( xi  2 , yi  k1h  2k 2 h)
i
h        2
k3  f ( xi  h, yi  k1h  2k 2 h)

Chapter 25
Runge-Kutta Methods
4. Fourth order RK methods
1
yi 1  yi  (k1  2k2  2k3  k4 )h
6
where
k1  f ( x i , yi )
1          1
k 2  f ( xi  h, yi  k1h)
2          2
1          1
k3  f ( xi  h, yi  k 2 h)
2          2
k3  f ( xi  h, yi  k3 h)
Chapter 25
Comparison of Runge-Kutta Methods

Use first to fourth order RK methods to solve the equation from
x = 0 to x = 4
Initial condition y(0) = 2, exact answer of y(4) = 75.33896

f ( x, y )  4e 0.8 x  0.5 y

Chapter 25
y
Implicit Versus Explicit
Euler’s Methods
• Explicit Euler’s Method:                                       h
dy                                            f(xi,yi)
 f ( x, y )                                                         x
dx                                                       xi       xi +h
yi 1  yi  f ( xi , yi )  h            y

• Implicit Euler’s Method:
f(xi+1,yi+1)
dy
 f ( x, y )                                 f(xi,yi)
dx                                                              h

yi 1  yi  f ( xi 1 , yi 1 )  h
Chapter 27
xi       xi +1
x
The Finite Difference Method
• The previous central divided differences are
substituted for the derivatives in the original
equation.

• Thus a differential equation is transformed into a
set of simultaneous algebraic equations that can
be solved by the methods described earlier.

Chapter 27
The Central divided differences                                       f(x)
f(x)                   f(xi+1)
f ( x i 1 )  f ( x i1 )
f (x i ) 
/
2  x
f(xi-1)             f(xi)
f ( x i 1 )  2f ( x i )  f ( x i 1 )                      f\(xi)
f (x i ) 
//
x 2                                          x         x       x
xi-1     xi           xi+1
f ( x i  2 )  2f ( x i 1 )  2f ( x i1 )  f ( x i2 )
f (x i ) 
///
2  x 3

f ( x i 2 )  4f ( x i1 )  6f ( x i )  4f ( x i1 )  f ( x i 2 )
f   ////
(x i ) 
x 4
Chapter 27
The Finite Difference Method-Example
Solve the following 2nd order ODE for initial conditions
of T(0) = T1 and T(L) = T2
d 2T
 h / (Ta  T)  0       Where Ta and h/ are constants.
dx 2
Solution:
• Using the divided differences equations:
d 2T Ti1  2Ti  Ti1

dx 2
x 2
• Substitute into the original DE for d2T/dx2:
Ti 1  2Ti  Ti 1
 h / (Ti  Ta )  0
x 2              Chapter 27
The Finite Difference Method-Example
• Now collecting terms gives:

 Ti1  (2  h /  x 2 )Ti  Ti1  h /  x 2  Ta
• The above equation is now applied at each of the interior
point.
• The first point and the last point are specified by the
boundary conditions.
• So if there is 5 points (including the first and the last
point) we will have 3 equations in 3 unknowns.

Chapter 27
The Finite Difference Method:Example
Solve the following 2nd order ODE for initial conditions
of y(0) = 5 and y(10) = -1.5, Use x = 2
d2y  dy
8 2 2 yx 0
dx   dx

• Using the divided differences equations:
dy yi 1  yi 1

dx      2  x
d 2 y yi 1  2 yi  yi 1

dx  2
x 2
Chapter 27
The Finite Difference Method: Example
• Substitute into the original DE for d2y/dx2 and dy/dx:
yi 1  2 yi  yi1    yi1  yi1
8                     2              yi  x i  0
x  2
2  x
• Now collecting terms gives and substitute for x =2:
1.5  yi1  5  yi  2.5  yi1  x i  0

• The above equations will be used to find the y’s at 2, 4,
6 and 8 where y(0) = 5 and y(10) = -1.5

Chapter 27
The Finite Difference Method: Example
xo  0      yo  5
x1  2      1.5  y 2  5  y1  2.5  y o  x1  0
x2  4      1.5  y 3  5  y 2  2.5  y1  x 2  0
x3  6      1.5  y 4  5  y 3  2.5  y 2  x 3  0
x4  8      1.5  y 5  5  y 4  2.5  y 3  x 4  0
x 5  10     y5  1.5

1.5  y 2  5  y1  14.5  0
1.5  y3  5  y 2  2.5  y1  4  0
1.5  y 4  5  y3  2.5  y 2  6  0
 5  y 4  2.5  y3  5.75  0
Chapter 27
The Finite Difference Method: Example
• Or in a matrix format:
  5 1.5 0   0   y1    14.5 
2.5  5 1.5 0   y    4 
                2           
 0 2.5  5 1.5  y3    6 
                             
0     0 2.5  5  y 4   5.75

• Now you can use for example Gauss elimination
to solve these equations.

Chapter 27
PART 8
Partial Differential Equations PDEs

Finite Difference Method
Finite Element Method
Chapter 29
Partial Differential Equations

Chapter 29
Partial Differential Equations
• A partial differential equation (PDE) involves two
or more independent variables. For example:

1. Laplace equation       2 f 2 f
 2 0
x 2
y
2. Diffusion equation            2 f f
k 2 
x    t
3. Wave equation        2 y 1 2 y
 2 2
x 2
c t
Chapter 29
Partial Differential Equations
1. Finite Difference Method

• Similar to the ODE, central divided differences
are substituted for the partial derivatives in the
original equation.

• Thus a partial differential equation is transformed
into a set of simultaneous algebraic equations that
can be solved by the methods described earlier.

Chapter 29
Partial Differential Equations
The Central divided differences
f      f i 1, j  f i 1, j                   f    f i , j 1  f i , j 1
                                             
x            2  x                            y            2  y
 f
2
fi 1, j  2 fi , j  fi 1, j             f
2
fi , j 1  2 fi , j  fi , j 1
                                                      
x 2
x    2
y 2
y  2

y
i,j+1

i-1,j      i,j i+1,j
i,j-1
x
Chapter 29
Finite Difference: Elliptic Equations

• Because of its simplicity and general relevance to
most areas of engineering, we will use a heated plate
as an example for solving elliptic PDEs.

Chapter 29                       42
Figure 29.1

by Lale Yurttas, Texas A&M
Chapter 29   43
University
Figure 29.3

by Lale Yurttas, Texas A&M
Chapter 29   44
University
The Laplacian Difference Equations/
 2T  2T
 2 0
x   2
y                           Laplace Equation
 2T Ti 1, j  2Ti , j  Ti 1, j             O[(x)2]

x 2                   x 2
 2T Ti , j 1  2Ti , j  Ti , j 1
                                     O[(y)2]
y   2
y      2

Ti 1, j  2Ti , j  Ti 1, j Ti , j 1  2Ti , j  Ti , j 1
                             0
x    2
y   2

x  y
Ti 1, j  Ti 1, j  Ti , j 1  Ti , j 1  4Ti , j  0       Laplacian difference
equation.
Holds for all interior points
Chapter 29
Figure 29.4

Chapter 29   46
• In addition, boundary conditions along the edges must be
specified to obtain a unique solution.
• The simplest case is where the temperature at the boundary is
set at a fixed value, Dirichlet boundary condition.
• A balance for node (1,1) is:
T21  T01  T12  T10  4T11  0
T01  75
T10  0
 4T11  T12  T21  0

• Similar equations can be developed for other interior points
to result a set of simultaneous equations.

Chapter 29                        47
• The result is a set of nine simultaneous equations with nine
unknowns:

4T11     T21              T12                                                       75
 T11    4T21    T13              T22                                             0
 T21     4T31                           T32                                50
 T11                      4T12    T22                   T13                       75
 T21              T12     4T22         T32              T23             0
 T31              T22          4T32                      T33     50
 T12                            4T13    T23              175
 T22                   T13     4T23    T33     100
 T32              T23     4T33    150

Chapter 29                                        48
Partial Differential Equations:
Example 1: Laplace Equation

 f  f
2          2
Laplace:                  2 0
x 2
y
Substitute with the Central divided differences and
assuming that x = y = h
2 f   fi 1, j  2 fi , j  fi 1, j   2 f   fi , j 1  2 fi , j  fi , j 1
                                       
x 2
h2                   y 2
h2

 f  f
 2  2 fi 1, j  fi 1, j  fi , j 1  fi , j 1  4 fi , j 
2          2
1
x 2
y  h
Partial Differential Equations:
Example 1: Laplace Equation

 f  f
 2  2 fi 1, j  fi 1, j  fi , j 1  fi , j 1  4 fi , j  0
2        2
1
x 2
y  h

y      Finite Difference Grid
At i and j:                                       i,j+1
1
i-1,j     i,j i+1,j
1         -4   1
i,j                              i,j-1
x
1
Partial Differential Equations:
Example 2: Diffusion Equation

 f
2
f
Diffusion:                  
y 2
x
Substitute with the Central divided differences and
assuming that x = y = h:
f   f i 1, j  f i 1, j             f   f i , j 1  f i , j 1
                                      
x           2h                       y            2h
2 f   fi 1, j  2 fi , j  fi 1, j        2 f   fi , j 1  2 fi , j  fi , j 1
                                            
x 2
h2                        y 2
h2
Partial Differential Equations:
Example 2: Diffusion Equation

 f     2
f
Diffusion:         
y 2
x
2 f    f
    
h
fi, j  fi, j1 fi1, j  2 fi, j  fi1, j  0
y 2
x   2
y    Finite Difference Grid
At i and j:                                      i,j+1
h/2
i-1,j     i,j i+1,j
-1         2      -1
i,j                            i,j-1
x
h/2

```
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
 views: 0 posted: 2/15/2013 language: Unknown pages: 52
How are you planning on using Docstoc?