0% found this document useful (0 votes)
15 views

Mm597 Advanced Numerical Methods in Engineers

This document discusses numerical methods for solving equations and inverting matrices. It begins by introducing different types of matrices, such as symmetric, upper and lower triangular, diagonal, and band matrices. It then discusses properties of matrix addition and multiplication. Methods covered for solving equations include Newton-Raphson, Newton's modified method, and the secant method. Homework problems are assigned involving using these methods to find roots of equations.

Uploaded by

yocomon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Mm597 Advanced Numerical Methods in Engineers

This document discusses numerical methods for solving equations and inverting matrices. It begins by introducing different types of matrices, such as symmetric, upper and lower triangular, diagonal, and band matrices. It then discusses properties of matrix addition and multiplication. Methods covered for solving equations include Newton-Raphson, Newton's modified method, and the secant method. Homework problems are assigned involving using these methods to find roots of equations.

Uploaded by

yocomon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 142

MM597

ADVANCED NUMERICAL
METHODS IN ENGINEERS

PROF.DR. NURİ YÜCEL


MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS
PROF.DR. NURİ YÜCEL

1. APPROXIMATE SOLUTIONS OF EQUATIONS

Sometimes, we encounter problems such as finding the roots of equations of the form

f x   0

1.1. Newton-Rapson Method

To find the roots of an equation given by the function f x   0 , let's open the Taylor

series at x  x 0 . So we can write it as a n x n  a n 1 x n 1  ...  a0

For the Fourier series expansion, it can be written as:

f  x   a n cosbn x   c n sin d n x   a n 1 cosbn 1 x   c n 1 sin d n 1 x   ...

x  x0 2
If we write Taylor Series expansion; f x   f x0   x  x0  f x0   f x0   ...
2!
In this series, at x  0 the McLauren series occurs. If we solve this equation, x 0 is the
closest value to root. Therefore, the 3rd term and after converge to 0.

=> f  x   f  x 0    x  x 0  f  x 0 

f x   0
0  f  x0    x  x0  f  x0 

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


1/141
f  x0  f xn 
=> x  x0  => xn1  xn  (Newton-Raphson Method)
f x0  f xn 

Example-1: Find the roots of the equation given by x2  2  0


x1, 2   2   1.414213562

f x   x 2  2
f x   2 x

x n2  2
=> x n 1  x n  (we can take any value as an first approximation)
2 xn
If we choose x 0  1 , as the first approximation value.

12  2
=> x1  1   1.5
2 *1
1.5 2  2
x 2  1.5   1.4166667
2 *1.5
1.41666672  2
x3  1.4166667   1.4142157
2 *1.4166667
1.4142157 2  2
x 4  1.4142157   1.4142143
2 *1.4142157
1.41421432  2
x5  1.4142143   1.4142136 * Solution
2 *1.4142143
x 6  1.4142136

Note: The found root converges to the root closest to the initially accepted value.

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


2/141
Example-2: Find the roots of the equation given by e
x2
 x 3  3. x  4  0

f x   e x  x 3  3.x  4
2

f x   2 x e x  3x 2  3
2

x 0  0.5 is chosen as a first approximation,

f x0  e 0.5   0.5  3 * 0.5  4


2
3
x1  x0   0.5 
f x0  2 * 0.5 * e 0.5   3 * 0.5  3
2
2

e 0.5   0.5  3 * 0.5  4


2
3
=> x1  0.5   0.8794467 bulunarak iterasyona devam edilir.
2 * 0.5 * e 0.5   3 * 0.5  3
2
2

e 0.8794467  0.8794467  3 * 0.8794467  4


2
3
x2  0.8794467   0.8515428
2 * 0.8794467 * e 0.8794467  3 * 0.8794467  3
2
2

e 0.8515428  0.8515428  3 * 0.8515428  4


2
3
x3  0.8515428   0.851049 *Çözüm
2 * 0.8515428 * e 0.8515428  3 * 0.8515428  3
2
2

x4  0.851049

The root found is the closest root to 0.5.

1.2. Newton's Modified Method

f x  u xn 
u x   => x n 1  x n 
f x  u x n 

f x n  * f x n 
u x n   1 
 f xn 2

In this method, the solution can be reached more easily by reducing the number of
iterations. However, it is not preferred because the quadratic derivative of the function is
used during the solution.

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


3/141
1.3. Secant Method

f x n   f x n 1 
If we define the derivative; f  x   lim
xn  xn 1 0 x n  x n 1

When we apply this definition to the Newton-Rapson model, we obtain the Secant method
equation:

f xn 
=> x n 1  x n 
 f xn   f xn1  / xn  xn1 

f  x n  *  x n  x n 1 
x n 1  x n 
 f xn   f xn1 

In this method, we do not take the derivative of the function, but instead of one initial
value, two initial values must be chosen.

Homework:

1) Find 5
83  f x   x 5

 83 ; by using all methods with precision up to the 6th digit.

2) Find the root of the equation f  x   x  2e


x
2
* x 3  e 3 x by taking initial values as
x0  1 and x 1  2 (by using all methods).

3) Find the root of the equation 


sin x 3  2   1
x
by taking initial values as x 0  1 and x1  3

(by using all methods).

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


4/141
2. SOLUTION OF LINEAR EQUATIONS AND INVERSION OF THE MATRIX

 c11 c12 c13 c14 


c c c23 c24 
C   21 22 4*4 matrix
c31 c32 c33 c34 
 
c41 c42 c43 c44 

c11, c22 , c33 , c44 diagonal terms

If Cij  C ji , then this matrix is a symmetric matrix

c11 c12 c13 c14 


0 c c23 c24 
C 22
This matrix is called the upper trigonal matrix.
0 0 c33 c34 
 
0 0 0 c44 

In the opposite case, it is called the lower trigonal matrix.

c11 0 0 0
0 c 0 0 
C 22
Diagonal matrix
0 0 c33 0
 
0 0 0 c44 

1 0 0 0
0 1 0 0
I  Unit matrix
0 0 1 0
 
0 0 0 1

 c11 c12 0 0
c c c23 0 
C   21 22 Band type matrix [Tri-diagonal matrix]
 0 c32 c33 c34 
 
0 0 c43 c44 

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


5/141
Some Matrix Properties

1) The sum of two matrices (such as A and B) is defined as long as their dimensions are
the same.

S  A B  B  A
sij  aij b ij b ij  aij

1 2 2 1 3 3
0 1  4 0  4 1
     
3 0 1 3 4 3

2) The difference of two matrices of the same size,

S  A  B  B  A
1 2 2 1   1 1 
0 1    4 0     4 1 
     
3 0 1 3  2  3

3) In multiplication of two matrices, if the number of columns in the first matrix is equal
to the number of rows in the second matrix, the multiplication operation is defined.

S  A* B  B * A
1 2 1 * 2  2 *1 1 *1  2 * 0 4 1
0 1   2 1    0 * 2  1 * 1 0 * 1  1 * 0   1 0 
  1 0     
1 0   1 * 2  0 *1 1 *1  0 * 0 2 1
   

n
General formula; Pij   aik bkj
k 1

4) When a matrix is multiplied by the unit matrix, the result is the matrix itself.
AI  A  IA

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


6/141
C.C 1  I and C 1   C (For the inverse to
1
5) If the inverse of the C matrix C-1 exists,

happen, the matrix must be a square matrix and its determinant must be different from
"0")

1
cofactor of Cij  1i  j M ji
C 
ij 
C C

8 0 1

Example-3: Find the inverse of C  3  2 1

 
1 4 0

If we calculate the determinant,

8 0 1 8 0
C  3  2 1 3  2  8 * 2 * 0  0 *1 *1  1 * 3 * 4  1 * 2 *1  8 *1 * 4  0 * 3 * 0
1 4 0 1 4

8 0 1 8 0
C  3  2 1 3  2  12  30  18
1 4 0 1 4

2 1
1*
c111 
 1 11
M 11

4 0

4

4
C  18  18 18

0 1
 1*
c121 
 11 2
M 21

4 0

4

4
C  18  18 18

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


7/141
0 1
1*
c1

 1 M 31
13

2 1

2

2
13
C  18  18 18

3 1
 1*
1
c21 
 1 1 2
M 12

1 0

1

1
C  18  18 18

8 1
1*
1
c22 
 1 2 2
M 22

1 0

1

1
C  18  18 18

8 1
 1*
1
c23 
 1 23
M 32

3 1

5

5
C  18  18 18

3 2
1*
1
c31 
 1
31
M 13

1 4

14

14
C  18  18 18

8 0
 1*
1
c32 
 1 3 2
M 23

1 4

 32 32

C  18  18 18

8 0
1*
1
c33 
 133 M 33 
3 2

 16 16

C  18  18 18

 4  4  2
1 
C 1
  1 1 5 
18
 14 32 16 

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


8/141
n

  1
k j
6) The determinant of a matrix of n*n dimensions is C  ckj M kj . In this formula,
j 1

a solution can be made by considering the desired row or column in the matrix. Selecting
the row or column with the highest number of "0" is convenient for analysis.

 3 1 16  8
 0 1 14 0 
Example-4: Calculate the determinant of C   
0 3 0 1
 
 0 14 6 0 
The analysis will be made by considering the 1st column with the maximum number of “0”.

 3 1 16  8
 0 1 14 0  1 14 0 1 16  8
    1  3 3 0 1   1 0 3 0 1   1 0...
11 1 2 1 3
C
0 3 0 1
  14 6 0 14 6 0
 0 14 6 0 

1 14 0
 1 14 
1  3 1 1   3 1 * 1 * 6  14 *14  3 * 6  196  570
23
=>  3 3 0
 14 6 
14 6 0
Matrix Representation of Systems of Linear Equations

c11 x1  c12 x2  c13 x3  c14 x4  r1

c21 x1  c22 x2  c23 x3  c24 x4  r2

c31 x1  c32 x2  c33 x3  c34 x4  r3

c41 x1  c42 x2  c43 x3  c44 x4  r4

 c11 c12 c13 c14   x1   r1 


c c24   x2  r2 
=>  21 c22 c23

c31 c32 c33 c34   x3   r3 
    
c41 c42 c43 c44   x4  r4 

C. X  R

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


9/141
Note: The determinant of a matrix whose two rows or two columns are the same is always
0.

The classical solution of this system of equations is done by Cramer's rule.

detC k 
Xk 
detC 

C k ; is the resulting matrix with the kth column replaced with R. The reason for not using
this method is the total number of operations consisting of addition, subtraction,

multiplication and division operations for each calculation. Approximately  


O N4
operation is needed.

C. X  R
=> C 1 .C. X  C 1 .R
I . X  C 1 .R
X  C 1 .R

Example–5: Solve the following system of equations using Cramer's rule.

x1  3 x 2  4 x3  1

 x1  x 2  3 x3  14

x 2  3 x3  5

1  3  4 x1 1
1 1  3 x 2  14
0 1  3 x3 5

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


10/141
If we calculate its determinant,

1 3 4 1 3
1 1  3 1 1  1  12  13
0 1 3 0 1

1 3 4 1 3
14 1  3 14 1
5 1 3 5 1  117
x1    9
13 13

1 1 4 1 1
 1 14  3  1 14
0 5 3 0 5  10
x2  
13 13

1 3 1 1 3
1 1 14  1 1
0 1 5 0 1  25
x3  
13 13

GAUSS VE GAUSS-JORDAN ELEMINATION METHODS

c11 x1  c12 x2  c13 x3  c14 x4  r1

c21 x1  c22 x2  c23 x3  c24 x4  r2

c31 x1  c32 x2  c33 x3  c34 x4  r3

c41 x1  c42 x2  c43 x3  c44 x4  r4

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


11/141
 c11 c12 c13 c14   x1   r1 
c c24   x2  r2 
=>  21 c22 c23

c31 c32 c33 c34   x3   r3 
    
c41 c42 c43 c44   x4  r4 

C. X  R

If we divide the first row of the matrix by c11 ,


 1 c12 
c13    x1   r1
c14
c c24   x2  r2 
=>  21 c22 c23

c31 c32 c33 c34   x3   r3 
    
c41 c42 c43 c44   x4  r4 

After this step, we will multiply the first row by c21 and subtract from the second row,
multiply the first row by c31 and subtract from the third row and multiply the first row by

c41 and subtract from the fourth row, the matrix becomes:

1 
c12  c14
c13    x1   r1
0 
c22    x2  r2
 c24
c23
=>      
0 
c32  c34
c33    x3   r3
    
0 
c42  c44
c43    x4  r4

If we repeat this sequence of operations for the second row (Dividing second row by  ,
c22
 and subtracting from third row; multiplying second row by
multiplying second row by c32

 and subtracting from fourth row) the matrix becomes:


c42

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


12/141

1 c12 
c13    x1  r  
c14
0 1 1

c23    x2   r 
c24
=>     2
0 0 
c33    x3   r 
c34
    3 
0 0 
c43    x4   r 
c44  4

When the same operations are done for the 3rd and 4th rows,


1 c12  c14
c13    x1   r1
0 1    x2  r2
 c24
c23
=>      
0 0    x3   r3
1 c34
    
0 0    x4  r4
0 c44


1 c12    x1   r1
 c14
c13
0 1    x2  r2
 c24
c23
=>      
0 0    x3   r3
1 c34
    
0 0 0 1   x4  r4

=> x 4  r4
 .x4  r3
x3  c34 => x3  r3 c34
 .x4

 .x3  c24
x2  c23  .x4  r2 => x2  r2  c23
 .x3  c24
 .x4

 .x2  c13
x1  c12  .x3  c14
 .x4  r1 => x1  r1  c12
 .x2  c13
 .x3  c14
 .x4

When the solution is made with the Gauss-Jordon method, the following matrix system is
formed,

1 0 0 0  x1   r1
0
 1 0 0  x 2  r2
=> 
0 0 1 0  x 3   r3
    
0 0 0 1  x 4  r4

In this method, the number of operations is 1.5 times higher than the Gaussian elimination
method. For this reason, the Gaussian elimination method is preferred.

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


13/141
3 1  1  x1   2 
    
Example: 1 4 1 x 2  12 Solve the equation with Gauss and Gauss-Jordan
    
2 1 2   x3  10
method.
If we start the solution with the Gauss method,

Step 1. Operations related to the first row,

1 1 / 3  1 / 3  x1  2 / 3
1 4 1   x2    12 

2 1 2   x3   10 

1 1 / 3  1 / 3  x1   2 / 3 
=>
0 11 / 3 4 / 3   x   34 / 3
  2   
0 1 / 3 8 / 3   x3  26 / 3

Step 2. Operations related to the second row,

1 1 / 3  1 / 3   x1   2 / 3 
=>
0 1 12 / 33  x   34 / 11
  2   
0 1 / 3 8 / 3   x3   26 / 3 

1 1 / 3  1 / 3   x1   2 / 3 
=>
0 1 4 / 11   x 2    34 / 11 

0 0 84 / 33  x3  252 / 33

Step 3. Operations related to the third row,

1 1 / 3  1 / 3  x1   2 / 3 
=>
0 1 4 / 11  x   34 / 11
  2   
0 0 1   x3   3 

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


14/141
x3  3

4 34
x 2  x3  => x2  2
11 11
1 1 2
x1  x2  x3  => x1  1
3 3 3

The final set of equations to be obtained when solving with Gauss-Jordan is below,

1 0 0  x1  1
0 1 0   x    2 
  2   
0 0 1  x3  3

Homework:

 b1 c1 0 0 0 0 0   x1   r1 
a b2 c2 0 . . 0   x 2   r2 
 2
0 a3 b3 c3 . . 0   x3   r3 
    
1)  0 . . . . . 0   .    .  Develop an algorithm for this system
0 . . . . . 0  .   . 
    
0 . . a n 1 bn 1 c n 1   x n 1  rn 1 
0 bn   x n   rn 
 0 0 0 0 an
that can be solved using the Gaussian elimination technique.

 3  5 47 20   x1  18 
11 16 17
 10   x 2  26
2)  Solve the system of equations.
56 22 11  18  x3  34
    
17 66  12 7   x 4  82
Results: x1  1.076888 , x2  1.99028 , x3  1.474477 and x4  1.906078

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


15/141
3) NUMERICAL INTEGRATION

3.1) Rectangles Integration Rule

f x dx   f c j 1 x j  x j 1 
b n


