Sayısal Analiz Çalışma
Sayısal Analiz Çalışma
gokhand@yildiz.edu.tr
References:
- Chapra, S. C., & Canale, R. P. (2011). Numerical methods for engineers (Vol. 1221). New York: Mcgraw-hill.
- Zafer Kütüğ, Numerical analysis lecture notes, Yildiz Technical University,
Outline
Root finding (Slayt 1) Interpolation (Slayt 53)
Gauss siedel Finite difference for solving differential equations (Slayt 86)
Central finite difference from Taylor series (Slayt 86)
Central finite difference from Lagrange Polynomial (Slayt 92-
102)
References:
Steven C. Chapra and Raymond P. Canale, Numerical Methods for Engineers, Mc Graw
Hill Education
Sayısal analiz ders notları, Zafer Kütüğ
For solving:
However, there are many other functions for which the root cannot be
determined so easily.
1.1) Bisection (Bifurcation method)
The bisection method is a numerical algorithm used to
find the roots of a given function.
The bisection method, which is alternatively called
binary chopping, interval halving, or Bolzano’s method,
is one type of incremental search method in which the
interval is always divided in half.
If a function changes sign over an interval, the function
value at the midpoint is evaluated. The location of the
root is then determined as lying at the midpoint of the
subinterval within which the sign change occurs. The
process is repeated to obtain refined estimates.
The basic idea of the method is to repeatedly divide
an interval in half and then select the subinterval in
which the root must lie, until the interval becomes
sufficiently small to obtain the desired accuracy.
1.1) Bisection (Bifurcation method)
25
1.5) Newton-Raphson method
Common derivatives:
1.5) Newton-Raphson method
Diagonal matrix
2) Solution of linear systems
Upper triangular matrix
z11=3x5+1x7=22
z12=3x9+1x2=29
z21=8x5+6x7=82
z22=8x9+6x2=84
z31=0x5+4x7=28
z32=0x9+4x2=8
2) Solution of linear systems
Inverse of matrix
2) Solution of linear systems
Inverse of matrix
1 2 −1 1 0 0
−2 0 1 I= 0 1 0
1 −1 0 0 0 1
Row operations
1 1 2
1 1 1
2 3 4
2) Solution of linear systems
Determinant of matrix
2.1) Cramer Method
2.1) Cramer Method
Det(A)
Cramer rule:
-1 1 2 Det(A) 2
-4 -1 2
-2 -1 4
Det(A) 18 x1 9
1 -1 2
2 -4 2
4 -2 4
Det(A) 12 x2 6
1 1 -1
2 -1 -4
4 -1 -2
Det(A) -16 x3 -8
2.1) Cramer Method
Example 2: Solve the followings using Cramer rule
2 A b By hand
2 -1 1 3 -1 2 -1 1 3
1 1 -1 -4 6 1 1 -1 -4
3 -1 1 1 4 3 -1 1 1
1 3 0 3 -5 1 3 0 3
Det(A) 15 1 -1 -4 Det
+ 2 -1 1 1 9
-1 -1 1 3 3 0 3
6 1 -1 -4
4 -1 1 1 1 -1 -4 Det
-5 3 0 3 - -1 3 1 1 15
1 0 3
Det(A) 15 x1 1
1 1 -4 Det
2 -1 1 3 + 1 3 -1 1 -54
1 6 -1 -4 1 3 3
3 4 1 1
1 -5 0 3 1 1 -1 Det
- 3 3 -1 1 -12
Det(A) -6,7E-15 x2 -4,4E-16 1 3 0
2 -1 -1 3
1 1 6 -4 Det(A) 15
3 -1 4 1
1 3 -5 3
Det(A) 45 x3 3
2 -1 1 -1
1 1 -1 6
3 -1 1 4
1 3 0 -5
Det(A) -30 x4 -2
2.2) Gauss Elimination !
Transforming a matrix to a row echelon form
2.2) Gauss Elimination
Example 1: Use gauss elimination method
1
R1 3 2 1 5
R2 2 5 1 -3
R3 2 1 3 11
R1 1 1 -1 -2
x + y – z = -2 R2-2R1 0 -3 3 9
R3+R1 0 3 1 -1
2x – y + z = 5
R1 1 1 -1 -2
-x + 2y + 2z = 1 R2 0 -3 3 9
R3+R2 0 0 4 8
R1 1 1 -1 -2
R2/-3 0 1 -1 -3
R3/4 0 0 1 2
R1 x y (-z) -2 x 1
R2 y (-z) -3 y -1
R3 z 2 z 2
2.3) Jacobi method
Each unknown is placed alone at the left side of the equation
Start finding the solution by using initial values (i.e., 0, 0, 0) and then continue
iteratively
1
n x1 x2 x3
1 0 0 0
2 1,833333 0,714286 0,2
3 2,038095 1,180952 0,852381
4 2,084921 1,053061 1,08
5 2,004354 1,001406 1,038209
6 1,994101 0,990327 1,001433
7 1,996537 0,997905 0,994951
8 2,000143 1,000453 0,998469
9 2,000406 1,000478 1,00021
10 2,000124 1,000056 1,000273
11 1,999973 0,999958 1,000047
2.3) Jacobi method
Example 2: Use Jacobi method by using (1,1,1) initial values
2
k 0 x1 x2 x3
x1 0,333333 7,85 0,1 0,2
x2 0,142857 -19,3 -0,1 0,3
x3 0,1 71,4 -0,3 0,2
n x1 x2 x3
1 1 1 1
2 2,716667 -2,72857 7,13
3 3,001048 -2,49038 7,003929
4 3,000583 -2,49985 7,000161
5 3,000016 -2,5 6,999986
6 2,999999 -2,5 6,999999
7 3 -2,5 7
8 3 -2,5 7
9 3 -2,5 7
10 3 -2,5 7
11 3 -2,5 7
2.4) Gauss-Siedel
Similar to Jacobi method but show difference in terms of iteration
When we find x1, this is used exactly for the following variable (i.e., x2)
1
n x1 x2 x3 Error 1 Error 2 Error 3 Error
1 0 0 0
2 1,833333 1,238095 1,061905
3 2,069048 0,934694 1,061905
4 1,967914 1,002041 0,987687
5 2,002732 0,994351 0,994399
6 1,99905 1,002381 0,998287 0,003682 0,00803 0,003888 0,009652
7 2,001079 1,000218 1,000762 0,002029 0,002163 0,002476 0,003863
8 1,999946 1,000091 1,000303 0,001134 0,000128 0,000459 0,00123
9 1,99998 0,999898 1,000025 3,4E-05 0,000193 0,000278 0,00034
10 1,999962 0,999987 0,999955 1,79E-05 8,91E-05 7,03E-05 0,000115
11 2,000003 1,000002 0,999987 4,14E-05 1,5E-05 3,2E-05 5,45E-05
2.4) Gauss-Siedel
Example: : Use Gauss-siedel by using (1,1,1) initial values
2
k 0 x1 x2 x3
x1 0,333333 7,85 0,1 0,2
x2 0,142857 -19,3 -0,1 0,3
x3 0,1 71,4 -0,3 0,2
n x1 x2 x3
1 1 1 1
2 2,716667 -2,7531 7,003438
3 2,991793 -2,49974 7,000252
4 3,000026 -2,49999 6,999999
5 3 -2,5 7
6 3 -2,5 7
7 3 -2,5 7
8 3 -2,5 7
9 3 -2,5 7
10 3 -2,5 7
11 3 -2,5 7
3) Interpolation (Curve fitting)
While the exact values are obtained at the points given in the
Lagrangian Polynomial, approximate results are obtained at the
intermediate values.
As in all polynomial fittings, the degree of the polynomial must
be at least 1 order less than the given number of points. For
instance, the polynomial to be fitted for 4 fn values
corresponding to the 4 Xn points can be maximum 3rd order.
Lagrange approximation polynomial:
3.1) Lagrange Polynomial
Example 1: Find a 3rd order polynomial using Lagrange Polynomials with the
following values obtained during an experiment.
0 1 2 3 4
x 3.2 2.7 1.0 4.8 5.6
f ( x) 22.0 17.8 14.2 38.3 51.7
3.1) Lagrange Polynomial
Example 2: According to the provided a and cos(a) values find cos(8040’) use
Lagrange third order polynomial.
xi yi Df D2 f D3 f
x0 0.4 1.491825 (f0)
Delta x 0.1 0.156897
x 0.54 x1 0.5 1.648721 0.016501 (f1)
0.173398 0.001735
x2 0.6 1.822119 0.018236 (f2)
0.191634
x3 0.7 2.013753 (f3)
n
0 a0 1.491825
1 a1 1.568966
2 a2 0.825048 Eğri 1.7160
3 a3 0.289237
xyii e xi
xi yi Df D2 f D3 f
Check x0 0.0585 0.14201 (f0)
Delta x 0.0185 0.0185 0.03575
x 0.08 x1 0.077 0.17776 -0.00401 (f1)
0.03174 0.00104
x2 0.0955 0.2095 -0.00297 (f2)
0.02877
x3 0.114 0.23827 (f3)
n
0 a0 0.14201
1 a1 1.932432
2 a2 -5.85829 Eğri 0.183152
3 a3 27.37581
3.4) Least Squares
The Least Squares Method is one of the most widely used interpolation methods.
The reason why it is so preferred is that it is not only easy to remember, but also
very good in precision. However, it is not preferred to obtain polynomials larger
than the 4th or 5th order because of the difficulty and the low sensitivity of the
approximate results.
Finding the difference between Y and the polynomial:
3.4) Least Squares
The calculation of the area under the curve by combining the subregions
divided into finite and equally spaced parts under the f(x) function with the
quadratic parabolic curves is called the 1/3 Simpson Integration Method. The
reason why the method is named this way is that the coefficient of 1/3 is found
in the formulation of the method:
4.3) 3/8 Simpson Integration Method
Computing the area under the curve by combining the subregions divided into
finite and equally spaced segments under the F(x) function with third-degree
cubic curves is called the 3/8 Simpson Integration Method. The reason why the
method is named this way is that there is a coefficient of 3/8 in the formulation
of the method.
Example: Take the integration of the following function using 1/3 Simpson
method by dividing 6 equal intervals between x0=0 and x1= 𝜋/2
Example: Take the integration of the following function using 1/3 Simpson
method by dividing 8 equal intervals between x0=1 and x1=2
Example: Take the integration of the following function by dividing 8 equal
intervals between x0=0 and x1= 2. Use 3/8 Simpson method for the first 6
intervals and 1/3 Simpson method for the last 2 intervals.
Example: Using the tabulated values of the f(x) function given in the table
below, calculate the integral over the range from x0=a=0.7 to xn=b=2.1.
Consider the followings:
a) First 3 intervals using 3/8 Simpson and last 4 intervals using 1/3 Simpson
b) First 4 intervals 1/3 Simpson and last 3 intervals 3/8 Simpson
c) First 6 intervals 3/8 Simpson and last interval Trapezodial
d) First interval Trapezodial and the following 6 intervals 3/8 Sİmpson
a) First 3 intervals using 3/8 Simpson and last 4 intervals using 1/3 Simpson
b) First 4 intervals 1/3 Simpson and last 3 intervals 3/8 Simpson
c) First 6 intervals 3/8 Simpson and last interval Trapezodial
d) First interval Trapezodial and the following 6 intervals 3/8 Sİmpson
5) Numerical Differantiation
5.1) Taylor series
If the function f(x) around x0=0 is continuous, that is, if it and its derivatives f',
f'' ..., f(n), the function around x0=0:
Find one solution of the differantial equation based on the conditions using
Taylor series
x y
0
0.1
0.2
0.3
0.4
0.5
0.6
5) Numerical Differantiation
5.1) Taylor series
Example:
Find one solution of the differantial equation based on the conditions using
Taylor series, consider first five expressions in the series.
x
0
0.1
0.2
0.3
0.4
0.5
0.6
5) Numerical Differantiation
5.2) Euler method
If h is small enough, first-order linear differential equations can be solved
using the first two terms of the Taylor Series.
5) Numerical Differantiation
5.2) Euler method
Example 1: Use Euler method
n x y yg Delta y n x y yg Delta y
0 0 0 0 -1 -1 0
1 0.1 1 0.1 -0.9 -0.91451 0.014512
2 0.2 2 0.2 -0.83 -0.85619 0.026192
3 0.3 -0.787 -0.82245 0.035455
3 0.3 4 0.4 -0.7683 -0.81096 0.04266
4 0.4
5) Numerical Differantiation
5.2) Euler method
Example 2: Use Euler method
If y(g)= and fill the table and find the errors in each step:
n x y yg Delta y
0 0 1.000000 1 0
1 1 0.990000 1.135335 0.145335
2 1.01 1.000200 1.142655 0.142455
3 1.02 1.010396 1.150029 0.139633
4 1.03 1.020588 1.157454 0.136866
5 1.04 1.030776 1.16493 0.134154
6 1.05 1.040961 1.172456 0.131496
6) Finite difference
6.1)Central finite difference from Taylor series
Consider Taylor series of F(x) at xi-1=xi – Δx and xi+1=xi + Δx
(-1)* Eq. 17 + 1*(Eq 18) and take the first five terms:
Eq 20 – Eq 19
6) Finite difference
6.1)Central finite difference from Taylor series
(4)* Eq. 11 + 4*(Eq 12) and take the first five terms:
(1)* Eq. 17 + 1*(Eq 18) and take the first five terms:
Eq 23 – Eq 22
6) Finite difference
6.1)Central finite difference from Taylor series
Central finite difference:
6) Finite difference
6.2)Central finite difference from Lagrange Polynomial
We need to write a Lagrange polynomial passes three and five points:
Write x=x0
6) Finite difference
6.2)Central finite difference from Lagrange Polynomial
Write x=x0
6) Finite difference
6.2)Central finite difference from Lagrange Polynomial
Example: y(0) = 1, y’(0)=-2,, use central finite differnece formulation to solve
for 6 points with Δx=0.1. (Gökhan)
6) Finite difference
6.2)Central finite difference from Lagrange Polynomial
Differential equation:
Conditions:
6) Finite difference
6.2)Central finite difference from Lagrange Polynomial
3a A b
A) 5 -4 1 0.238095 0.238095238
-4 6 -4 0.238095
1 -4 5 0.238095
Det(A) 16
0.238095 -4 1
0.238095 6 -4
0.238095 -4 5
5 0.238095 1
-4 0.238095 -4
1 0.238095 5
5 -4 0.238095
-4 6 0.238095
1 -4 0.238095