Mm597 Advanced Numerical Methods in Engineers
Mm597 Advanced Numerical Methods in Engineers
ADVANCED NUMERICAL
METHODS IN ENGINEERS
Sometimes, we encounter problems such as finding the roots of equations of the form
f x 0
To find the roots of an equation given by the function f x 0 , let's open the Taylor
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
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.
f x e x x 3 3.x 4
2
f x 2 x e x 3x 2 3
2
x4 0.851049
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.
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 xn1 / xn xn1
f x n * x n x n 1
x n 1 x n
f xn f xn1
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.
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
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
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
happen, the matrix must be a square matrix and its determinant must be different from
"0")
1
cofactor of Cij 1i j M ji
C
ij
C C
8 0 1
Example-3: Find the inverse of C 3 2 1
1 4 0
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*
c111
1 11
M 11
4 0
4
4
C 18 18 18
0 1
1*
c121
11 2
M 21
4 0
4
4
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 23
M 32
3 1
5
5
C 18 18 18
3 2
1*
1
c31
1
31
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
133 M 33
3 2
16 16
C 18 18 18
4 4 2
1
C 1
1 1 5
18
14 32 16
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...
11 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
23
=> 3 3 0
14 6
14 6 0
Matrix Representation of Systems of Linear Equations
C. X R
detC k
Xk
detC
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,
C. X R
=> C 1 .C. X C 1 .R
I . X C 1 .R
X C 1 .R
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
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
C. X R
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
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.
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
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
1 1 / 3 1 / 3 x1 2 / 3
=>
0 1 4 / 11 x 34 / 11
2
0 0 1 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
f x dx f c j 1 x j x j 1
b n
a j 1
ba
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
mb 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
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
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
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
=> f ( x)
1
y0 y1 x1 x0 1 y1 y2 x2 x1 ...... 1 yn1 yn xn xn1
2 2 2
ba
h
n
Error, E
b a f c h 2 acb
12
b
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
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
sinx dx ?
2
Example:
0
=>
Error, E
b a f c .h 4 Oh 4 acb
180
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
f x dx 3 y 4 y1 y 2
h
0
a
b
f x dx 1 42.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
lnx
0.8 1
e dx ? x 1 dx ?
x 2
3) 4)
0 0.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
*
1 n
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".
2.P2 x 3 x.P1 x P0 x 0
3x 2 1
=> P2 x
2
wk
2 1 xk
2
n Pn1 xk
Weight Function : 2 2
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
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 12n! 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.
ba n
*
b
f y dy wi . f y i Rn
a 2 i 1
ba ba
yi xi
2 2
1
Example: Calculate the integral x
2
cosx 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
cosx dx w1 . f x1 w2 . f x2 w3 . f x3
1
1
1
0.555556 * 0.77459 * cos 0.77459
2
1
x
2
cosx dx 0.47650
1
1
20 3
2
0 wi . f y i
y
e dy
2 i 1
ba ba
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
20 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
f x
1
1 1 x2
dx , The integral has singular points in x 1 . if we try to solve
Tn x cosn.arccos x i
f x
1 n
=> dx wi * f x i Rn , wi
1 1 x2 i 1 n
If Tn x cosn.arccos x i 0 ,
n * arccos xi
2i 1 becomes.
2
=> arccos xi
2i 1
2n
2i 1
cosarccos xi cos
2n
2i 1
=> xi cos
2n
Error function, Rn f 2 n c , 1 c 1
2n!*2 2 n 1
formula.
2i 1
xi cos
2n
i 1 2 *1 1 3
For x1 cos cos
2*3 6 2
i2 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
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 i2 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 ba n
b
dy wi * f yi Rn
a y a b y 2 i 1
ba ba
yi xi
2 2
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
sinx dx ?
0
f x sinx
n
0 i 0
n 2 6 10 14
n
w * sinx
i 0
i i 0.43 0.50005 0.500002 0.500000
n
e
x2
f x dx wi * f xi Rn
i 1
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
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
cos x 1 x2
1 1
7)
1 1 x2
dx ? 8)
1 1 x2
dx ?
b d
I f x, y .dy.dx
x a y c
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
xa
2
xa j 1
m
d c b a n
I wk w j * f xk , y j
2 2 k 1 j 1
ba ba
xk xk
2 2
b a d c
wk * w j * f xk , y j
n m
I
4 k 1 j 1
2 1
dy.dx 2 01 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
ba ba
xk xk xk 1
2 2
yj xj
If we assume m n 2,
w1 w2 1
2 1
dy.dx 2 01 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
ba 2
x
I x y.e y dy wi * f y i
2
0 2 i 1
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
0.57735 1
x1 0.788675
2 2
=> 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
h2 h3
f x h f x h. f x f x f x ...
2! 3!
f x h f x h h2
=> f x f x f x ...
h 2 6
f x h f x
=> f x Oh (Forward Difference Formula)
h
f x => fi
f x h => f i 1
f i 1 f i
=> f i Oh (Forward Difference Formula)
h
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 Oh
h
f i f i 1
=> f i Oh (Backward Difference Formula)
h
Operators
f
f i f i 1 f i => f i i Oh (Forward Difference Formula)
h
f
f i f i f i 1 => f i i Oh (Backward Difference Formula)
h
In order to calculate the quadratic forward difference formula, the solution is obtained by
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!
f x 2h 2 f x h f x
=> f x hf x ...
h2
f i 2 f i 1 f i 2
f i Oh (Quadratic Backward Difference Formula)
h2
2 f i
2 f i f i 2 2 f i 1 f i => f i Oh
h2
2 fi
2 f i f i 2 f i 1 f i 2 => f i Oh
h2
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
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
dn f n f j
Oh Forward Difference Formula
dx n xj
hn
dn f n f j
Oh 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
n f n1 n f n1
n
d f j j
2 2
O h2 , if n is odd
dx n xj
2h n
n f j n 1 f j 1 n1 f j
n f j n 1 f j n 1 f j 1
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
Oh
2
xj
d2 f
f j 1
f j f j f j 1 f j 1 f j f j f j 1 Oh
2
dx 2 xj 2h 2
d2 f
f j 1 2 f j f j 1 Oh
2
dx 2 xj h 2
x 0 1 2 3 4 5
Find the third derivative of the function f(x) at x 0, 1, 2 using the forward difference
formulas.
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
d3 f 3 f j
Oh
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
f x h f x h h2
f x f x f x ...
h 2 6
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 i2 4 f i1 3 f i
f i Oh 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)
1)
x 0 0.5 1.0 1.5 2 2.5 3.0
Solve by all approximations f 1.5 and f 1.5 so that the error order of O 0.5 2
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 xx h x 2h 3
f x f 0
x
f 0 2
f0 f 0 ...
h 2!.h 3!.h 3
If the data are equally spaced, the Gregory-Newton interpolation formula is used to
interpolate or extrapolate.
f x -7 -3 6 25 62 129
When we look at the values, since there are more points beyond the 1.1 point, the forward
difference formula will be used.
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 94 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 85 3 43 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 )
f 1.1 f 1
1.1 1 f
1.1 11.1 1 1 2 f
0.10.1 10.1 2 3
f1
1 2 1
1 2!.1 3!.13
0.10.1 10.1 20.1 3 4
f1
4!.14
f 1.1 2.40465
n
Pj x A j ( x xi )
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
0 k0
=> 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
x x
i 0
i
Pj x
i j
x xi
n
j
i 0
i j
=> 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
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
Find the Lagrange polynomial for the data given. Calculate the f 1 value.
5.3) Extrapolation
x 1 2 3 4 5
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 hx 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 - - -
x n 5 (closest to 5.7)
x 5.7
h 1
f 5.7 23.163
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 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.
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
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
There are (3n) unknowns in total consisting of a's, b's and c's.
i) At internal data points, the function values must be equal to the data values.
ii) First and last functions must pass through first and last data points.
a n .x n2 bn .x n c n f x n
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.
calculate f 5 .
i 0 1 2 3
Here n=3 and 3n=9 unknowns. If we write the 9 equations that depend on these 9
unknowns,
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
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
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.
=> 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.
Since the number of equations is too large during these operations, a set of equations has
been developed for each region and generalized as;
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
f 3 and f 9 values are equal to zero from the 5th condition. In this case, the above
equations take the form:
f 3
4.5 x 3 f 4.5 x 33 2.5 f 34.5 34.5 x
f1 x
64.5 3 64.5 3 4.5 3 6
1 f 4.54.5 3
x 3 , i 1
4.5 3 6
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
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.)
The optimal curve is defined as the curve that minimizes the sum of the squared errors.
xi yi
x1 y1
x2 y2
. .
. .
. .
xn yn
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
n6
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
Sr
Sy/x S y / x : Standard deviation
n2
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.
St 0
r2 r 1 r2
St
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
Sr 0.08562
Sy/x 0.14630 (standard error)
n2 62
S t S r 1.3153 0.08562
r2 0.935
St 1.3153
=> r 0.9669
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
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
Standard deviation,
Sr
Sy/x
n m 1
Coefficient of determination,
St S r
r2
St
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
n6
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
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
a 0 0.587114
a1 0.059102
a 2 1.729537
NOTE: Calculate correlation coefficient. Compare result with the linear regression result.
Probably here r=0.98.
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
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.
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.
y f x, y and y x 0 y 0
y 0 yx 0
y1 y x 0 h
y 2 y x 0 2h
.
.
.
y n y x 0 nh
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.
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
f x, y x dx f x, y x dy
y x . .
x dx y dx
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
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 1x 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
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
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.
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.11 sin 4.7 0.1682
2 2
0.1
2
0.1682
2
C 0 0.11 sin 4.7 0.1884
2 2
D0 0.1 1 0.1 sin4.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
y f x, y, y yx0 A y x 0 B
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 1h
y j 1 y j h. y j
h2
2!
y j O h 3
y j 1 y j h. y j Oh 2
First we will take j 0 , and calculate y 0 , y1 and y1 . Then take j 1 and calculate y1 ,
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: j0
y1 1 0.1 * 3
0.12 2.666974 0.686665
2
y1 3 0.1* 2.666974 3.2666974
Step 2: j 1
Step 3: j2
y 3 y 1.3 0.018939
y f 2 x, y, y y x0 y 0 y x 0 P0
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 n1 y n
1
k1 2.k 2 2.k 3 k 4
6
p n1 p n
1
l1 2.l2 2.l3 l4
6
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.22 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.22 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.22 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
Analytical solution
x sin4. lnx
1 2
y
2
y1.2 0.23137
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 hy 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.
ba
h
n
x j x0 j.h
x j a j.h
y j f x j , y j , y j
y j 1 2. y j y j 1
yj
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 ya and yb 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.
b a 1 0
h 0.1
n 10
yj x j 2 y j yj
=>
h
h
1 y j 1 2 2h y j 1 y j 1 h .x j
2 2
2 2
Except “j=0” and “j=10”, for j=1,2,3…, (n-1) values, the set of linear equations:
If the boundary conditions are entered, the first and last equations become:
y 0 y0 1
y 1 y10 3
y0 1
y10 3
HOMEWORK
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
yi 1 C.h 2 2 . yi yi 1 h 2 . f xi (1)
y 1 C.h 2 2 . y 0 y1 h 2 . f x 0
(2)
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,
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 im (3)
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 im
2 2
2 2.h. 1 2.h. 1
h .C 2 y 0 2. y1 h 2 . f x 0 i0
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 i2
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 im
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.
y 1 y1
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
x i i.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
y 1 2.h. y 0 y1 0 i0
y1 y 1
y 0 0 => 0 => y 1 y1
2.h
=> y1 2.h. y 0 y1 0
y0 0 i0
h h
1 1 .m y m 1 2.h m. y m 1 1 .m y m 1 0 im
2 2
y m 1 y m 1 1
ym
2.h 2
=> y m 1 y m 1 2.h. y m h
h
2m. y m 1 2h h 2 2 .m. y m h 1 1 m
2
for im
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
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 ; y0 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 y0 , 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
yB when it goes to x . Then a new predict value is calculated for y when it goes
A
ca f ( xn )
A B / a b xn1 xn
f ( xn )
f ( xn )
x n 1 x n
f ( x n ) f ( x n 1 )
x n x n 1
Differential equation ; y 4. y 1
y
1
Boundary conditions ; y0 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
y0 0
If y 0 p0 a 1 is chosen
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
It is found at y4.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 .
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
u 2 u
t x 2
u x, t u i , j ix 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.
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.
1
ux,0 2.x 0 x
2
Initial condition
1
ux,0 2.1 x x 1
2
u0, t 0
u1, t 0
Boundary conditions
ui , j 1
1
ui1, j 8.ui, j ui1, j
10
xi x0 i.x => x i 0 .1 * i
If xi 0.1 * i ,
1 1
ux,0 2.x 0 x => u i ,0 2.x 0.2 * i 0 x
2 2
1 1
sin n. sin n. .x .e n t
8
u n
2 2
2
2
n 1 2
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
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
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
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
1
are valid for the 0r 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
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
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.
u 2 u
t x 2
1
ux,0 2.x 0 x
2
Initial condition
1
ux,0 2.1 x x 1
2
u0, t 0
u1, t 0
Boundary conditions
t
=> r 1
x 2
If we take j 0,
Since xi 0.1 * i ,
1 1
ux,0 2.x 0 x => u i ,0 2.x 0.2 * i 0 x
2 2
1 1
ux,0 2.1 x x 1 => ux,0 2.1 x 2.1 0.1* i x 1
2 2
Unknowns Knowns
u1 4.u 2 u 3 u1 u 3 i2
u 2 4.u 3 u 4 u 2 u 4 i 3
u 3 4.u 4 u 5 u 3 u 5 i4
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 ,
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.
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.
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
u1, j u 0, j
hu 0, j v
x
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
hu 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, jt . 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 .
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
If n 10 is chosen,
1
n 10 => x 0.1
10
If i 10 ,
u11, j u9, j
u10, j => u11, j u 9, j 2.x.u10, j
2.x
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
u 0, j 1
1
2
0.9 * u 0, j u1, j i0
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
. . . . . . .
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
. . . . . . .
Example: Solve the same problem with the forward (backward) finite difference expansion
for boundary conditions and the differential equation with the explicit method.
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 ,
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
. . . . . . .
. . . . . . .
. . . . . . .
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.
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)
if x 0.1 is chosen and r 1 is taken, when equations (2) and (3) are substituted and
arranged in equation (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
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,
. . . . . . .
. . . . . . .
. . . . . . .
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:
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
Ot Ox
2
=>
t 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
be determined, and as t gets larger, the criterion for t to be limited can be determined.
t t
As time progresses 1 must be (convergence condition).
t
u i , j t .e ıˆ . x
u i , j 1 t t .e ıˆ . x
t t .eıˆ . x r. t .eıˆ . xx 1 2r . t .e ıˆ . x r. t .e ıˆ . xx
t t
r.e ıˆ. .x 1 2r r.e ıˆ. .x
t
=>
1 2r r. e ıˆ. .x e ıˆ. .x
.x
=> 1 4r. sin 2
2
t t .x
1 => 1 4r. sin 2 1
t 2
.x
( sin
2
1 ), maximum value it can take
2
1
=> 0r and r has a range.
2
t
r Explicit method is therefore not used.
x 2
This approach is called the Von Neumann approach.
u 2 u 2 u
t x 2 y 2
ux, y, t u mA,n
A f t , m f x , n f y
u mA,n1 u mA,n u mA1,n 2.u mA,n u mA1,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 .
u
2u
t
u 2 u 1 u 1 2 u 2 u
ur , , 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
(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
u 2 u u
2.x 2 2 x 2 .u
t x x
If a fully implicit solution is desired, the A 's on the right side of the equation become
A 1 .
8. HYPERBOLIC EQUATIONS
2u 2u
t 2 x 2
u x, t u i , j and i x, j t
ux,0 f x
u x,0
t
g x
Initial conditions for t 0
u0, t 0
u1, t 0
It is homogenous, If it is “ a ” and “ b ”,
if arranged,
t
r
x
ux,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
ui ,1
1 2
2
r .ui 1,0 2. 1 r 2 .ui ,0 r 2 .ui1,0 2.t.g i (3)
1
x t
u x, t f x t f x t g .d
2 x t
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
u0, t 0
u1, t 0
Boundary conditions ( t 0 )
1 0 t
x 0.1 (divided into 10 parts) r 1 => t 0.1 becomes
10 x
u i ,1
1
ui1,0 ui1,0 2.t.g i,0 g i ,0 0 (2)
2
u i ,1
1
ui1,0 ui1,0 (3)
2
u i ,0 sin0.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
u 4,0 0.1189
u5,0 0.125
u 6,0 0.1189
t 0.3 0.0 0.0227 0.0432 0.0594 0.0699 0.0735 …… 0.0 From Eq.
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.
2T 2T
0
x 2 y 2
If x y ,
İf x y ,
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
If x y ,
1
2.Tm1,n Tm,n1 Tm,n1 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,
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.
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.
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:
Example:
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
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
If x y ,
If 1 and 1 ,
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
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
Iteration
0 1 2 3 4 5 …
No
0 (initial
T1 0.2 0.68 0.872 0.949 0.98 … 1
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 )
T 2 T4 T 1T3
T1 150 T2 150
4 4
T 2 T4 T 1T3
T3 50 T4 50
4 4
0
Iteration
(initial 1 2 3 …
No
prediction)
1 for all equations
Scarborough criterion ;
a nb
ap
0.4 1.0
For example, T1 0.4 * T2 0.2 and T2 T1 1.0 satisfies Scarborough
1 1.0
criterion
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 …