a j 1

ba
h (pitch range)
n

 f x dx  h f c   f c   ......  f c 
a
0 1 n 1

If c j 1  x j 1 ,

 f x dx  h f x   f x   f x   ......  f x 
a
0 1 2 n 1

x j  x j 1
If c j 1  , (that is generally used)
2

 f x dx  h f c   f c   ......  f c 
a
0 1 n 1

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


16/141
The order of error that occurs as a result of the integral solved in this method,

m If minimum value of f x 

M If maximum value of f x  ; the error, is in range of

mb  a  M b  a 
3 3

2
 
12n 12n 2

If we interpret this formula; It is seen that the error decreases as the number of intervals

1 / n 2 , in other words, when h (step interval) increases, the error also increases.

x dx  ? , for n=2, obtain the approximate result of the integral using the
2
Example:
1

rectangular integration method.

4
x3 4
 x dx  3  21
2

1 1

For n  2,
x j  x0  j.h , j  0,1,2,......, n

b  a 4 1
h   1.5
n 2

x j  1 1.5 j , j  0,1,2

x0  1

x1  2.5
x2  4

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


17/141
4
=> x
2
dx h f c0   f c1 
1

x j  x j 1
c j 1 
2
x1  x0 1  2.5
c0    1.75
2 2
x 2  x1 2.5  4
c1    3.25
2 2

 
4

x dx h f c0   f c1   1.5 1.75  3.25  20.4375


2 2 2

As the number of steps, n is increased, the process gets closer to the correct result.
4

x
2
n dx
1

2 20.4375
4 20.859375
10 20.9775
50 20.9991
100 20.999775

 /2
Example:
x 2
2

 e sin x  1 dx  ? 
0

 /2
Solution; for n  100 e
 x2
 
sin x 2  1 dx  0.7484696904 and
0

 /2
For n  200 e
 x2
 
sin x 2  1 dx  0.748468314
0

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


18/141
3.2) Trapezoidal Integration Rule

=> f ( x) 
1
 y0  y1 x1  x0   1  y1  y2 x2  x1   ......  1  yn1  yn xn  xn1 
2 2 2
ba
h
n

Formula of trapezoidal integration rule


b

 f x dx  2 hy  2 y1  2 y 2  ......  2 y n 1  y n  *


1
o
a

Error, E
b  a  f c h 2 acb
12

 
b

 f x dx  2 hy  2 y1  2 y 2  ......  2 y n 1  y n   O h 2


1
o
a

Example: For n=2 by using trapezoidal integration rule, find the approximate value of
4

x dx  ? .
2

For n  2,
x j  x0  j.h , j  0,1,2,......, n

b  a 4 1
h   1.5
n 2

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


19/141
x j  1 1.5 j , j  0,1,2

x0  1 x1  2.5 x2  4

 f x dx  2 h yo  2 y1  y 2   2 1  2.2.5  4 
4
1 2 1. 52 2

4
=>  f x dx  22.125
1

As the number of steps is increased, the process gets closer to the correct result.

x
2
n dx
1

2 22.125
4 21.28125
10 21.045
50 21.00180
100 21.00045

 /2

 sinx dx  ?
2
Example:
0

n Rectangular Rule Trapezoidal Rule


2 0.89293919 0.69947699
4 0.84420228 0.79620809
10 0.83064857 0.82305960
50 0.82821727 0.82791446
100 0.82814156 0.82806586

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


20/141
3.3) Simpson Integration Rule

In this method, each interval divided between a and b is


also divided into two within itself. It is tried to approach
the solution by defining a quadratic curve passing
thorough each point. Here, as we can see in the error
expression, the error rates decrease with respect to
order of h4.

=>

 f  x dx   y  4 y  2 y  4 y  2 y  ...... 2 y  4 y  y   Oh 


b
h 4
0 1 2 3 4 n2 n 1 n
a 3

Error, E
b  a  f c .h 4  Oh 4  acb
180

x dx  ? , for n=2, obtain the integral using Simpson's integration method.


2
Example:
1

For n  2,
x j  x0  j.h , j  0,1,2,......, n

b  a 4 1
h   1.5
n 2

x j  1 1.5 j , j  0,1,2

x0  1

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


21/141
x1  2.5
x2  4

 f x dx  3 y  4 y1  y 2 
h
0
a

 
b

 f x dx  1  42.5  4 2
1.5 2 2

a
3

4
=>  f x dx 21
1

1
dx
Example: 
0 2 sin 2 x
 ? Find the result of the integration according to all three rules?

Solution:
n Rectangular Rule Trapezoidal Rule Simpson’s Rule
2 0.76260967 0.77253221 0.7655945
10 0.76582073 0.76620815 0.76594906
50 0.76594477 0.76596025 0.76594992
100 0.76594864 0.76595251 0.76594993

3.4) Romberg Integration Rule

This rule will not be used in this course.


HOMEWORK
 
1)  sinx dx  ?
0
2)  ln5  4. cosx dx  ?
0

lnx 
0.8 1

 e dx  ?  x  1 dx  ?
x 2
3) 4)
0 0.1

By choosing n=100, solve the integrals using all the methods.

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


22/141
3.5) Gauss-Legendre Quadrature and Integration
1

The aim of the method, to calculate the integral  f x dx . In the formula given below,
1
xk

and wk values are gauss quadratures. x k ’s represent the roots of the Legendre polynomial

and the wk 's represent the weight functions dependent on these roots. The limits of integral

are between -1 and 1.

*
1 n

 f x dx  w1 . f x1   w2 . f x2   ......  wn f xn    wk . f xk 


1 k 1

Legendre Polynomials,

Pn x  
1 dn
n
2 .n! dx n

x2 1
n
 can be calculated by “Rodriguez Formula”.

P0  x   1

P1 x   x

P2 x  
1 2
2

3x  1 
P3 x  
1 3
2

5 x  3x 
P4 x  
1
8

35x 4  30 x 2  3 
.
.

If two previous Legendre polynomials are known, the remaining Legendre polynomials can
be calculated by the "recurrence relation".

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


23/141
Recurrence relation : n  1.Pn1 x   2n  1x.Pn x   n.Pn1 x   0

If this formula is applied for n=1,

2.P2  x   3 x.P1  x   P0  x   0

=> 2.P2  x   3 x.P1  x   P0  x   3 x.x  1

3x 2  1
=> P2  x  
2

wk 

2 1  xk
2

n Pn1 xk 
Weight Function : 2 2

Example: Find the Gauss quadratures for n=3.

P3 x  
1 3
2

5 x  3x  0  => 5 x 3  3x  0

3
=> x1  0 x 2,3    0.7745966
5

w1 

2 1  02  
2

8
 0.888889
3 P2 0 
2 2 2
9
1
 
9  3.0 2  1  
2 


2 1  0.7745966 2
w2  2 

2 1  0.7745966 2 
 0.555556

3 P2 0.7745966 
2 2
1
9 3 * 0.7745966  1 
2 
 
2 
w3  w2

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


24/141
Example: Find the Gauss quadratures for n=2.

P2 x  
2

1 2
3x  1  0  => x1, 2  0.577350

wk 

2 1  x k2 
n 2 Pn 1 x k 
2

  1 2 
2 1    
  3  
w1  1
 
2 & w2  w1
1
22  
 3

----------ooooooooooooo-----------

The error equation that occurs in the solutions made with the Gauss-Legendre formulas is
as follows,

2 2 n 1 n!
4
Rn  f 2 n  c  , 1  c  1
2n  12n! 2

If the limits of the integral are not between -1 and 1, but between two different values
such as a and b, the following formulas must be used to calculate the integral.

ba n
*
b

 f  y dy    wi . f  y i   Rn
a  2  i 1

ba ba
yi    xi   
 2   2 

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


25/141
Error Function ; Rn 
b  a 2n1 n!4 f 2 n  c 
2n  12n!3

1
Example: Calculate the integral x
2
cosx dx for n  3 by using Gauss-Legendre
1

formulas.

P3 x  
2

1 3
5 x  3x  0  => 5 x 3  3x  0

3
=> x1  0 & x 2,3    0.7745966
5

w1 

2 1  02  
2

8
 0.888889
3 P2 0 
2 2 2
9
1
 
9  3.0 2  1  
2 

w2 

2 1  0.7745966 2


2 1  0.7745966 2 
 0.555556

32 P2 0  & w3  w2
2 2
1
9  3 * 0.7745966  1 
2 
 
2 
1

x
2
cosx dx  w1 . f x1   w2 . f x2   w3 . f x3 
1

 
1

x cosx dx  0.888889 * 0  0.555556 * 0.77459 * cos0.77459 


2 2

1


0.555556 *  0.77459 * cos 0.77459
2

1

x
2
cosx dx  0.47650
1

Check by analytical solution;

 x cosx dx  2 x * cosx   x  2* sin x  1  0.47830


1 1
2 2

1

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


26/141
2

 e dy n  3 by using Gauss-Legendre formulas.


y
Example: Calculate the integral for
0

20 3
2

0    wi . f  y i 
y
e dy
 2  i 1

ba ba
yi    xi     xi  1
 2   2 
y1  x1  1  0  1  1
y 2  x2  1  0.77459  1  1.77459
y 3  x3  1  0.77459  1  0.22541

20 3
 
2
=> 0 e dy   2 
y
wi . f  y i   1 0.888889 * e1  0.555556 * e1.77459  0.555556 * e 0.22541
i 1

e dy  6.388853
y

2 2
 e dy  e 0  e  e  6.389056
y y 2 0
Check by analytical solution;
0

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


27/141
3.6) Gauss-Chebysev Integration Formula

f x 
1


1 1 x2
dx , The integral has singular points in x  1 . if we try to solve

it with normal numerical methods, the integral goes to


infinity at these points. In this case we use Chebysev
formulas,

Tn  x   cosn.arccos x i 

f x  
1 n
=>  dx   wi * f  x i   Rn , wi 
1 1 x2 i 1 n

We can calculate x i such that

If Tn  x   cosn.arccos x i   0 ,

n * arccos xi  
2i  1 becomes.
2

=> arccos xi 
2i  1
2n
 2i  1 
cosarccos xi   cos 
 2n 

 2i  1 
=> xi  cos 
 2n 


Error function, Rn  f 2 n  c  , 1  c  1
2n!*2 2 n 1

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


28/141
1
dx
Example: Calculate the integral 
1 1 x2
for n  3 by using Gauss-Chebysev integration

formula.

 2i  1 
xi  cos 
 2n 

i 1  2 *1  1    3
For x1  cos   cos  
 2*3  6 2

i2  2 * 2  1   
For x2  cos   cos   0
 2*3  2

i 3  2 * 3  1   5  3
For x3  cos   cos   
 2*3   6  2

 
w1  w2  w3  
n 3
where f x   1 ,

1
 w1 * f x1   w2 * f x 2   w3 * f x3 
dx
=> 
1 1 x2
1


dx
 1  1  1  
1 1 x2 3

1
dx 1   
Check by analytical solution ;   arcsin x       
1 1 x2 1 2  2

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


29/141
1
x4
Example: Calculate the integral 
1 1 x2
dx for n  3 by using Gauss-Chebysev

integration formula.

f x   x 4

 2i  1 
xi  cos 
 2n 

 2 *1  1    3
For i 1 x1  cos   cos  
 2*3  6 2
 2 * 2  1   
For i2 x2  cos   cos   0
 2*3  2

 2 * 3  1   5  3
For i 3 x3  cos   cos   
 2*3   6  2

 
w1  w2  w3  
n 3

1
x 4 dx
=>   w1 * f x1   w2 * f x 2   w3 * f x3 
1 1 x2

  3    3
4 4
1
x 4 dx  3
   0  
4  
1 1 x2 3  2  
 2   8
 

NOTE: If the limits of integral are between a and b, the formula becomes

f y ba n
b

 dy    wi * f  yi   Rn
a  y  a b  y   2  i 1

ba ba
yi    xi   
 2   2 

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


30/141
3.7) Gauss-Laguerre Formula

 n

 e f x dx   wi * f xi   Rn
x

0 i 1

Laguerre functions , Ln x   e x 
d n x n
e x 
dx n

Weighting function , wi 
n!2
xi Ln xi 
2

Error function , Rn 
n! 2 n 
2
f c 
2n!


Example: e
x
sinx dx  ?
0

f x   sinx 

 n

 e sinx dx   wi * sinxi 


x

0 i 0

n 2 6 10 14
n

 w * sinx 
i 0
i i 0.43 0.50005 0.500002 0.500000

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


31/141
3.8) Gauss-Hermite Formula

 n

e
 x2
f x dx   wi * f xi   Rn
 i 1

Where x i ’s are the roots of Hermite functions.

H n x    1 e x
n 2

dx n
e  
d n  x2

2 n 1 n!  n!  2 n 
wi  and Rn  f c 
H n xi 2 2 n 2n !

 e sin x dx  ?
x 2 2
Example:


 n

 e sin xdx  wi * sin xi 


x 2 2
2
=>
 i 1

n 2 4 6 8 10
n

 w * sin x 
i 0
i
2
i 0.748 0.5655 0.560255 0.560202 0.560202

HOMEWORKS

1 
sin  x 
 x dx  ? e dx  ?
x
1) 2)
0 0

   1
 x  

e e
x
3) x dx  ?
4
4)  x
dx  ?
0 0

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


32/141
  1
 x2 
5) e
 x2
cosx dx  ? 6) e x2
dx  ?
 

cos x  1 x2
1 1
7) 
1 1 x2
dx  ? 8) 
1 1 x2
dx  ?

3.9) Multiple Integrals

b d
I   f x, y .dy.dx
x  a y c

The integral can be separated two parts,


d b
If we say F x   
y c
f x, y .dy , then I integral becomes I   F x .dx
xa
.

d c m
 w j * f x, y j 
d
=> F x    f  x , y .dy  
y c  2  j 1

d c d c
yj   x j   
 2   2 

d c m
w j * f x, y j .dx
b b
=> I  F x .dx 
xa
  2 
xa  j 1

m
 d  c  b  a  n
I    wk   w j * f xk , y j  
 2  2 k 1  j 1 

ba ba
xk    xk   
 2   2 

b  a d  c   
   wk * w j * f xk , y j 
n m
I
4 k 1  j 1 

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


33/141
2 1
dy.dx
Example: A  
x  0 y  1 x  y
2 2
 ? Find the approximate value of integral by dividing the

integrals by x and y into two parts.

2 1
dy.dx 2  01   1 2 2 w * w * 1
A   2 2  
x  0 y  1 x  y xk2  y 2j
k j
4 k 1 j 1

ba ba
xk    xk     xk  1
 2   2 
yj  xj
If we assume m  n  2,

For integral depends on x,

x1  0.57735 => x1  x1  1  0.57735  1  1.57735


x2  0.57735 => x2  x2  1  0.57735  1  0.42265
w1  w2  1

For integral depends on y,

x1  0.57735 => y1  x1  0.57735

x2  0.57735 => y 2  x 2  0.57735

w1  w2  1

2 1
dy.dx 2  01   1 2 2 w * w * 1
A   2 2  
x  0 y  1 x  y xk2  y 2j
k j
4 k 1 j 1

2
 1 1   1 1 1 1 
A    2  2    2
  2  2  2 
k 1  x k  y1 x k  y 22   x1  y1 x1  y 2 x 2  y1 x 2  y 2
2 2 2 2 2

=> A  4.61538

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


34/141
1x 2
Example: A    x. y.e  y dy.dx  ? Find the approximate value of integral by dividing the
00

integrals by x and y into two parts.


1
 x  y2 
A   x  y.e dy dx
0 0 
x 1
If I  x    y.e dy A   x.I  x .dx
y 2
=> then “A” integral becomes
0 0

ba 2
x
I x    y.e  y dy    wi * f  y i 
2

0  2  i 1

x1, 2  0.57735 and w1  w2  1

ba ba  x0  x0  x x


yi    xi    => yi    xi       xi 
 2   2   2   2  2 2
x
y1  0.57735  x  0.788675x
2 2

y2 
x
 0.57735  x  0.211325x
2 2

=> I x  
x
1* f  y1   1* f  y 2 
2

I x  
x
2

0.788675.x* e 0.788675x   0.211325.x* e 0.211325x 
2 2

 
1
A   0.394338.x 3 .e 0.622. x  0.105663.x 3 .e 0.04466. x dx
2 2
=>
0

ba ba 1 0   1  0  xi 1


xi    xi    => xi    xi    
 2   2   2   2  2 2

0.57735 1
x1    0.788675
2 2

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


35/141
 0.57735 1
x2    0.211325
2 2
ba 2
A  w j * g x j 
 2  j 1

=> A
1
2
0.394338.0.788675 .e 0.622*0.788675  0.105663.0.788675 .e 0.04466*0.788675 
3 2
3 2

1
2
0.394338.0.211325 .e 0.622*0.211325  0.105663.0.211325 .e 0.04466*0.211325
3 2
3 2

=> A  0.0932

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


36/141
4) NUMERICAL DIFFERENTIAL

4.1) Forward and Backward Differences

If we expand the f  x  function to a Taylor series at a distance h from x, we get,

h2 h3
f x  h   f x   h. f x   f x   f x   ...
2! 3!

In this case f x  can be obtained such that,

f x  h   f x  h h2
=> f x    f x   f x   ...
h 2 6

f x  h   f x 
=> f x    Oh  (Forward Difference Formula)
h

f x  => fi

f x  h  => f i 1

f i 1  f i
=> f i   Oh  (Forward Difference Formula)
h

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


37/141
If we repeat the above operations for a point at a negative distance of h from the
selected point x, we get

h2 h3
f x  h   f x   h. f x   f x   f x   ...
2! 3!

f x   f x  h  h h2
f x   
 f x  f x   ...
h 2 6

f x   f x  h 
=> f x    Oh 
h

f i  f i 1
=> f i   Oh  (Backward Difference Formula)
h

Operators

 f
f i  f i 1  f i => f i  i  Oh  (Forward Difference Formula)
h

 f
f i  f i  f i 1 => f i  i  Oh  (Backward Difference Formula)
h

In order to calculate the quadratic forward difference formula, the solution is obtained by

opening the f x  h and f x  2h functions to the Taylor series.

h2 h3
2/ f x  h   f x   h. f x   f x   f x   ...
2! 3!

f x  2h   f x   2h. f x  
2h 
2
f x  
2h 
3
f x   ...
2! 3!

2 f  x  h   f  x  2h   f  x   h 2 f  x   h 3 f  x   ...

f  x  2h   2 f  x  h   f  x 
=> f x    hf x   ...
h2

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


38/141
f i  2  2 f i 1  f i
f i  Oh  (Quadratic Forward Difference Formula)
h2

f i  2 f i 1  f i  2
f i  Oh  (Quadratic Backward Difference Formula)
h2

2 f i
2 f i  f i  2  2 f i 1  f i => f i  Oh 
h2

2 fi
 2 f i  f i  2 f i 1  f i 2 => f i  Oh 
h2

4.2) Central Differences

f x  h   f x  h 
f x    tan 
2h

h2 h3
f x  h   f x   h. f x   f x  
 f x   ... (1)
2! 3!
h2 h3
f x  h   f x   h. f x   f x   f x   ... (2)
2! 3!

2h 3
f x  h   f x  h   2h. f x   f x   ...
3!

f x  h   f x  h  h 2
=> f x    f x   ...
2h 6

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


39/141
f x  h   f x  h 
=> f x  
2h
 O h2  

If we add formulas (1) and (2) side by side,

 
2
f x  h   f x  h   2 f x   f x   O h 4
2h
2!

f x  h   2 f x   f x  h 
=> f x   2
 O h2  
h


 f  f i 1
f i  i 1
2h
 O h2  
Central Difference Formula

 f  2 f i  f i 1
f i  i 1
h 2
 O h2  

4.3) Generalization of Difference Formulas

dn f n f j
  Oh  Forward Difference Formula
dx n xj
hn

dn f n f j
  Oh  Backward Difference Formula
dx n xj
hn


n f n  n f n

 
n
d f j j
 2 2
 O h2 , if n is even
dx n xj
2h n

Central Difference Formula

 n f n1  n f n1
 
n
d f j j
 2 2
 O h2 , if n is odd
dx n xj
2h n

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


40/141
General Formulas,

n f j  n 1 f j 1  n1 f j

 n f j   n 1 f j   n 1 f j 1

Example: Calculate the central difference formula for n  2 .

2 f 2  2 f 2

 
2
d f j j
 2 2
 O h2
dx 2 xj 2h 2

d2 f
dx 2

 2 f j 1  2 f j 1
2h 2
  f
 O h2 
j 1  
 f j  f j  f j 1
2h 2
  Oh 
2

xj

d2 f

f j 1  
 f j  f j  f j 1  f j 1  f j  f j  f j 1   Oh 
2

dx 2 xj 2h 2

d2 f

f j 1  2 f j  f j 1   Oh 
2

dx 2 xj h 2

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


41/141
Example:

x 0 1 2 3 4 5

f x  1 0.5 8.0 35.5 95 198.5

Find the third derivative of the function f(x) at x  0, 1, 2 using the forward difference
formulas.

Since the step interval is 1, it is taken as h=1 in the expressions.

i xi fi f i  f i 1  f i 2 f i  f i 1  f i 3 f i  2 f i 1  2 f i

0 0 1 0.5  1  0.5 7.5   0.5  8 20  8  12


1 1 0.5 8.0  0.5  7.5 27.5  7.5  20 32  20  12
2 2 8.0 35.5  8.0  27.5 59.5  27.5  32 44  32  12
3 3 35.5 95  35.5  59.5 103.5  59.5  44
4 4 95 198.5  95  103.5
5 5 198.5

d3 f 3 f j
  Oh 
dx 3 xj h3

h  1 =>

d3 f 3 f d3 f 3 f d3 f 3 f 2
 3 0  12  3 1  12  3  12
dx 3 0 1 dx 3 1 1 dx 3 2 1

4.4) Higher Order Forward, Backward, and Central Difference Formulas

If we write the forward difference formula,

f x  h   f x  h h2
f x    f x   f x   ...
h 2 6

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


42/141
When we write the second order forward difference formula instead of f x  in this
formula,

f  x  2h   2 f  x  h   f  x 
f x    hf x   ...
h2

f  x  h   f  x  h  f  x  2h   2 f  x  h   f  x   h
2
=> f x      O h  6 f x   ...

h 2 h2 

 f x  2h  4 f x  h  3 f x 
=> f x  
2h
 O h2  


 f i  2  4 f i 1  3 f i
f i 
2h
 
 O h2 Forward Difference

f i 1  f i 1
f i 
2h
 
 O h2 Central Difference (Three-Point Formulas)

f i2  4 f i1  3 f i
f i   Oh 2  Backward Difference
2h

f i  2  8 f i 1  8 f i 1  f i  2
f i 
2h
 
 O h4 Central Difference (Five Point Formula)

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


43/141
HOMEWORK

1)
x 0 0.5 1.0 1.5 2 2.5 3.0

f x  1 0.8 1.2 0.4 0.6 0.8 0.7

Solve by all approximations f 1.5 and f 1.5 so that the error order of O 0.5 2 

2) Obtain central difference formula for f x  .

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


44/141
5) INTERPOLATION AND EXTRAPOLATION

5.1) Gregory-Newton Interpolation Formula

If the function f  x  expand to Taylor series at x  0 ,

x2 x3
f x   f 0  x. f 0  f 0 
 f 0  ...
2! 3!

f 0
f 0  
h
 h. f 0   O h 2  , by substituting forward difference expression in Taylor

series, we obtain

x x  h  2 xx  h x  2h  3
f x   f 0 
x
f 0  2
 f0   f 0  ...
h 2!.h 3!.h 3

If we expand it to the Taylor series at x  x n , we can generalize the formula as

x  xn  x  xn x  xn   h x  xn x  xn   hx  xn   2h


f x   f xn   f n  2
2 f n  3
3 f n  ...
h 2!.h 3!.h
(Gregory-Newton interpolation formula with forward difference)

If we repeat these steps with the backward difference formula,

x  x n  x  x n x  x n   h x  x n x  x n   hx  x n   2h


f x   f x n   f n  2
2 fn   3 f n  ...
h 2!.h 3!.h 3
(Gregory-Newton interpolation formula with backward difference)

If the data are equally spaced, the Gregory-Newton interpolation formula is used to
interpolate or extrapolate.

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


45/141
Example:
x 0 1 2 3 4 5

f x  -7 -3 6 25 62 129

Estimate the value of f 1.1 based on the given values.

When we look at the values, since there are more points beyond the 1.1 point, the forward
difference formula will be used.

x  x n  x  x n x  x n   h x  x n x  x n   hx  x n   2h


f x   f x n   f n  2
2 f n  3 f n  ...
h 2!.h 3!.h 3

i xi fi f i  f i 1  f i 2 f i  f i 1  f i 3 f i  2 f i 1  2 f i

0 0 7  3   7  4 94 5 10  5  5
1 1 3 6   3  9 19  9  10 18  10  8
2 2 6 25  6  19 37  19  18 30  18  12
3 3 25 62  25  37 67  37  30 -

4 4 62 129  62  67 - -

5 5 129 - - -

i xi fi 4 f i  3 f i 1  3 f i 5 f i  4 f i 1  4 f i
0 0 7 85  3 43 1
1 1 3 12  8  4 -

2 2 6 - -

3 3 25 - -

4 4 62 - -

5 5 129 - -

Since the closest value to 1.1 is 1.0, x n  1 will be accepted. ( h  1 and x  1.1 )

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


46/141
x  x n  x  x n x  x n   h x  x n x  x n   hx  x n   2h
f x   f x n   f n  2
2 f n  3
3 f n  ...
h 2!.h 3!.h

f 1.1  f 1 
1.1  1 f 
1.1  11.1  1  1 2 f 
0.10.1  10.1  2 3
 f1 
1 2 1
1 2!.1 3!.13
0.10.1  10.1  20.1  3 4
 f1
4!.14

0.1 *  0.9 0.1 *  0.9 *  1.9 0.1 *  0.9 *  1.9 2.9


f 1.1  3  0.1 * 9  10  8 4
2 6 24

f 1.1  2.40465

If we consider only first to terms the result would be


f 1.1  3  0.1 * 9  2.1 (Linear Interpolation)

5.2) INTERPOLATION TO UNEVEN DATA (LAGRANGE POLYNOMIALS)

If we write nth order polynomial for x j point,

Pj x   A j x  x0 x  x1 x  x2 ......x  x j 1 x  x j 1 ......x  xn 

n
Pj x   A j  ( x  xi )
i 0
i j

If we were to find the value of the polynomial for any point, x k

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


47/141


0 k j

Pj xk   
 n
 Aj  ( x j  xi ) k j
 i 0
 i j

1
If Aj  is chosen,
 x  xi 
n

j
i 0
i j

 x  x 
i 0
i

Pj  x  
i j
=> (Lagrange Polynomials)
 x  xi 
n

j
i 0
i j

0 k j

Pj x k   
1 k j

f x    f x j * Pj x 
j 0

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


48/141
=> f x  f x0 * P0 x  f x1 * P1 x  f x2 * P2 x  f x3 * P3 x

0 k0

=> P0 x k   
1 k 0

=> f  x 0   f  x 0  * 1  f  x1  * 0  f  x 2  * 0  f  x3  * 0

f  x1   f  x 0  * 0  f  x1  * 1  f  x 2  * 0  f  x3  * 0

Example:
i 0 1 2 3

xi 1 2 4 8

f xi  1 3 7 11

Find the Lagrangian function and calculate the value f 7  .

 x  x 
i 0
i

Pj  x  
i j

 x  xi 
n

j
i 0
i j

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


49/141
x  x1 x  x2 x  x3  x  2x  4x  8
=> P0 x   
x0  x1 x0  x2 x0  x3  1  21  41  8

x  x0 x  x2 x  x3  x  1x  4x  8


P1 x   
x1  x0 x1  x2 x1  x3  2  12  42  8

x  x0 x  x1 x  x3  x  1x  2x  8


P2 x   
x2  x0 x2  x1 x2  x3  4  14  24  8

x  x0 x  x1 x  x2  x  1x  2x  4


P3 x   
x3  x0 x3  x1 x3  x2  8  18  28  4

=> f  x   f  x 0  * P0  x   f  x1  * P1  x   f  x 2  * P2  x   f  x3  * P3  x 

=> f  x   1 * P0  x   3 * P1  x   7 * P2  x   11 * P3  x 

=> f 7   1 * P0 7   3 * P1 7   7 * P2 7   11 * P3 7 

x  x1 x  x2 x  x3  7  27  47  8 5 * 3 * 1


P0 7      0.71429
x0  x1 x0  x2 x0  x3  1  21  41  8  1 * 3 * 7
x  x0 x  x2 x  x3  7  17  47  8 6 * 3 * 1
P1 7      1.5
x1  x0 x1  x2 x1  x3  2  12  42  8 1 * 2 * 6
x  x0 x  x1 x  x3  7  17  27  8 6 * 5 * 1
P2 7      1.25
x2  x0 x2  x1 x2  x3  4  14  24  8 3 * 2 * 4
x  x0 x  x1 x  x2  7  17  27  4 6 * 5 * 3
P3 7      0.53571
x3  x0 x3  x1 x3  x2  8  18  28  4 7 * 6 * 4

=> f 7  1* 0.71429  3 *  1.5  7 *1.25  11* 0.53571

=> f 7  10.8571

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


50/141
HOMEWORK

1)
i 0 1 2 3 4

xi 2 4 6 7 9

f xi  3 6 9 5 8

Find the Lagrange polynomial for the data given. Calculate the f 8 and f 1 values.

2)

i 0 1 2 3 4 5 6 7

xi 0.1 0.3 0.7 0.9 1.2 1.5 1.7 2.0

f xi  0.99 0.92 0.7 0.57 0.39 0.24 0.16 0.07

Find the Lagrange polynomial for the data given. Calculate the f 1 value.

5.3) Extrapolation

If the function f  x  is known only a  x  b in the range, but the values of f  x  in x  a


or x  b are desired, then extrapolation is performed. Gregory-Newton or Lagrange
functions are used.

In order to be able to perform interpolation and extrapolation for f  x  , it must be suitable


for polynomial interpolation.

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


51/141
Example:

x 1 2 3 4 5

f x  100 25 11.111 6.25 4

=> Find estimated value of f 5.7  .

Since the intervals are equal, we need to use the Gregory-Newton forward or backward
difference formulas. Since the desired value is 5.7, we need to use the backward
differences formula.
x  x n  x  x n x  x n   h x  x n x  x n   hx  x n   2h
f x   f x n   f n  2
2 fn   3 f n  ...
h 2!.h 3!.h 3
(Gregory-Newton interpolation function with backward difference formula)

i xi fi f i  f i  f i 1  2 f i  f i  f i 1  3 f i   2 f i   2 f i 1  4 f i   3 f i   3 f i 1

0 1 100 - - - -

1 2 25  75 - - -

2 3 11.111  13.889 61.111 - -

3 4 6.25  4.861 9.028  52.083 -

4 5 4  2.25 2.611  6.417 45.666

x n  5 (closest to 5.7)
x  5.7
h 1

x  x n  x  x n x  x n   h x  x n x  x n   hx  x n   2h


f x   f x n   f n  2
2 fn   3 f n  ...
h 2!.h 3!.h 3
x  x n  5.7  5  0.7

0.70.7  1 2 0.71.72.7 3 0.71.72.73.7 4


f 5.7   f 5  0.7f 5   f5   f5   f5
2 6 24

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


52/141
f 5.7   4  0.7 *  2.25   6.417  0.7 *1.7 * 2.7 * 3.7 45.666
0.7 * 1.7 0.7 * 1.7 * 2.7
2.611 
2 6 24

f 5.7   23.163

Not suitable for interpolation and extrapolation.

If we do linear interpolation taking the first two terms, we get

f 5.7   f 5  0.7f 5  4  0.7 *  2.25   2.425

Real Value
Linear 2. Degree 3. Degree 4. Degree
f x  
100
x2
f 5.7  3.078 2.425 3.979 0.543 23.163

In such a case, the safest approach is the linear interpolation approach.

5.4) Spline Interpolation

In the interpolation methods we have examined under other headings, an n th degree curve
passes from the (n+1) points. However, passing high-order polynomials across data points
could produce erroneous results when there were abrupt changes in data values. To avoid
this, the data can be divided into smaller data groups and smaller order polynomial
overlays can be made for each data group. Thus, the curve fitting operations made from
small-order polynomials are called spline interpolation.

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


53/141
MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL
54/141
Linear Spline

First-order spline functions for data groups given in order can be given as follows,

f  x   f  x 0   m0  x  x 0  x0  x  x1

f x   f x1   m1 x  x1  x1  x  x2
.
.
.

f  x   f  x n 1   m n 1  x  x n 1  x n 1  x  x n

f  xi 1   f  xi 
Here the slope expression, mi 
xi 1  xi

Example: For the data group given below, apply the linear spline and calculate f 5 .

i 0 1 2 3

xi 3.0 4.5 7.0 9.0

f xi  2.5 1.0 2.5 0.5

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


55/141
f x   f x1   m1 x  x1  x1  x  x2
f x   1  m1 x  4.5
f x 2   f  x1  2.5  1
m1    0.6
x 2  x1 7  4.5

f x   1  0.6 * x  4.5 4.5  x  7


=> f 5  1  0.6 * 5  4.5  1.3

Quadratic Spline

As seen in the example above, the curve at the node (data) points is discontinuous and 1.,
2., …, n. derivatives are undefined. If it is required, the continuous m th derivative, It is
necessary to pass a (m+1) degree polynomial. If a third-order polynomial is passed
through the data points, both the 1 st and 2nd derivatives are defined. For this reason, cubic
splines are mostly used in spline interpolation. In a quadratic spline, the goal is to pass a
second-order curve through the data points. As a result, the first derivative is defined at
the data points.

f i x   ai .x 2  bi .x  ci

For (n+1) data points, there are n intervals in total.

There are (3n) unknowns in total consisting of a's, b's and c's.

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


56/141
Then a total of (3n) conditions (equations) are needed. These;

i) At internal data points, the function values must be equal to the data values.

ai 1 .xi21  bi 1 .xi 1  ci 1  f xi 1 


i  2, 3, ..., n
a i .x 2
i 1  bi .xi 1  ci  f xi 1 

This condition satisfies 2(n-1) equation.

ii) First and last functions must pass through first and last data points.

a1 .x02  b1 .x0  c1  f x0 

a n .x n2  bn .x n  c n  f x n 

This provides 2 equations.

iii) The first derivatives must be equal at the internal data points.

f x   2a.x  b
2ai 1 .xi 1  bi 1  2ai .xi 1  bi i  2, 3, ..., n
This provides n  1 equations.

iv) At the first data point, the second derivative is assumed to be “0”.

2a1  0 => a1  0

In this case, the first function is a straight line, not a quadratic curve.

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


57/141
Example: For the data given in the previous example, solve the quadratic spline and

calculate f 5 .

i 0 1 2 3

xi 3.0 4.5 7.0 9.0

f xi  2.5 1.0 2.5 0.5

Here n=3 and 3n=9 unknowns. If we write the 9 equations that depend on these 9
unknowns,

20,25a1  4.5b1  c1  1 (1)

20,25a2  4.5b2  c2  1 (2)

49a2  7b2  c2  2.5 (3)

49 a3  7b3  c3  2.5 (4)

9a1  3b1  c1  2.5 (5)

81a3  9b3  c3  0.5 (6)

9a1  b1  9a2  b2 (7)

14 a2  b2  14 a3  b3 (8)

a1  0 (9)

If we solve these equations with the Gauss elimination method, the equation becomes as
follows,

b1 c1 a2 b2 c2 a3 b3 c3
 4. 5 1 0 0 0 0 0  b1   1 
0
0  
 0 20.25 4.5 1 0 0 0  c1   1 
0 0 49 7 1 0 0 0 a 2  2.5
    
0 0 0 0 0 49 7 1  b2  2.5

3 1 0 0 0 0 0 0  c 2  2.5
    
0 0 0 0 0 81 9 1  a3  0.5
1 0 9 1 0 0 0 0  b3   0 
    
 0 0 14 1 0  14  1 0  c3   0 

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


58/141
If a solution is made,

a1  0 b1  1 c1  5.5
a2  0.64 b2  6.76 c2  18.46
a3  1.6 b3  24 .6 c3  91 .3

=> f1 x    x  5.5 3  x  4.5


f 2  x   0.64 x 2  6.76 x  18 .46 4.5  x  7

f 3 x   1.6 x 2  24.6 x  91.3 7 x9

x5 => f 2 5  0.64 * 25  6.76 * 5  18.46


f 2 5  0.66

There are two important shortcomings in the quadratic spline solution;

i) The first two data points are joined with a straight line.
ii) Functions in both the first and last intervals show extreme oscillation.

The remedy for these weaknesses is the cubic spline. These deficiencies are not observed
in the cubic spline.

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


59/141
Cubic Spline

=> f i x   ai x 3  bi x 2  ci x  d i
For (n+1) data points,
There are n intervals.
4n unknowns appear (a, b, c, d's)

Conditions:

1) Function values at internal data points must be equal to the data value.
It provides 2(n-1) equations.

2) The first function must pass through the first data point, and the last function
must pass through the last data point.
It provides 2 equations.

3) The value of the first derivatives of the functions at the internal data points must
be equal.
It provides (n-1) equations.

4) The value of the second derivatives of the functions at the internal data points
must be equal.
It provides (n-1) equations.

5) The second derivatives of the functions passing through the first and last data
points must be “0”. (Forcing Condition). It provides 2 equations.

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


60/141
In the sum of these items, 4n equations are obtained and a solution is made in this way.

Since the number of equations is too large during these operations, a set of equations has
been developed for each region and generalized as;

f xi 1  f xi 1   f xi 1  f xi 1 xi  xi 1 


f i x   xi  x 3  x  xi 1 3      xi  x 
6xi  xi 1  6xi  xi 1   xi  xi 1  6 
 f  xi  f  xi  xi  xi 1  
    x  x i 1  , i  1,2,3,......, n (A)
  xi  xi 1  6 

xi  xi 1  f xi 1   2xi 1  xi 1  f xi   xi 1  xi  f xi 1   6


 f x   f xi 
xi 1  xi  i 1

6
 f x   f xi  , i  1,2,3,......, n  1 (B)
xi  xi 1  i 1

First, equation B is solved. After obtaining f  values at internal points, those can be
substituted in equation A and for each interval a third order curve is obtained.

Example: Calculate the cubic spline curves using the data below and calculate f(5).

i 0 1 2 3

xi 3.0 4.5 7.0 9.0

f xi  2.5 1.0 2.5 0.5

=> If we say i=1 in equation B,

x1  x0  f x0 '2x2  x0  f x1   x2  x1  f x2   6


 f x2   f x1   6  f x0   f x1 
x2  x1  x1  x0 
4.5  3 f 3'27  3 f 4.5  7  4.5 f 7   6
 f 7   f 4.5  6  f 3  f 4.5
7  4.5 4.5  3

If we say i=2 in equation B,

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


61/141
7  4.5 f 4.5'29  4.5 f 7   9  7  f 9  6
 f 9  f 7  6  f 4.5  f 7
9  7 7  4.5

f 3 and f 9 values are equal to zero from the 5th condition. In this case, the above
equations take the form:

8. f 4.5  2.5 f 7  9.6 if i=1

2.5. f 4.5  9. f 7  9.6 if i=2

=> f 4.5  1.67909


f 7  1.53308

For the first interval;

If equation A is solved by setting i=1;

f 3
4.5  x 3  f 4.5 x  33   2.5  f 34.5  34.5  x 
 
f1 x  
64.5  3 64.5  3  4.5  3 6 
 1 f 4.54.5  3
  x  3 , i 1
 4.5  3 6 

f1 x   1.86566x  3  1.666674.5  x   0.246894x  3


3

For the second interval;

If equation A is solved by setting i=2;

f 2 x   0.1119397  x   0.102205x  4.5  0.2996217  x   1.638783x  4.5 , i2


3 3

For the third interval;

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


62/141
If equation A is solved by setting i=3;

f 3 x   0.1277579  x   1.7610279  x   0.25x  7 i3


3
,

The point x=5 is valid for the second interval. In this situation,

f 2 5  1.102886

Cubic Interpolation

HOMEWORK

1) Construct quadratic and cubic splines for the data given below. Find the value of f 0.47 
.
i 0 1 2 3 4 5 6 7 8

xi 0 0.1 0.7 0.9 1.2 2.8 2.1 2.4 2.7

fi 3.0 4.0 6.5 7.2 4.3 3.2 6.0 7.1 8.3

2) Write a computer program that overlaps a cubic spline with a curve.

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


63/141
LEAST SQUARE REGRESSION

If the data contains errors or is thought to contain errors, instead of the curve that will
pass through all data points, the lower-order curve fitting that is thought to represent these
data approximately and does not pass through all data points is called regression.

1. Linear Regression

y  a 0  a1 x  e , e ; error

e  y  a 0  a1 x

ei  y i  a 0  a1 xi (The difference between each point that makes up the function and

the actual value gives the error value for that point.)

Criterion for Optimal Curve

The optimal curve is defined as the curve that minimizes the sum of the squared errors.

xi yi

x1 y1
x2 y2
. .
. .
. .

xn yn

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


64/141
n n
S r   ei2    yi  a0  a1 xi 
2

i 1 i 1

S r n
0 =>  2.  yi  a0  a1 xi   0 (1)
a 0 i 1

S r n
0 =>  2.  yi  a0  a1 xi xi  0 (2)
a1 i 1

n n n n n
(1)  y  a  a x
i 1
i
i 1
0
i 1
1 i 0 => y
i 1
i  n.a0   a1 xi
i 1
(3)

n n n n n n
(2)  xi . yi   a0 .xi   a1 xi2  0
i 1 i 1 i 1
=>  xi . yi   xi .a0   xi2 .a1
i 1 i 1 i 1
(4)

Example: Find the most appropriate linear line for the following data.

i xi yi xi . y i xi2 y (result)
1 0.1 0.61 0.061 0.01 0.46262
2 0.4 0.92 0.368 0.16 0.99198
3 0.5 0.99 0.495 0.25 1.16844
n6
4 0.7 1.52 1.064 0.49 1.52135
5 0.7 1.47 1.029 0.49 1.52135
6 0.9 2.03 1.827 0.81 1.87426

 3.3 7.54 4.844 2.21

According to equation 3, 6a 0  3.3a1  7.54

According to equation 4, 3.3a 0  2.21a1  4.844

a1  1.7645 and a 0  0.2862


y  a 0  a1 x
=> y  0.2862  1.7645x

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


65/141
y
y i

7.54
 1.25667
n 6

Determining the Amount of Error in Linear Regression:

a) Standard deviation of the regression line

Sr
Sy/x  S y / x : Standard deviation
n2
n  2 : Degrees of freedom
b) Coefficient of determination

St  S r
r2 
St
n
S r   ei2
i 1

n
S t    yi  y    oi2
2

i 1

S t , is the sum of the squares of the difference from the mean value of the dependent
variable. Here, r is defined as the correlation coefficient.

In case of perfect curve overlap, r=0.

St  0
r2  r 1 r2 
St

If S t  S r then r 2  r  0 , it means the curve did not provide any improvement.

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


66/141
If we calculate the amount of error for the previous example,

 yi  a0  a1 xi 2  ei2 oi2   yi  y 
2

0.02172 0.4181
0.00518 0.1133
0.03183 0.07111
0.000001822 0.06931
0.0026368 0.0455
0.02425 0.598

 0.08562 1.3153

S r   ei2  0.08562 and S t   oi2  1.3153

Sr 0.08562
Sy/x    0.14630 (standard error)
n2 62

S t  S r 1.3153  0.08562
r2    0.935
St 1.3153

=> r  0.9669

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


67/141
2. Polynomial Regression

It may be more appropriate to represent the same data as a polynomial rather than a
straight line. In this case, the least squares method can be applied similarly for the m th
degree polynomial.

y  a0  a1 .x  a 2 .x 2  ......  a m .x m  e

ei  yi  a0  a1.xi  a2 .xi2  ......  am .xim


S r   ei2   yi  a0  a1 .xi  a2 .xi2  ......  am .xim 
2

(1)
S r
a0
 
 2 yi  a0  a1 .xi  a 2 .xi2  ......  a m .xim  0

(2)
S r
a1
 
 2 yi  a0  a1 .xi  a 2 .xi2  ......  a m .xim .xi  0

.
.

(m+1)
S r
a m
 
 2 yi  a0  a1 .xi  a 2 .xi2  ......  a m .xim .xim  0

1) a0 n  a1  xi  a 2  xi2  ......  a m  xim   y i

2) a0  xi  a1  xi2  a 2  xi3  ......  a m  xim1   xi y i


.
.
.

m+1) a0  xim  a1  xim1  a 2  xim 2  ......  a m  xi2m   xim y i

Standard deviation,

Sr
Sy/x 
n  m  1
Coefficient of determination,

St  S r
r2 
St

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


68/141
Example: Calculate the 2nd order regression curve for the values given in the previous
example?

i xi yi xi . y i xi2
1 0.1 0.61 0.061 0.01
2 0.4 0.92 0.368 0.16
3 0.5 0.99 0.495 0.25
n6
4 0.7 1.52 1.064 0.49
5 0.7 1.47 1.029 0.49
6 0.9 2.03 1.827 0.81

 3.3 7.54 4.844 2.21

y  a 0  a1 .x  a 2 .x 2  e
=> ei  y  a0  a1 .xi  a2 .xi2


S r   ei2   y  a 0  a1 .xi  a 2 .xi2 2

S r
0 =>  2 y  a0  a1 .xi  a 2 .xi2   0 (1)
a 0
S r
0 =>  2 y  a0  a1 .xi  a 2 .xi2 xi  0 (2)
a1
S r
0 =>  2 y  a0  a1 .xi  a 2 .xi2 xi2  0 (3)
a 2

1) na0  a1  xi  a 2  xi2   y i => 6a 0  3.3a1  2.21a 2  7.54

2) a0  xi  a1  xi2  a 2  xi3   xi y i => 3.3a 0  2.21a1  1.605 a 2  4.844

3) a0  xi2  a1  xi3  a 2  xi4   xi2 y i => 2.21a 0  1.605 a1  1.2245 a 2  3.5102

a 0  0.587114

a1  0.059102
a 2  1.729537

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


69/141
y  0.587114  0.059102 .x  1.729537 .x 2 2. degree regression polynomial

y  0.2862  1.7645x Linear regression polynomial

NOTE: Calculate correlation coefficient. Compare result with the linear regression result.
Probably here r=0.98.

3. Multiple Linear Regression

If there is more than one variable. (assuming there are 2 variables)

x1i x 2i yi

. . .
. . .
. . .

In this case, not the best curve, but the plane that best represents the data will be found.

ei  y i  a 0  a1 x1i  a 2 x 2i

S r   ei2    y i  a0  a1 x1i  a 2 x 2i 
2

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


70/141
S r
 0  2  y i  a 0  a1 x1i  a 2 x 2i  => n.a0   x1i a1   x 2i a 2   y i
a 0
S r
 0  2  y i  a 0  a1 x1i  a 2 x 2i .x1i => x a0   x12i a1   x1i .x 2i .a 2   x1i . y i
a1 1i

S r
 0  2  y i  a 0  a1 x1i  a 2 x 2i .x 2i => x a0   x1i x 2i a1   x 22i .a 2   x 2i . y i
a 2 2i

HOMEWORK

1) Using the least squares regression method, find the first (linear), second, and third
order polynomials for the data set given below. Compute and compare the coefficient of
correlation for each case.

xi 0 0.1 0.2 0.4 0.5 0.7 0.8 1.0

yi 0 1.3 2.0 2.4 2.8 2.7 2.4 2.1

2) Using the least squares regression method, write a computer program that
superimposes a 3rd degree polynomial curve and apply it to the above data.

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


71/141
6) NUMERICAL SOLUTION OF ORDINARY DIFFERENTIAL EQUATIONS

6.1.1) Numerical Solution of Initial Value Problems

y   f x, y  and y  x 0   y 0

y 0  yx 0 

y1  y  x 0  h 

y 2  y  x 0  2h 
.
.
.

y n  y  x 0  nh 

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


72/141
y1  y 0  y  x 0  x1  x 0 

y 2  y1  y x1 x 2  x1 
.
.
.

y n 1  y n  y  x n  x n 1  x n 

=> y n 1  y n  y  x n h

y  x n   f  x n , y n 

 
y n 1  y n  h. f x n , y n   O h 2

This method is called the Euler method or the tangent line method.

6.1.2) Three-term Taylor Series Method

In the y   f x, y  differential equation, if the initial value y  x 0   y 0 is known, if we


expand yx  h to the Taylor series, we get,

h2 h3
y x  h   y x   y x .h  y x   y x   ......


2! 3!

If we take first three term in Taylor series and apply chain rule to y x  and y x 

y x   f x, y   f x, yx 

f x, y x  dx f x, y x  dy
y x   .  .
x dx y dx

f x, yx  f x, yx 


=> y x    f x, yx 
x y

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


73/141
h 2  f x, y x  f x, y x  
y x  h   y x   h. f x, y x  
2 

x

y
 
f x, y x   O h 3

h 2  f x n , y n  f x n , y n  
y n 1  y n  h. f x, y x  
2 

x

y
 
f x n , y n   O h 3

Example: Numerically solve the differential equation given as y   x  y and y1  2


compare the solution with the analytical solution results.

Analytical solution: y  x  1

f f
f x, y   x  y , 1 , 1
x y

=> y n 1  y n  h. f x n , y n  
h2
2
 
1  1x n  y n   O h 3
If we choose h  0.1 ,
x n  x 0  nh => x n  1  0.1 * n

n xn y n (Analytical) y n (Numerical)
0 1 -2.0 -2.0

1 1.1 -2.1 -2.1

2 1.2 -2.2 -2.2


3 1.3 -2.3 -2.3
. . . .
. . . .
10 1.8 -2.8 -2.8

=> y1,1  y1  0.11  2 


0.1
2
1  11  2  Oh 3 
2
y1,1  2.0  0.1  2.1

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


74/141
Example: y   y. sin x    cosx   2 y ,
2 2
y 3  2

 
f x, y   y. sin x 2  cos x 2  2 y  

f
x
 
 2 xy. cos x 2  2 x. sin x 2  
f
y
 
 sin x 2  2

    
y n 1  y n  h. y. sin x 2  cos x 2  2 y 
n 
h2
2
            
2 xy. cos x 2  2 x. sin x 2  sin x 2  2 y. sin x 2  cos x 2  2 y 
n  
 O h3

If we choose h  0.1 ,
x n  x0  nh => x n  3  0. 1 * n

n xn yn

0 3.0 2  1.4142
1 3.1 1.7138
2 3.2 1.9156
3 3.3 1.9787
4 3.4 1.9512
5 3.5 1.9238
6 3.6 2.0176
. . .
. . .
. . .
10 4 4.0834

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


75/141
6.1.3) Runge-Kutta Method

y x   f x, y  and y  x 0   y 0


An  h. f  x n , y n 

 1 1 
Bn  h. f  x n  h, y n  An 
 2 2 
 1 1 
C n  h. f  x n  h, y n  Bn 
 2 2 
D n  h. f  x n  h, y n  C n 

y n 1  y n 
1
6
 
An  2.Bn  2.C n  Dn   O h 5

y n 1  y n  h. f  x n , y n 

y n 1  y n  h. y  x n 

It is a very reliable method. The degree of error is extremely low and there is no problem
of derivation.

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


76/141
Example: Solve the differential equation given by y   x  sin y
2
  and y1  4.7
2

If we choose h  0.1 ,

 
f  x, y   x 2  sin y 2 x0  1 y 0  4 .7

  
A0  0.1 f x0 , y0   0.1* 12  sin 4.7 2  0.1099


 0.1 
2
 0.1099  
2

B0  0.11    sin 4.7     0.1682

 2   2   

 0.1 
2
 0.1682  
2

C 0  0.11    sin 4.7     0.1884

 2   2   

D0  0.1 1  0.1  sin4.7  0.1884  0.2115
2 2

y1  y0 
1
6
 
A0  2.B0  2.C0  D0   O h5  4.7  1 0.1099 2 * 0.1682 2 * 0.1884 0.2155
6
=> y1  4.8731
x n  x 0  nh

x n  1  0.1 * n

x  1.1 , y1  4.8731

n xn yn
0 1.0 4.7 (given)
1 1.1 4.8731
2 1.2 5.0426
3 1.3 5.1313
4 1.4 5.2168
5 1.5 5.4039
6 1.6 5.6797

7 1.7 5.8708

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


77/141
6.2) NUMERICAL SOLUTION OF SECOND DEGREE INITIAL VALUE PROBLEMS

y   f x, y, y  yx0   A y  x 0   B

6.2.1) Taylor Method

If we expand yx  to Taylor series at x  h ,

h2 h3
y x  h   y x   y x .h  y x   y x   ......
2! 3!
and

h2 h3
y x  h   y x   y x .h  y x  y x
( 4)
   ......
2! 3!

y x  h   y x   h. y x  
h2
2!
 
y x   O h 3

y  x  h   y  x   h. y  x   O h 2  

=> 
y j  f x j , y j , y j 
x j 1  x0   j  1h

y j 1  y j  h. y j 
h2
2!
 
y j  O h 3

y j 1  y j  h. y j  Oh 2 

First we will take j  0 , and calculate y 0 , y1 and y1 . Then take j  1 and calculate y1 ,

y 2 and y 2 . By continuing the iteration process, y1 , y 2 , y 3 , …, y n will be obtained

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


78/141
Example: Solve the differential equation given by y   x  cos y   2.e . y  with initial
2 x

conditions y1  1 and y 1  3

x0  1 y 0  1 y 0  3 f  x, y, y   x 2  cos y   2.e  x . y 

If h  0.1 is chosen.

Step 1: j0

y 0  12  cos 1  2.e 1 .3  2.666974


x1  x0  0.1 * 1  1.1

y1  1  0.1 * 3 
0.12 2.666974  0.686665
2
y1  3  0.1* 2.666974  3.2666974

Step 2: j 1

y1  1.12  cos 0.686665   2.e 1.1 * 3.266974   2.611405


x2  x1  0.1*1  1.2

y2  0.686665  0.1 * 3.2666974 


0.1
2
2.611405  0.346938
2
y 2  3.2666974  0.1* 2.611405  3.527838

Step 3: j2

y 3  y 1.3  0.018939

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


79/141
6.2.2) Runge-Kutta Method

y   f 2 x, y, y  y x0   y 0 y  x 0   P0

y   p  f1 x, y, p  => y x0   y 0

y   p  f 2 x, y, p  => p  x 0   P0

If y   p  x  f1 x, y, p  then
p  1  f 2 x, y, p  is obtained

k1  h. f1  x n , y n , p n 

l1  h. f 2  x n , y n , p n 

 1 1 1 
k 2  h. f1  xn  h, y n  k1 , pn  l1 
 2 2 2 
 1 1 1 
l 2  h. f 2  xn  h, y n  k1 , p n  l1 
 2 2 2 
 1 1 1 
k 3  h. f1  xn  h, y n  k 2 , p n  l 2 
 2 2 2 
 1 1 1 
l3  h. f 2  xn  h, y n  k 2 , p n  l 2 
 2 2 2 
k 4  h. f 1  x n  h, y n  k 3 , p n  l 3 

l 4  h. f 2  x n  h, y n  k 3 , p n  l 3 

y n1  y n 
1
k1  2.k 2  2.k 3  k 4 
6

p n1  p n 
1
l1  2.l2  2.l3  l4 
6

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


80/141
Example: Solve the differential equation given by x . y   5.x. y   20 . y  0 with initial
2

conditions y1  0 and y 1  2 . Evaluate y1.2  ?


5. y  20
=> y     2 y
x x
If y   p  f1 x, y, p  is assumed

p  2 y  f 2 x, y, p 
5 20
p  
x x
y 0  y 1  0

p 0  p 1  2

If h  0.2 is chosen,

k1  0.2 * 2  0.4

 5 20 
l1  0.2 *   2  2 0   2
 1 1 
 1   
k 2  0.2 p0  l1   0.22   2  0.2
1
 2   2 
 
 
 5  2 20  0.4 
l 2  0.2 2   0    1.570
1  0.2  2   0.2  2  2 
 2 1   
 2 

 1 
k3  0.22   1.57  0.243
 2 
 
 
 5   1.57  20  0.2 
l3  0.2 2   0    1.435
1  0.2  2   0.2  2  2 
 2 1   
 2 
k 4  0.22   1.435  0.113
 5 
l 4  0.2 2  1.435  20 2 0  0.243  1.146
1  0.2 1  0.2 

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


81/141
y1  y1.2  0 
1
0.4  2 * 0.2  2 * 0.243  0.113
6
y1  y1.2  0.233

Analytical solution

x sin4. lnx 
1 2
y
2
y1.2  0.23137

6.2.3) Runge Kutta – Nystrom Method

y   f x, y, y  y x0   K y  x0   L

h. f x j , y j , y j 
1
Aj 
2
1  1 1  1  
Bj  h. f  x j  h, y j  h y j  A j , y j  A j 
2  2 2  2  
1  1 1  1  
Cj  h. f  x j  h, y j  h y j  A j , y j  B j 
2  2 2  2  

Dj 
1
2

h. f x j  h, y j  hy j  C j , y j  2.C j 

 1
 

y j 1  y j  h  y j  A j  B j  C j 
3
 

y j 1  y j 
1
3
A j  2.B j  2.C j  D j 

Since it is only for 2nd order differential equation, its usage is limited.

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


82/141
HOMEWORK

1) Differential equation y   x  4. y  3.e


2  y
is given with initial conditions of y2  3 and
y 2  4 . By choosing h  0.1 , calculate y 5 .

2) Differential equation y   x  cos y   2.e


2 x
. y  is given with initial conditions of y1  1
and y 1  3 . By choosing h  0.1 , calculate y 5 .

6.3) Numerical Solution of Second Order Boundary Value Problems

y  f x, y, y ya    yb   

ba
h
n
x j  x0  j.h

x j  a  j.h


y j  f x j , y j , y j 

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


83/141
y j 1  y j 1
yj 
2.h
 
 O h2

y j 1  2. y j  y j 1
yj 
h 2
 
 O h2

If we substitute and rearrange the finite difference formulas in the differential equation,
then if j  1,2,3,......, n  1 is chosen, we get (n-1) algebraic equations. If we substitute the
boundary conditions ya    and yb    properly in this (n-1) equation, we get an (n-
1) set of equations. By solving this (n-1) equation, values of y1 , y2 , y3 , ……, yn 1 can be
found.

Example: Differential equation y  x  2 y  y with boundary conditions y0  1 and


y1  3 is given. If n  10 is chosen, solve the differential equation numerically.

b  a 1 0
h   0.1
n 10

yj  x j  2 y j  yj

If we use the central difference formulas,

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


84/141
y j 1  2. y j  y j 1 y j 1  y j 1
=> 2
 x j  2. y j 
h 2.h

=>
 h
 
 h
1   y j 1   2  2h y j  1   y j 1  h .x j
2 2

 2  2

x j  x0  j.h => x j  0.1 * j

1.05 * y j 1  1.98 * y j  0.95 * y j 1  0.001* j

Except “j=0” and “j=10”, for j=1,2,3…, (n-1) values, the set of linear equations:

1.05 * y0  1.98 * y1  0.95 * y2  0.001 j 1


1.05 * y1  1.98 * y2  0.95 * y3  0.002 j2
1.05 * y2  1.98 * y3  0.95 * y4  0.003 j3
1.05 * y3  1.98 * y4  0.95 * y5  0.004 j4
1.05 * y4  1.98 * y5  0.95 * y6  0.005 j5
1.05 * y5  1.98 * y6  0.95 * y7  0.006 j6
1.05 * y6  1.98 * y7  0.95 * y8  0.007 j7
1.05 * y7  1.98 * y8  0.95 * y9  0.008 j 8
1.05 * y8  1.98 * y9  0.95 * y10  0.009 j9

If the boundary conditions are entered, the first and last equations become:

y 0   y0  1

1.05 *1  1.98 * y1  0.95 * y2  0.001 =>  1.98 * y1  0.95 * y2  1.049

y 1  y10  3

1.05 * y8  1.98 * y9  0.95 * 3  0.009 => 1.05 * y8  1.98 * y9  2.8590

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


85/141
Matrix created with equations,

 1.98 0.95 0 0 0 0 0 0 0   y1   1.049


 1.05  1.98 0.95
 0 0 0 0 0 0   y2   0.002 
 0 1.05  1.98 0.95 0 0 0 0 0   y3   0.003 
    
 0 0 1.05  1.98 0.95 0 0 0 0   y4   0.004 
 0 0 0 1.05  1.98 0.95 0 0 0   y5    0.005 
    
 0 0 0 0 1.05  1.98 0.95 0 0   y6   0.006 
 0 0 0 0 0 1.05  1.98 0.95 0   y7   0.007 
    
 0 0 0 0 0 0 1.05  1.98 0.95   y8   0.008 
 0
 0 0 0 0 0 0 1.05  1.98  y9   2.8590 

y0  1

y1  0.7299 y4  0.3231 y7  1.6371

y2  0.4171 y5  0.7406 y8  2.0991

y3  0.0646 y6  1.1813 y9  2.5571

y10  3

HOMEWORK

1) Differential equation y  x  2 y  y with boundary conditions y0  1 and y1  3


is given. By choosing n=100, solve the problem.

2) Differential equation y  x 2  4. y  4. y with boundary conditions y1  2 and


y2  4 is given. By choosing n=100, solve the problem.

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


86/141
6.3.1) Mixed Boundary Condition

The most general expression of boundary conditions that can be encountered in boundary
dy
value problems is    . y   . Here  ,  and  are constants. In these boundary
dx
conditions; In the case of  0 and   0 , the condition that arises with these conditions
is called the Mixed Boundary Condition. In the case of  0 and   0, the previous

boundary condition is obtained and called the Dirichlet Boundary Condition, in the case of
 0 and  0 a2 and b2 the Neuman Boundary Condition is obtained

Let's formulate the following differential equation for mixed boundary conditions at both
endpoints,

d2y
Differential equation is given  C. y  f  x 
dx 2


dy
at x  a 1  1 . y   1
dx
Boundary conditions

dy
At x  b 2   2 . y2   2
dx

Under these boundary conditions, nothing can be said between the function values at

x0  a and x  b . y a   y0 and y b   ym are unknown. In this case, the number of


unknowns is equal to the number of points obtained by dividing the interval into (m) equal
parts, that is (m+1).

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


87/141
If we write the finite difference expression of the differential equation, we get
yi 1  2. yi  yi 1
 C. yi  f xi 
h2

 
yi 1  C.h 2  2 . yi  yi 1  h 2 . f xi  (1)

if i=0 in equation (1),

 
y 1  C.h 2  2 . y 0  y1  h 2 . f x 0 
(2)

In this equation, the unknown y 1 y-1 is encountered. This unknown represents an


imaginary point behind x  a to h , i.e. x = a-h. We can make use of the first boundary
condition to eliminate this imaginary point outside the range.

dy
1  1 . y   1
dx

 y1  y 1 
1    1 . y 0   1
 2h 

=> y 1  y1 
2.h
 1  1 . y 0 
1

If this expression is substituted in equation (2) and summed under common factors, the
difference equation for the left endpoint is,

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


88/141
 2 2.h. 1  2.h. 1
 h .C  2   y 0  2. y1  h 2 . f  x 0   for i0
 1  1

Likewise, if i  m is written in equation (1) to obtain the difference equation of the right
endpoint,

 
y m 1  C.h 2  2 . y m  y m 1  h 2 . f x m  im (3)

In this equation, y m 1 , represents an imaginary point x  b  h . This imaginary point can


be eliminated using the second boundary condition.

 y m 1  y m 1 
2    2 .ym   2
 2h 

=> y m 1  y m 1 
2h
 2   2 . y m 
2

If this expression is substituted in equation (3) and summed under common factors, the
difference equation for the right end point is,

 2.h. 2  2.h. 2
2. y m 1   h 2 .C  2   y m  h 2 . f  x m   im
 2  2

For midpoints i  1,2,3,......, m  1 , equation (1) is valid.

 2 2.h. 1  2.h. 1
 h .C  2   y 0  2. y1  h 2 . f  x 0   i0
 1  1

 
y 0  C.h 2  2 . y1  y 2  h 2 . f x1  i 1

y1  C.h 2
 2. y 2  y 3  h 2 . f x 2  i2

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


89/141
 
y 2  C.h 2  2 . y 3  y 4  h 2 . f x3  i 3
. .
. .
. .

 
y m  2  C.h 2  2 . y m 1  y m  h 2 . f x m 1  i  m 1

 2.h. 2  2.h. 2
2. y m 1   h 2 .C  2   y m  h 2 . f  x m   im
 2  2

Example: Solve the following differential equation for decreasing h values under the given
boundary conditions by means of a computer program and compare with the analytical
solution.

Differential Equation ; x. y   x  2. y   2 y  0

y 1  y1 
1
Boundary conditions ; y 0  0
2

Analytical Solution ; y x   e x 
2

1 2
x  2x  2 

First, let's divide the interval "0-1" into m equal parts, since both of the boundary

conditions are of mixed type, the unknown number is m  1 . A general formula for any
point x i is produced by using central difference formulas instead of derivatives in the

differential equation.

 y  2. yi  yi 1   y  yi 1 
xi  i 1 2   xi  2 i 1   2. yi  0
 h   2.h 

 h   h 

  
h  1  2 .xi  y i 1  2. h  xi . y i   h  1  2 .xi  y i 1  0
2

       

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


90/141
x i  x 0  i.h

x i  i.h

If x i  i.h is substituted divide side by side h,

  h    h 
1  1  .i  y i 1  2.h  i . y i   1  1  .i y i 1  0 , i  0,1,2,......, m (1)
  2    2  

If we put i  0 in equation (1), we get,

y 1  2.h. y 0  y1  0 i0

If the left boundary condition is used,

y1  y 1
y 0  0 => 0 => y 1  y1
2.h

=> y1  2.h. y 0  y1  0

y0  0 i0

If we put i  m in equation (1),

  h    h 
1  1  .m y m 1  2.h  m. y m   1  1  .m y m 1  0 im
  2    2  

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


91/141
From the second boundary condition,

y m 1  y m 1 1
 ym 
2.h 2

=> y m 1  y m 1  2.h. y m  h

If this expression is replaced and arranged above;

 h 
  
2m. y m 1  2h  h 2  2 .m. y m  h  1  1  m
2  
for im
 

For i  1,2,......, m  1 , from the equation (1), m  1 equations are also obtained. Thus, the
solution is completed by solving m equations with m unknown Gauss method.

Numerical Solution
Analytical
x h  0.1 h  0.05 h  0.0025 h  0.001 Solution
n=10 n=20 n=400 n=1000

0.2 0.000935 0.001285 0.001375 0.001398 0.001402

0.4 0.010563 0.011508 0.011745 0.011813 0.011824

0.6 0.039696 0.041510 0.041960 0.042098 0.042110

0.8 0.101570 0.104547 0.105290 0.105508 0.105541

1.0 0.212410 0.216810 0.217915 0.218230 0.218280

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


92/141
6.3.2) The Boundary Condition Given at Infinite

Some differential equations may have a limit value at infinity. If we give an example of
this,

Differential equation ; y   C. y  f x 
Boundary conditions ; y0  0 , y  

In order to solve this problem by creating difference equations, we need to know what order the
value specified as infinity is. Since we cannot form an idea about the order of x , we need to solve
the problem as an initial value problem. But there is another problem here as well. The one of the

initial condition, I mean  y  is missing. In other words, in order to solve the above differential

equation, not only y0 , we need to know y 0 initial value as well as . However, y 0 value is

unknown. By the way, we solve the problem as an initial value problem by making an estimation for

the initial condition y 0 and see where y 0 is going on the way to x   . In other words, when
y 0  a is taken, it converges to a value such as y  A when it goes to x   . Then let's make

a second guess for the initial condition; When y 0  b is taken, it converges to a value such as

yB when it goes to x  . Then a new predict value is calculated for y   when it goes

to infinity . This is a kind of Newton-Rapson application,

A 
ca f ( xn )
 A  B  / a  b xn1  xn 
f ( xn )

f ( xn )
x n 1  x n 
f ( x n )  f ( x n 1 )
x n  x n 1

This method, which is applied, is called the shooting method.

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


93/141
Example: Solve the following differential equation,

Differential equation ; y   4. y  1

y   
1
Boundary conditions ; y0  0 ,
4

To solve the problem as an initial value problem, we reduce the differential equation to a
first-order system of equations,

y   p  f1 x, y, p 
p   1  4. y  f 2 x, y, p 

y0  0
If y 0  p0  a  1 is chosen

If the solution is made,

y  y5  A  8242

If y 0  p0  b  1 is chosen,

If the solution is made,

y  y5  B  2749

If we put these values into the expression given for “c” above, we get a new predict for
the derivative,

8242  (1 / 4)
c  1  0.499818
8242   2749  /1   1

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


94/141
If we repeat the solution with this new value,

It is found at y4.6  y  0.25 , we see that the solution is fixed. In reality the value
of “c” is 0.5. Some equations can be solved several times with the number of predictions
Newton-Rapson.

The second boundary condition is not necessarily like y   K . The shooting method can
be applied similarly to boundary value problems such as y L   K .

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


95/141
7. NUMERICAL SOLUTION OF PARABOLIC EQUATIONS

7.1. Transform into Dimensionless Form

Numerical solutions of problems involve quite a lot of arithmetic operations. Therefore, it


is desirable that a solution be valid for as many problems as possible. This solution can be
achieved by bringing the desired equation into dimensionless form. For example, although
the swing of a pendulum in a viscous medium and the discharge of voltage across a
capacitor through resistance and inductance are physically separate, the differential
equation governing these two different expressions is exactly the same.

U  2U
K
T X 2

X
x (The size of the object has been made dimensionless)
L

=> X  x.L

U
u => U  u.U 0
U0

u.U 0  2 u.U 0 u  2u
=> K => U0  KU 0 2 2
T x.L  T L .x
2

L2 u  2 u K .T L2
=>  ,if t , T  t becomes
K T x 2 L2 K

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


96/141
L2 u  2u u  2 u
 => 
K  L2  x 2 t x 2
 t 
K 

7.2. Explicit Solution Method

The one-dimensional, time-dependent conduction heat equation is a parabolic equation


and its formula is as follows,

u  2 u

t x 2

u  x, t   u i , j ix and j t

The first-degree derivative expression on the left side of the equation must be opened with
the forward difference formula (Due to stability and convergence problem). Although the
right side of the equation is usually opened with the central difference formula, it can also
be opened with the forward and backward difference formulas, if desired.

ui , j 1  ui , j ui 1, j  2.ui , j  ui 1, j



t x 2 , FTCS (Forward Time Central Space)

t
u i , j 1  r.u i 1, j  1  2.r u i , j  r.u i 1, j and r
x 2
u i , j 1 , i, j  1 is the unknown temperature at the lattice point. If the temperatures in the

j step are known, the temperatures in the j  1 time step can be calculated with the finite
difference formula above. Since the temperatures at the first moment, that is, at the
moment j  0 , are given, the temperatures in the step j  1,2,3,......, n are calculated step
by step. This method is called the explicit solution method.

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


97/141
Example: The initial temperature of the stick (in dimensionless form) whose ends are in
contact with a melting ice block is given by
1
ux,0  2.x 0 x
2
1
ux,0  2.1  x   x 1
2
Calculate the change in temperature of the rod with time.


1
ux,0  2.x 0 x
2
Initial condition
1
ux,0  2.1  x   x 1
2

u0, t   0

u1, t   0
 Boundary conditions

Finite difference expression,


t
u i , j 1  r.u i 1, j  1  2.r u i , j  r.u i 1, j and r
x 2

Since the system is symmetrical, it will be sufficient to solve half of it.

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


98/141
Case 1: Let's take n  10 (divide the bar into 10 parts)
1 1
Let’s choose x   0.1 and t 
10 1000
t
r  0.1
x 2

=> u i , j 1  0.1 * u i 1, j  0.8 * u i , j  0.1 * u i 1, j

ui , j 1 
1
ui1, j  8.ui, j  ui1, j 
10
xi  x0  i.x => x i  0 .1 * i

i0 i 1 i2 i3 i4 i5 i  10


.....
x0 x  0.1 x  0.2 x  0.3 x  0.4 x  0.5 x 1
t  0.000 0 0.2 0.4 0.6 0.8 1 ..... .

t  0.001 0 0.2 0.4 0.6 0.8 0.96 ..... .

t  0.002 0 0.2 0.4 0.6 0.7960 0.9280 ..... .

t  0.003 0 0.2 0.4 0.5996 0.7816 0.9016 ..... .


. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
t  0.01 0 0.1996 0.3968 0.5822 0.7281 0.7867 .....
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
t  0.02 0 0.1938 0.3781 0.5373 0.6486 0.6891 ..... .

If xi  0.1 * i ,

1 1
ux,0  2.x 0 x => u i ,0  2.x  0.2 * i 0 x
2 2

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


99/141
1 1
ux,0  2.1  x   x 1 => ux,0  2.1  x   2.1  0.1* i   x 1
2 2

Analytical solution of differential equation,


1  1 
sin n. sin n. .x .e n  t
8
u n
2 2

2 
 2
n 1  2 

Finite Difference Analytical


Percentage
Solution at Solution at Difference
Error
x  0.3 x  0.3
t  0.01 0.5822 0.5799 0.0023 0.4

t  0.02 0.5373 0.5334 0.0039 0.7

t  0.1 0.2472 0.2444 0.0028 1.1

Case 2: Let's take n  10 (divide the bar into 10 parts)

1 5
Let’s choose x   0.1 and t   0.005
10 1000
t
r  0.5
x 2
=> u i , j 1  0.5 * u i 1, j  0.5 * u i 1, j 
1
ui 1, j  ui 1, j 
2

i0 i 1 i2 i3 i4 i5 i  10


.....
x0 x  0.1 x  0.2 x  0.3 x  0.4 x  0.5 x 1
t  0.000 0 0.2 0.4 0.6 0.8 1 ..... .

t  0.005 0 0.2 0.4 0.6 0.8 0.8 ..... .

t  0.01 0 0.2 0.4 0.6 0.7 0.8 ..... .

t  0.015 0 0.2 0.4 0.55 0.7 0.7 ..... .


. . . . . . . . .
. . . . . . . . .

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


100/141
. . . . . . . . .
t  0.1 0 0.0949 0.1717 0.2484 0.2778 0.3071 ..... .

Finite
Analytical
Difference Percentage
Solution at Difference
Solution at Error
x  0.3
x  0.3
t  0.005 0.6 0.5966 0.0034 0.57

t  0.01 0.6 0.5799 0.0201 3.5

t  0.02 0.55 0.5334 0.0166 3.1

t  0.1 0.2484 0.2444 0.0040 1.6

Case 3: Let's take n  10 (divide the bar into 10 parts)

1 1
Let’s choose x   0.1 and t   0.01
10 100
t
r 1
x 2
=> u i , j 1  u i 1, j  u i , j  u i 1, j

i0 i 1 i2 i3 i4 i5 i  10


.....
x0 x  0.1 x  0.2 x  0.3 x  0.4 x  0.5 x 1
t  0.000 0 0.2 0.4 0.6 0.8 1.0 ..... .

t  0.01 0 0.2 0.4 0.6 0.8 0.6 ..... .

t  0.02 0 0.2 0.4 0.6 0.4 1.0 ..... .

t  0.03 0 0.2 0.4 0.2 1.2 -0.2

t  0.04 0 0.2 0.4 1.4 -1.2 2.6 ..... .


. . . . . . . . .
. . . . . . . . .
. . . . . . . . .

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


101/141
The solution is completely pointless. These 3 case studies show that the r value is an
1
important parameter. In the explicit method, the solution range is valid for 0r  . Later,
2
this limitation will be analytically demonstrated on stability and convergence issues.

u  2 u  2 u t t 1
  => r1  , r2  and it must be r1 , r2 
t x 2 y 2 x 2 y 2 4

u  2 u  2 u  2 u t t t 1
   => r1  , r2  , r2  and r1 , r2 , r3 
t x 2 y 2 z 2 x 2 y 2 z 2 8

7.3. Crank-Nicolson Implicit Method

Although the Explicit method is computationally simple, it has a very important


shortcoming. The time digit t must be taken very, very small. Because the calculations

1
are valid for the 0r  range. Therefore, t should be taken very small in order to
2
obtain sufficiently accurate results. If the t value is taken too small, the computational
load increases. In 1947, Crank-Nicolson proposed a method that reduces the
computational volume and is valid for all values. They thought that the partial differential
equation was valid at the midpoints of the lattice points and took the finite differences of

 2u
as the mean of the approximations at the lattice points j and j  1 .
x 2

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


102/141
u  2 u

t x 2

u i , j 1  u i , j 1 u i 1, j  2 * u i , j  u i 1, j 1 u i 1, j 1  2 * u i , j 1  u i 1, j 1


 
t 2 x 2 2 x 2

u i , j 1  u i , j u i 1, j  2 * u i , j  u i 1, j u i 1, j 1  2 * u i , j 1  u i 1, j 1


  1   
t x  2
x 2

 1 : Explicit method

1
 : Crank-Nicolson Implicit Method
2
 0 : Full Implicit Method

1
If  is chosen,
2

 r.u i 1, j 1  2  2.r .u i , j 1  r.u i 1, j 1  r.u i 1, j  2  2.r .u i , j  r.u i 1, j

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


103/141
There are 3 unknown j  1 terms on the left side of the finite difference expression and 3
known  j expressions on the right side. If there are n  1 inner lattice points during
each time step (For example, j  0 and i  1,2,......, n  1) n  1 sets of interconnected
equations are obtained and n  1 will be unknown. Since the u values are given as the

first condition and the boundary conditions are given during the time at the first time

 j  0 , the u values at the j  1 order are found from the data at the j  0 time order.
This method is defined as the Implicit method.

Example: Solve the previous example using the Crank-Nicolson method.

u  2 u

t x 2


1
ux,0  2.x 0 x
2
Initial condition
1
ux,0  2.1  x   x 1
2

u0, t   0

u1, t   0
 Boundary conditions

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


104/141
1 1
If n  10 i.e. x   0.1 and if we choose t   0.01
10 100

t
=> r 1
x 2

=>  u i 1, j 1  4.u i , j 1  u i 1, j 1  u i 1, j  u i 1, j

If we take j  0 , i  1,2,3,......, n  1(9) (It is sufficient to calculate up to i  5 since it is


symmetrical)

If we take j 0,

 u 0,1  4.u1,1  u 2,1  u 0,0  u 2,0 i 1

 u1,1  4.u 2,1  u 3,1  u1,0  u 3,0 i2

 u 2,1  4.u 3,1  u 4,1  u 2,0  u 4,0 i 3

 u 3,1  4.u 4,1  u 5,1  u 3,0  u 5,0 i4

 u 4,1  4.u 5,1  u 6,1  u 4,0  u 6,0 i 5

Since xi  0.1 * i ,

1 1
ux,0  2.x 0 x => u i ,0  2.x  0.2 * i 0 x
2 2
1 1
ux,0  2.1  x   x 1 => ux,0  2.1  x   2.1  0.1* i   x 1
2 2

 u 0,1  4.u1,1  u 2,1  0.0  0.4 i 1 ( u 0,1 0)

 u1,1  4.u 2,1  u 3,1  0.2  0.6 i2

 u 2,1  4.u 3,1  u 4,1  0.4  0.8 i 3

 u 3,1  4.u 4,1  u 5,1  0.6  1.0 i4

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


105/141
 u 4,1  4.u 5,1  u 6,1  0.8  0.8 i 5 ( u 4, 0  u 6,0 and u 4,1  u 6,1 )

Unknowns Knowns

 u 0  4.u1  u 2  u 0  u 2 i 1 ( u 0,1 0)

 u1  4.u 2  u 3  u1  u 3 i2
 u 2  4.u 3  u 4  u 2  u 4 i 3
 u 3  4.u 4  u 5  u 3  u 5 i4

 u 4  4.u 5  u 6  u 4  u 6 i 5 ( u 4, 0  u 6,0 and u 4,1  u 6,1 )

u1 u2 u3 u4 u5
 4 1 0 0 0   u1  0.0  0.4
 1 4  1 0
 0  u 2  0.2  0.6
 0  1 4  1 0  u 3   0.4  0.8
    
0 0  1 4  1 u 4   0.6  1.0 
 0 0 0  2 4  u 5  0.8  0.8

u1  0.1989 u 2  0.3956
u 3  0.5834 u 4  0.7381
u 5  0.7691

If j  1 ,

 u 0  4.u1  u 2  u 0  u 2  0  0.3956 i 1 ( u 0,1 0)

 u1  4.u 2  u 3  u1  u 3  0.1989  0.5834 i2


 u 2  4.u 3  u 4  u 2  u 4  0.3956  0.7381 i 3
 u 3  4.u 4  u 5  u 3  u 5  0.5834  0.7691 i4

 u 4  4.u 5  u 6  u 4  u 6  0.7381  0.7381 i 5 ( u 4, 0  u 6,0 and u 4,1  u 6,1 )

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


106/141
i0 i 1 i2 i3 i4 i5 .... i  10
x0 x  0.1 x  0.2 x  0.3 x  0.4 x  0.5 . x 1
....
t  0.000 0 0.2 0.4 0.6 0.8 1.0 .
.
....
t  0.01 0 0.1989 0.3956 0.5834 0.7381 0.7691 .
.
....
t  0.02 0 0.1936 0.3789 0.5400 0.6461 0.6921 .
.
. . . . . . . .
. 0 . . . . . . .
. . . . . . . .
....
t  0.1 0 0.0948 0.1803 0.2482 0.2918 0.3069 .
.
t  0.1
....
(Analytical 0 0.0934 0.1776 0.2444 0.2873 0.3021 .
.
Solution)

The Crank-Nicolson method is stable for all r values. But for large values of r (around 40),
undesirable finite oscillations occur in numerical solutions. The problem can be solved
systematically with the method of Gauss and Gauss-Jordan elimination.

HOMEWORK:

1) Solve the question in the previous Example with the fully implicit (closed) method.

7.4. Derivative Type Boundary Conditions

In practice, derivative-type boundary conditions are frequently encountered. For example,


if a surface is thermally isolated, that is, there is no heat transfer perpendicular to this
u
surface, the boundary condition is  0 everywhere on this surface. Similarly, if a surface
n
with temperature u is in contact with a fluid with temperature v , the condition that the

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


107/141
heat transfer by conduction equals the heat transfer by convection can be given as
u
K  H .u  v  .
n

Here, K is the heat transfer coefficient (thermal conductivity) of the material and H (film
coefficient) is the heat transfer coefficient of the surface.

u
 h.u  v 
n

H
h (positive coefficient)
K
Let the surface of a rod of length L be thermally insulated and allow the heat to be
transferred by convection at x  0 . At time t , the temperature at this end will be unknown.
It can be determined this by using the boundary condition.

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


108/141
u
   h.u  v 
x

Since x  0 is the left end and in the opposite direction to the normal x -axis outward from

the boundary condition, the   sign is placed at the beginning of the expression.

u
 h.u  v 
x x 0

If we write the forward difference finite difference expression,

u1, j  u 0, j
 hu 0, j  v 
x

Thus we get an additional equation for u 0, j .

u
If we want to express more precisely, we can open the first derivative with the central
n
difference formula,

u1, j  u 1, j
 hu 0, j  v 
2.x

u 1, j is an imaginary temperature and is the temperature of the outer lattice point outside

the domain  x, jt  . u 1, j is an unknown temperature and another equation is needed
for the solution. This can be achieved by obtaining one more equation, assuming that the
finite difference expression of the differential equation is also satisfied at the point x  0 of

the bar. Similar equations can be used for the point of the bar at x  l .

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


109/141
u  2 u
Example: Solve the equation  with the explicit method for the following
t x 2
boundary and initial conditions. Use the central difference expression for the boundary
conditions.

u x,0  1 => Initial condition


u 0, t 
 u 0, t 
x
Boundary conditions
u 1, t 
 u 1, t 
x

ui , j 1  ui , j ui 1, j  2 * ui , j  ui 1, j

t x 2

t
=> u i , j 1  u i , j  r u i 1, j  2.u i , j  u i 1, j  and r
x 2

i  0,1,2,......, n  1, n Since the derivative type is the boundary condition and central

differences are used in this equation, it is valid for the values


of “0” and “ n ”.

u 0, j 1  u 0, j  r u 1, j  2.u 0, j  u1, j 

u 0, t  u1, j  u 1, j


 u 0, t  =>  u 0, j
x 2.x

=> u1, j  u1, j  2.x.uo, j

From the general equation u 0, j 1  u 0, j  r u1, j  2.x.u o, j  2.u 0, j  u1, j  ,

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


110/141

u 0, j 1  u 0, j  2r u1, j  1  x u 0, j  for i0

If n  10 is chosen,

1
n  10 => x   0.1
10

If i  10 ,

u10, j 1  u10, j  r u 9, j  2.u10, j  u11, j 

u11, j  u9, j
 u10, j => u11, j  u 9, j  2.x.u10, j
2.x

u10, j 1  u10, j  r u 9, j  2.u10, j  u 9, j  2.x.u10, j 

u10, j 1  u10, j  2r.u 9, j  1  x u10, j  for i  n  10 ,

The first and last boundary conditions show that the equations are symmetrical. In this
case, it is sufficient to take half of the system and make a solution.
1
The solution is valid for r .
2  x
t
t  r.x 2  0.0025
1
If r is chosen, r  =>
4 x 2

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


111/141
u 0, j 1  u 0, j 
1
2

u1, j  1.1 * u 0, j 

u 0, j 1 
1
2

0.9 * u 0, j  u1, j  i0

u i , j 1 
1
4

u i 1, j  2 * u i , j  u i 1, j  i  1,2,3,4,5

x i  x 0  i * x => x i  0 .1 * i

i0 i 1 i2 i3 i4 i5


x0 x  0.1 x  0.2 x  0.3 x  0.4 x  0.5
t  0.000 1.0 1.0 1.0 1.0 1.0 1.0

t  0.0025 0.95 1.0 1.0 1.0 1.0 1.0

t  0.0050 0.9275 0.9875 1.0 1.0 1.0 1.0

. . . . . . .

t  0.100 0.7175 0.7829 0.8345 0.8718 0.8942 0.9017

t  0.250 0.5542 0.6048 0.6492 0.6745 0.6923 0.6983

t  0.500 0.3612 0.3942 0.4205 0.4396 0.4512 0.4551

t  1.000 0.1534 0.1674 0.1786 0.1867 0.1917 0.1933

The analytical solution of this differential equation is

 sec n  4. .t
 1 
u  4    (0  x  1)
2

e Cos 2 ( x ) n

n 1
 3  4. 2
n
 n
2 

1
Here  n is the positive roots of the  . tan   function.
2

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


112/141
i0 i 1 i2 i3 i4 i5
x0 x  0.1 x  0.2 x  0.3 x  0.4 x  0.5
t  0.000 1.0 1.0 1.0 1.0 1.0 1.0

t  0.0025 0.9400 0.9951 0.9999 1.0 1.0 1.0

t  0.0050 0.9250 0.9841 0.9984 0.9999 1.0 1.0

. . . . . . .

t  0.100 0.7176 0.7828 0.8342 0.8713 0.8936 0.9010

t  0.250 0.5546 0.6052 0.6454 0.6747 0.6924 0.6984

t  0.500 0.3619 0.3949 0.4212 0.4403 0.4519 0.4558

t  1.000 0.1542 0.1682 0.1794 0.1875 0.1925 0.1941

Example: Solve the same problem with the forward (backward) finite difference expansion
for boundary conditions and the differential equation with the explicit method.

u  2 u u i , j 1  u i , j u i 1, j  2.u i , j  u i 1, j


 => 
t x 2 t x 2

t
=> ui , j 1  ui , j  r.ui 1, j  2.ui , j  ui 1, j  and r
x 2

In this case, it is valid for i  1,2,3,......, n  1 (forward and backward difference expansion
applied to the boundary conditions)

If i  1 ,

u1, j 1  u1, j  r.u0, j  2.u1, j  u2, j  i 1

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


113/141
If we write the forward difference expression of the boundary condition at x  0 ,

u 0, t  u1, j  u 0, j
 u 0, t  =>  u 0, j
x x
u1, j u1, j 1
=> u 0, j  u 0, j 1 
1  x 1  x

 u 
u1, j 1  u1, j  r. 1, j  2.u1, j  u2, j 
 1  x 

 r 
u1, j 1  1  2r  u1, j  r.u2, j for i  1 ,
 1  x 

1
If x  0.1 and r is chosen,
4

t  0.0025 becomes,

8 1
u1, j 1  u1, j  u 2, j i 1
11 4

u1, j 1
u 0, j 1 
1.1

u i , j 1 
1
ui 1, j  2.u i, j  ui 1, j  i  2,3,4,5
4

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


114/141
For x  0.1 * i ,

i0 i 1 i2 i3 i4 i5


x0 x  0.1 x  0.2 x  0.3 x  0.4 x  0.5
t  0.000 1.0 1.0 1.0 1.0 1.0 1.0

t  0.0025 0.8884 <= 0.9773 1.0 1.0 1.0 1.0

t  0.0050 0.8734 <= 0.9607 0.9943 1.0 1.0 1.0

. . . . . . .
. . . . . . .
. . . . . . .

t  0.100 0.6869 <= 0.7556 0.8102 0.8498 0.8738 0.8818

t  0.250 0.5206 <= 0.5727 0.6142 0.6444 0.6628 0.6689

t  0.500 0.3283 <= 0.3611 0.3873 0.4063 0.4179 0.4218

t  1.000 0.1305 <= 0.1435 0.1540 0.1615 0.1661 0.1677

HOMEWORK

1) Solve the same problem with the Crank-Nicolson method. For derivative boundary
conditions, use the forward (backward) difference expansion.

2) Solve the same problem with the Full Implicit method. For derivative boundary
conditions, use the central difference expansion.

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


115/141
Example: Solve the same equation using the Crank-Nicolson method. For derivative
boundary conditions, use the central difference expression.

u  2 u u i , j 1  u i , j 1 u i 1, j  2.u i , j  u i 1, j 1 u i 1, j 1  2.u i , j 1  u i 1, j 1


 =>  
t x 2 t 2 x 2 2 x 2

 r.ui 1, j 1  2  2.r .ui , j 1  r.ui 1, j 1  r.ui 1, j  2  2r .ui , j  r.ui 1, j (1)

u 0, t  u1, j  u 1, j


 u 0, t  =>  u 0, j => u 1, j  u1, j  2.x.u 0, j (2)
x 2.x

and u 1, j 1  u1, j 1  2.x.u 0, j 1 (3)

 r.u 1, j 1  2  2r .u 0, j 1  r.u1, j 1  r.u 1, j  2  2r .u 0, j  r.u1, j (4)

if x  0.1 is chosen and r  1 is taken, when equations (2) and (3) are substituted and
arranged in equation (4),

2.1 * u 0, j 1  u1, j 1  0.1 * u 0, j  u1, j for i  0 ,

Equation (1) can be used for the remaining points.

 ui 1, j 1  4 * ui , j 1  ui 1, j 1  ui 1, j  ui 1, j i  1,2,3,4,5

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


116/141
If j 0,

2.1 * u 0,1  u1,1  0.1 * u 0,0  u1,0 i0

 u 0,1  4 * u1,1  u 2,1  u 0,0  u 2,0 i 1

 u1,1  4 * u 2,1  u 3,1  u1,0  u 3,0 i2

 u 2,1  4 * u 3,1  u 4,1  u 2,0  u 4,0 i 3

 u 3,1  4 * u 4,1  u 5,1  u 3,0  u 5,0 i4

 u 4,1  4 * u 5,1  u 6,1  u 4,0  u 6,0 i 5

When the initial condition is entered,

2.1 * u 0,1  u1,1  0.1  1.0 i0

 u 0,1  4 * u1,1  u 2,1  1.0  1.0 i 1

 u1,1  4 * u 2,1  u 3,1  1.0  1.0 i2

 u 2,1  4 * u 3,1  u 4,1  1.0  1.0 i 3

 u 3,1  4 * u 4,1  u 5,1  1.0  1.0 i4

 u 4,1  4 * u 5,1  u 6,1  1.0  1.0 i 5 , u 6,1  u 4,1 and u 6,0  u 4,0

If matrix editing is done,

2.1 * u 0  u1  0.1 * u 0  u1  0.1  1.0 i0


 u 0  4 * u 1  u 2  u 0  u 2  1 .0  1 .0 i 1
 u 1  4 * u 2  u 3  u 1  u 3  1 .0  1 . 0 i2
 u 2  4 * u 3  u 4  u 2  u 4  1.0  1.0 i 3
 u 3  4 * u 4  u 5  u 3  u 5  1 .0  1 .0 i4
 u 4  4 * u 5  u 4  u 4  u 4  1.0  1.0 i 5

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


117/141
u0 u1 u2 u3 u4 u5
 2 .1  1 0 0 u 0   0.1  1.0
0 0
 1 4 1 0 0 0   u1   1.0  1.0 
    
0  1 4 1 0 0  u 2   1.0  1.0 
   
0 0  1 4  1 0   u 3   1 .0  1 .0 
 
0 0 0 1 4  1 u 4   1.0  1.0 
   



0 0 0 0  2 4  u 5   1.0  1.0 

u 0  0.8908

u1  0.9707
u 2  0.9922 For t  0.01 ,
u 3  0.9979 r  1 and x  0.1  r  t / x 
2

u 4  0.9994
u 5  0.9997

If j  1,

2.1 * u 0  u1  0.1 * u 0  u1  0.08908  0.9707 i0


 u 0  4 * u1  u 2  u 0  u 2  0.8908  0.9922 i 1
 u1  4 * u 2  u 3  u1  u 3  0.9707  0.9979 i2
 u 2  4 * u 3  u 4  u 2  u 4  0.9922  0.9994 i 3
 u 3  4 * u 4  u 5  u 3  u 5  0.9979  0.9997 i4
 u 4  4 * u 5  u 6  u 4  u 6  0.9994  0.9994 i 5

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


118/141
u0 u1 u2 u3 u4 u5
 2 .1  1 0 0 u 0   0.08908  09707 
0 0
 1 4 1 0 0 0   u1   0.8908  0.9922 
    
0  1 4 1 0 0  u 2   0.9707  0.9979 
   
0 0  1 4  1 0  u 3   0.9922  0.9994 
 
0 0 0 1 4  1 u 4   0.9979  0.9997 
    
0 0 0 0  2 4  u 5   0.9994  0.9994 

i0 i 1 i2 i3 i4 i5


x0 x  0.1 x  0.2 x  0.3 x  0.4 x  0.5
t  0.000 1.0 1.0 1.0 1.0 1.0 1.0

t  0.01 0.8908 0.9707 0.9922 0.9979 0.9994 0.9997

t  0.02 0.8624 0.9293 0.9720 0.9900 0.9964 0.9979

. . . . . . .
. . . . . . .
. . . . . . .

t  0.10 0.7179 0.7834 0.8349 0.8720 0.8944 0.9018

t  0.25 0.5547 0.6054 0.6458 0.6751 0.6929 0.6989

t  0.50 0.3618 0.3949 0.4212 0.4404 0.4520 0.4559

t  1.00 0.1540 0.1680 0.1793 0.1874 0.1923 0.1940

u  2 u u
NOT:  2  2x u x
t x x

When the equation is opened with Crank-Nicolson, the values other than the second
derivative become:

 1 ui1, j  ui1, j 1 ui1, j 1  ui1, j 1   1 1 


...  ...  2.xi      ui , j  ui , j 1   xi
2 2.x 2 2.x  2 2 

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


119/141
7.5. Convergence and Stability

It is very difficult to estimate the accuracy of the results of finite difference equations.
However, if the two criteria known as convergence and stability are met, accuracy can be
achieved by increasing the number of steps and thus increasing the number of operations.

If the time and size steps goes to “0”, the approximate numerical solution converges to the
analytical solution, the solution is said to be convergent. If the numerical method
converges to the analytical solution in the limit, it can be said that the method has achieved
the convergence criterion.

When the differential equation and boundary conditions are written as a finite difference
equation, operations are performed for a finite number of time and dimension steps.
Rounding errors are also processed during these operations. If these errors do not grow
as the solution progresses, it can be said that the solution is stable. Stability is also a
necessary condition for convergence in reality.

u  2 u

 t x 2

u i , j 1  u i , j u i 1, j  2 * u i , j  u i 1, j
 Ot    Ox 
2
=>
t x  2

1- the finite difference equation cannot be represented


2- rounding error
t
u i , j 1  r.u i 1, j  1  2r .u i , j  r.u i 1, j and r
x 2

At any instant t , the solution can be expanded to the Fourier series. If we neglect the
constants, the general term of solution of the differential equation will be in the form of

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


120/141
ux, t    t .e ıˆ. . x . By substituting this expression in the finite difference equation,  t  can

be determined, and as t gets larger, the criterion for  t  to be limited can be determined.

ıˆ   1 and e ıˆ. . x  cos  .x  ıˆ. sin  .x

 t  t 
As time progresses 1 must be (convergence condition).
 t 
u i , j   t .e ıˆ . x

u i 1, j   t .e ıˆ . x x 

ui 1, j   t .e i . x x 

u i , j 1   t  t .e ıˆ . x

Substituting these in the finite difference equation expression, we get

 t  t .eıˆ . x  r. t .eıˆ . xx   1  2r . t .e ıˆ . x  r. t .e ıˆ . xx 

If we divide both sides by  t .e ıˆ . x expression,

 t  t 
 r.e ıˆ. .x  1  2r   r.e ıˆ. .x
 t 

e ıˆ. .x  cos  .x  ıˆ.sin  .x

e ıˆ. .x  cos  .x  ıˆ.sin  .x

=> e ıˆ. .x  e ıˆ. .x  2. cos  .x

=> 
 1  2r   r. e ıˆ. .x  e ıˆ. .x 

=>  1  2r   r.2. cos  .x 

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


121/141
If we arrange,

 t  t  1  cos  .x  1  cos  .x  .x


 1  4r   and  sin 2
 t   2  2 2

 .x
=>  1  4r. sin 2
2

For stability, the value of  t  should be limited as x and t go to 0.

 t  t   .x
1 => 1  4r. sin 2 1
 t  2

 .x
( sin
2
 1 ), maximum value it can take
2

1  4r  1 in other words  1  1  4.r  1

1
=> 0r and r has a range.
2

t
r Explicit method is therefore not used.
x 2
This approach is called the Von Neumann approach.

The term with  t  should not go to  and take a limited value.

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


122/141
7.6. Formulation of Two-Dimensional Unsteady (Time-Dependent) Heat Transfer
Problems in Cartesian Coordinates

u  2 u  2 u
 
t x 2 y 2

ux, y, t   u mA,n

A  f t  , m  f x  , n  f y

u mA,n1  u mA,n u mA1,n  2.u mA,n  u mA1,n u mA,n 1  2.u mA,n  u mA,n 1
  (Explicit)
t x 2 y 2

t t 1
r1  r2  r1 , r2 
x 2 y 2 4
If a fully implicit solution is desired, the A 's on the right side of the equation become
 A  1 .

7.7. Formulation of Unsteady (Time Dependent) Heat Transfer Problems in


Cylindrical Coordinates

u
  2u
t
u  2 u 1 u 1  2 u  2 u
    ur , , z, t   u mA,n,k
t r 2 r r r 2  2 z 2

A  f t  , m  f r  , n  f   , k  f z 

umA,n1,k  umA,n ,k umA1,n ,k  2.umA,n ,k  umA1,n ,k 1 um1,n ,k  um1,n ,k


A A
  
t r 2 rm 2.r

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


123/141
1 u m, n 1, k  2.u m, n, k  u m, n 1, k u m, n, k 1  2.u m, n, k  u m, n, k 1
A A A A A A

  (Explicit)
rm2  2 z 2
rm  m.r
If a fully implicit solution is desired, the A 's on the right side of the equation become
 A  1 .

Here u ort is the weighted average of the temperatures at the lattice points surrounding

r  0 . (Because at r  0 the equation is unsolvable)

u  2 u u
 2.x 2 2   x 2 .u
t x x

u i , j 1  u i , j u i 1, j  2.u i , j  u i 1, j u i 1, j  u i 1, j


=>  2.xi2   xi2 .u i , j (Explicit)
t x  2
2.x

If a fully implicit solution is desired, the A 's on the right side of the equation become
 A  1 .

8. HYPERBOLIC EQUATIONS

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


124/141
8.1. Explicit Method and Courant-Friedrichs-Lewy Condition

The wave equation is a hyperbolic equation.

 2u  2u

t 2 x 2

u  x, t   u i , j and i  x, j t

ux,0  f x 

u x,0
t
 g x 
 Initial conditions for t 0

u0, t   0

u1, t   0
 It is homogenous, If it is “ a ” and “ b ”,

When an analytical solution is desired, we can write vx, t   ux, t   a  a  b.x

u i , j 1  2.u i , j  u i , j 1 u i 1, j  2.u i , j  u i 1, j



t  2
x 2

if arranged,

u i , j 1  r 2 .u i 1, j  2.1  r 2 .u i , j  r 2 .u i 1, j  u i , j 1 (1)

t
r
x

u i ,1  r 2 .u i 1,0  2.1  r 2 .u i ,0  r 2 .u i 1,0  u i , 1 (2)

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


125/141
Initial conditions,

ux,0  f x  => u i ,0  f i

u x,0 ui ,1  ui , 1
 g x  =>  gi
t 2.t

=> ui , 1  ui ,1  2.t.g i

If we substitute it in equation (2),

ui ,1  r 2 .ui1,0  2.1  r 2 .ui ,0  r 2 .ui1,0  ui ,1  2.t.gi 

ui ,1  
1 2
2
 
r .ui 1,0  2. 1  r 2 .ui ,0  r 2 .ui1,0  2.t.g i  (3)

Analytical solution of the wave equation by D'Alembert is that

1 
x t
u  x, t    f  x  t   f  x  t    g  .d 
2 x t 

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


126/141
If the wave equation is solved numerically with the help of equations (1) and (3), u i , j value

at the P point will depend on the value of the remaining lattice points within the ABP .
Suppose the initial conditions in DA and BE are changed. Although the change made in
these initial conditions changes the analytical solution result in P , the numerical solution
value at the point P found with the help of equations (1) and (3) will not change. In this
case, the numerical solution will not converge to the analytical solution. Then the value of
t
r should be chosen such that while there is a numerical solution at the point P , the
x
initial conditions between DE should also reflect the solution.
t
This condition, known as the Courant-Frendrich-Lewy condition, is r . Usually r  1 is
x
taken.

 2u  2u
Example: Solve the  equation.
t 2 x 2


u x,0  sin  .x  f x 
1
8
Initial conditions ( t  0 )

u x,0
 0  g x 
t

u0, t   0

u1, t   0
 Boundary conditions ( t  0 )

1 0 t
x   0.1 (divided into 10 parts) r 1 => t  0.1 becomes
10 x

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


127/141
ui , j 1  ui 1, j  ui1, j  ui , j 1 (1)

u i ,1 
1
ui1,0  ui1,0  2.t.g i,0  g i ,0  0 (2)
2

u i ,1 
1
ui1,0  ui1,0  (3)
2

u i ,0  sin0.1 *  * i 
1 1
ui ,0  f i  sin  .xi =>
8 8
xi  x0  i.x => x i  0 .1 * i

u 0, 0  0

u1,0  sin0.1 *    0.03863


1
8

u 2,0  sin0.2 *    0.07347


1
8
u 3,0  0.10113

u 4,0  0.1189

u5,0  0.125

u 6,0  0.1189

u 7 ,0  0.10113 (Since there is symmetry in the values, it will be sufficient to solve

for half of the wire.)

i0 i 1 i2 i3 i4 i5 i  10


……
x0 x  0.1 x  0.2 x  0.3 x  0.4 x  0.5 x  1.0
İnitial
t  0.0 0.0 0.03863 0.07347 0.1013 0.1189 0.125 …… 0.0
condition
From Eq.
t  0.1 0.0 0.0367 0.0699 0.0962 0.1131 0.1189 …… 0.0
(3)

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


128/141
t  0.2 0.0 0.0312 0.0594 0.0818 0.0962 0.1011 …… 0.0

t  0.3 0.0 0.0227 0.0432 0.0594 0.0699 0.0735 …… 0.0 From Eq.

t  0.4 0.0 0.0119 0.0227 0.0312 0.0368 0.0386 …… 0.0 (1)

t  0.5 0.0 0.0 0.0 0.0 0.0 0.0 …… 0.0

t  0.6 0.0 -.0119 -.0227 -.0312 -.0368 -.0386 …… 0.0

Analytical
Solution 0.0 0.0227 0.0432 0.0594 0.0699 0.0735 …… 0.0
t  0.3

1
Analytical Solution: u  sin  .x * cos  .t
8

In the first step, we use equation (3). Then we find the solution using other equations.

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


129/141
9. ELLIPTICAL EQUATIONS

9.1. Formulation and Solution of Heat Conduction Equation in Steady State in


Cartesian Coordinates

 2T  2T
 0
x 2 y 2

T x, y   Tm, n m  f x  n  f y

Tm 1,n  2.Tm,n  Tm 1, n Tm, n 1  2.Tm, n  Tm, n 1


 0
x  2
y 2

If x  y ,

Tm 1, n  Tm 1, n  Tm,n 1  Tm,n 1  4.Tm, n

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


130/141
 2T  2T q
  0
x 2 y 2 k

Tm 1, n  2.Tm , n  Tm 1, n Tm, n 1  2.Tm, n  Tm , n 1 W 


=>  
q
0 and q  2 
x 2 y 2 k m 

İf x  y ,

Tm 1, n  Tm 1, n  Tm,n 1  Tm, n 1 


q
x 2  4.Tm,n
k

9.2. Boundary Conditions

We have obtained the finite difference equation for the two-dimensional system. This
equation is valid for every node of the lattice inside the rigid body. The boundary conditions
must be known to calculate the boundary temperatures as they approach the boundary.
Let us now examine how the boundary conditions are written in terms of finite differences.
9.2.1. The Boundary Condition for Given Fluid Temperature and Film Coefficient

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


131/141
Thickness of Solid : b
dT
Fourier's Law of Heat Conduction : Q   k . A.
dn
Newton's Law of Cooling : Q  h. A.T  T 

Tm, n  Tm 1, n x Tm,n  Tm,n 1 x Tm,n  Tm,n 1


 k .y.b k b k b  h.b.y.Tm, n  T 
x 2 y 2 y

If x  y ,

1
2.Tm1,n  Tm,n1  Tm,n1   h.x T  Tm,n  h.x  2   0
2 k  k 

If the boundary consists of a corner, as shown in the figure below, the heat conduction
law, together with the Fourier and Newton rules, can be applied to the system shown in
the figure,

y Tm, n  Tm 1, n x Tm, n  Tm, n 1 y x


 k. .b k b  h1 bTm,n  T1   h2 bTm, n  T 2 
2 x 2 y 2 2

If the variable expressing the thickness of the solid body is eliminated on both sides of the
equation, the system of equations takes its final form.

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


132/141
9.2.2. Given Boundary Temperature

This is used exactly as the temperatures are given at the boundary.

9.2.3. Isolated border

It is assumed that there is no heat transfer from the boundary.

Tm,n  Tm1,n Tm,n  Tm1,n Tm,n  Tm,n1 Tm,n  Tm,n1


 k .y.b  k .y.b  k .x.b  k .x.b 0
x x y y

In systems with isolated boundary conditions, the solution can be made by taking the
symmetry of the system. as well as the expression found in “The Boundary Condition for
Given Fluid Temperature and Film Coefficient” case, the film coefficient “ h ” can be set to
“ 0 ”, the equation is obtained.

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


133/141
In this case, the general heat conduction equation becomes:

y Tm, n  Tm 1, n x Tm, n  Tm, n 1


k k 0
2 x 2 y

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


134/141
9.2.4. Given Boundary Heat Flux

If the heat flux is given at the boundary, the expression q w .y.b is put in place of the last

term in the expression obtained for the boundary where the film coefficient is given. Here,
q w is the heat flux from the system to outer space.

Example:

Tm, n  Tm 1, n Tm, n  Tm 1, n Tm, n  Tm, n 1 Tm, n  Tm, n 1


 k .y.b  k .y.b  k .x.b  k .x.b 0
x x y y
If the variables k and b are eliminated and the equality divided by x.y ,

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


135/141
Tm1,n  2.Tm,n  Tm1,n Tm,n1  2.Tm,n  Tm,n1  2T  2T
 0   0
x 2 y 2 x 2 y 2

Example:

 y  y 2  Tm, n  Tm 1, n  y  y 2  Tm, n  Tm 1, n


 k . 1 .b  k . 1 .b
 2  x1  2  x 2

 x  x2  Tm ,n  Tm ,n 1  x  x2  Tm ,n  Tm ,n 1
 k . 1 .b  k . 1 .b 0
 2  y1  2  y2

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


136/141
9.3. Curved Borders

The main benefit of the finite difference method is that it can also be used for complex
boundaries. If the boundaries of a solid body are not parallel to the coordinate axis,

 x .x  x
Dimensions of the system,     1   
2 2  2
 y  .y  y
    1   
2 2  2

y Tm , n  Tm 1, n y Tm, n  Tm 1, n


 k. 1   .b  k. 1   .b
2  .x 2 x

x Tm, n  Tm, n 1 x Tm, n  Tm, n 1


 k. 1   .b  k. 1   .b 0
2  .y 2 y

If x  y ,

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


137/141
2 2 2 2 2 2
Tm, n 1  Tm 1, n  Tm, n 1  Tm 1, n    .Tm, n  0
1    1     .1    .1      

If   1 and   1 ,

Tm,n 1  Tm 1, n  Tm,n 1  Tm 1, n  4.Tm,n  0 (general formula)

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


138/141
10. GAUSS-SEIDEL POINT BY POINT ITERATION METHOD

It is the simplest of the iteration methods, and the calculation is made by considering the
variable values at each grid point. If the finite difference equation for the grid point “ P ” is
given as follows,

a p .T p   a nb .Tnb  b

Here, the index nb denotes neighboring points.

4.Tm, n  3.Tm 1, n  2.Tm 1,n  8.Tm, n 1  3Tm, n 1  K (Example)

Tp 
a nb .Tnb*  b
ap

Tnb* , are the values of neighboring points before iteration or the first estimated values. For
each lattice point, new values can be found with the above equation. Iteration is continued

until the difference between the iterations is less than a certain  .

Example: T1  0.4 * T2  0.2


T2  T1  1.0 , Find the T1 and T2 values using the Gauss-Seidel
iteration method.

Iteration
0 1 2 3 4 5 … 
No
0 (initial
T1 0.2 0.68 0.872 0.949 0.98 … 1
prediction)

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


139/141
0 (initial
T2 1.2 1.68 1.872 1.949 1.98 … 2
prediction)

As the iteration continues, the last values that emerged in the iteration are used.

Example: Find the temperature distribution in the solid body under the boundary
conditions given in the figure, using the Gauss-Seidel iteration method. ( x  y )

4.T1  100  500  T2  T4


4.T2  500  100  T1  T3

4.T3  T2  T4  100  100

4.T4  100  T1  T3  100

T 2 T4 T 1T3
T1   150 T2   150
4 4
T 2 T4 T 1T3
T3   50 T4   50
4 4

0
Iteration
(initial 1 2 3 … 
No
prediction)

T1 300 275 257,33 252,25 … 250

T2 300 268,75 256,13 251,61 … 250

T3 200 167,19 154,17 151,12 … 150

T4 200 160,55 152,88 150,84 … 150

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


140/141
The Gauss-Seidel method does not always converge, it is sufficient to meet the
Scarborough criterion for convergence.


 1 for all equations

Scarborough criterion ;
a nb

ap

 1 for at least one equation

0.4 1.0
For example, T1  0.4 * T2  0.2  and T2  T1  1.0  satisfies Scarborough
1 1.0
criterion

But if we change the order of equations,

1.0 2.5
T1  T2  1.0  and T2  2.5 * T1  0.5   2.5 does not satisfy Scarborough
1.0 1.0
criterion.

Iteration No 0 1 2 3

T1 0 -1 -4 -11.5

T2 0 -3 -10.5 …

MM597 ADVANCED NUMERICAL METHODS IN ENGINEERS / PROF.DR. NURİ YÜCEL


141/141

You might also like