Beruflich Dokumente
Kultur Dokumente
(kishalay@iith.ac.in)
Tue / Thu: 11:30 AM 1 PM
Room # 132
Indian Institute of Technology Hyderabad
Overview
Topics
Examples
Topics
Examples (contd.)
Topics
ODE - IVPs
ODE - BVPs
Evaluation
No.
Type
Final
Weightage
Tentative
Time
Remarks
1.
30
End Sept.
Absolute
Grading
2.
30
End Nov.
Absolute
Grading
3.
15+15
Almost
each
class
Relative
Grading
4.
10
85%
attendance
Total = 100
Programming Practices
Problems
3!
5!
7!
2n 1!
Sum e a a k / k!
Use of subroutines (preferably)
Programming
Programming Review
EVALUATE S = 1 + 2 + 3 + . + n
and COMPARE WITH analytical results
S = n(n + 1)/2
PLOT S vs. n
Chapter 1
LINEAR ALGEBRIC EQUATIONS
GAUSS ELIMINATION
THOMAS ALGORITHM
LU DECOMP
Representing MENU
SET OF M EQUATIONS IN N UNKNOWNS
SIMULTANEOUS LINEAR ALGEBRAIC
EQUATIONS
NLE
SLE
9
Cramers Rule
Example 1.1
X1 + X2 = 4
2X1 + 3X2 = 11
In case A is singular
10
Reviewing Rank r
(AUGMENTED A Aug A)
Aug A [ A b]
1 1 4
2 3 11
1 1
2 3 0
r=2
r=1
11
Solution exists
IF and ONLY IF
COMPATABLE EQUATIONS
IF r (A) = N
UNIQUE SOLUTION
IF r (A) < N
INFINITE SOLNS
12
Example
Example 1.3
X1 + X2 = 4
2 X1 + 3 X2 = 11
2 X1 + 3 X2 = 11
4 X1 + 6 X2 = 22
2 X1 + 3 X2 = 11
4 X1 + 6 X2 = 20
13
Homogeneous Case
ANxN xNx1 = bNx1
IF
Homogeneous equations
a11x1 + a12x2 = 0
a22x1 + a22x2 = 0; AND r(A) = 2 = N
Unique Solution
Trivial solution
4 2
14
r(A) = 1
Nr=21=1
ASSUME x1 = 5; THEN x2 = -10
x1 = 10; THEN x2 = -20
15
Review
= : FOCUS ON ONLY
HOMOGENEOUS EQUATIONS (b = 0)
16
Direct Methods
()
Ax=b
RANK =
17
G E Example
Example 1.4
18
Direct Methods
PIVOT
()
Ax=b
RANK =
19
G E (contd.)
PIVOT
20
G E (contd.)
Computational Complexity
22
Pivoting
NOTE
G E Example (Pivoting)
Example 1.5
24
Pivoting Practice
25
Thomas Algorithm
Finite Difference BVP
Stage operations
26
27
LU Decomposition (Factorization)
Cases where A does not
change but b changes
1
(1)
a 21
(1)
a11
(1)
a 31
(1)
a11
L
.
.
.
(1)
a N1
(1)
a11
a (322 )
a (222 )
a (NN,N1)1
a (NN11, N) 1
.
.
Multiplying factors are multiplied with the pivot row and added
with the other rows we take ve of multiplying factors
28
LU Decomp (contd.)
We can show
A = L U;
Ly=b
A x = L (U x) = b
SOLVE BY FORWARD /DOWNWARD SWEEP
Ux=y
1
(1)
a 21
(1)
a11
(1)
a 31
(1)
a11
L
.
.
.
(1)
a N1
(1)
a11
a (322 )
a (222 )
a (NN,N1)1
a (NN11, N) 1
.
.
29
LU Decomp Example
Example 1.8
Ly=b
Ux=y
Solution: [-11 5 4]
30
LU Decomp Example
7 1 2 x1 15
1 5 1 x 14
2
2 3 9 x 3 35
1
2 x1
15
1
1
1
1
1 ( )7 5 ( )1 1 ( )2 x 2 14 ( )15
7
7
7
7
2 ( 2 )7 3 ( 2 )1 9 ( 2 )2 x 3 35 ( 2 )15
7
7
7
7
By R2 (1/7) R1 &
R3 (2/7) R1
7 1
34
0
0 19
M21 = (1/7)
M31 = (2/7)
2 x1 15
5 83
x 2
7
7
59 x 3 215
7
7
31
LU Decomp Example
7 1
34
0
0 19
2 x1 15
5 83
x 2
7
7
59 x 3 215
7
7
By R3 (19/34) R2
7
0
1
34
7
0
U 0
M21 = (1/7)
M31 = (2/7)
M32 = (19/34)
2
15
x
1
5
83
x 2
7
7
59 19 5 x 3 215 19 83
7 34 7
7 34 7
32
1
34
7
0
2
5
7
1911
238
0
0
1
L 1 / 7
1
0
2 / 7 19 / 34 1
LU Decomp Example
1
34
7
0
2 x1 15
5 83
x 2
7
7
1911 x 3 5733
238
238
By GE, x1 = 1, x2 = 2, x3 = 3
Ux=y
Ly=b
0
0 y1 15
1
Ly 1 / 7
1
0 y 2 14
2 / 7 19 / 34 1 y 3 35
By Forward Sweep, y1 =
15, y2 = 83/7, y3 = 5733/238
Ux 0
1
34
7
0
2 x1 15
5 83
x 2
7
7
1911 x 3 5733
238
238
By Backward Sweep, x1 =
1, x2 = 2, x3 = 3
33
LU Different b
0
0 y1 45
1
Ly 1 / 7
1
0 y 2 35
2 / 7 19 / 34 1 y 3 77
By Forward Sweep, y1 =
45, y2 = 200/7, y3 =
11466/238
Ux 0
1
34
7
0
2 x1 45
5 200
x 2
7
7
1911 x 3 11466
238
238
By Backward Sweep, x1 =
4, x2 = 5, x3 = 6
34
LU Factorization
7 1 2
L11
A 1 5 1 LU L 21
2 3 9
L 31
0
L 22
L 32
0 U11
0 0
L 33 0
U12
U 22
0
U13
U 23
U 33
Doolittles Method
L11 L 22 L 33 1
L11U11 7 U11 7; L 31U11 2; L 31
Row Column
multiplication:
9 equations,
12 unknowns
3 to be assumed
2
7
19
34
1
;
7
34
7
5
7 35
L 21U12 L 22 U 22 5 U 22
L 21U13 L 22 U 23 1 U 23
1911
238
0
0 7
1
2
1
A 1 / 7
1
0 0 34 / 7
5 / 7
2 / 7 19 / 34 1 0
0
1911 / 238
U same as GE
Indian Institute of Technology Hyderabad
LU Factorization (contd.)
7 1 2
L11
A 1 5 1 LU L 21
2 3 9
L 31
0
L 22
L 32
0 U11
0 0
L 33 0
U12
U 22
0
U13
U 23
U 33
Row Column
Multiplication:
9 equations,
12 unknowns
3 to be assumed
Crouts Method
U11 U 22 U 33 1
L11U11 7 L11 7; L 31U11 2; L 31 2
1
19
; L 31U12 L 32 U 22 3 L 32
7
7
2
1911
L11U13 2 U13 ; L 31U13 L 32 U 23 L 33 U 33 9 L 33
7
238
L 21U11 1 L 21 1;
L11U12 1 U12
L 21U12 L 22 U 22 5 L 22
L 21U13 L 22 U 23 1 U 23
0
0
7
1 1 / 7 2 / 7
0 1 5 / 34
A 1 34 / 7
0
2 19 / 7 1911 / 238 0 0
1
34
7
5
34
36
LU Factorization (contd.)
Row Column multiplication: 9 equations, 12 unknowns 3 to be assumed
2 1 0
U11
A 1 2 1 LU U12
0 1 2
U13
0
U 22
U 23
0 U11
0 0
U 33 0
U12
U 22
0
U13
U 23 L U T
U 33
A 1 / 2
0
0 2
3/ 2
0 0
2 / 3 2 / 3 0
0
37
1/ 2
3/ 2
0
2 / 3
2 / 3
0
LU Decomp (contd.)
Benefit of LU Decomposition:
Solving Ax = b when only b is changing as in Finite difference
technique of ODE-BVP
FOR ONE A AND M bs:
# OF MULTIPLICATIONS/ DIVISIONS =
||
||
=;
Gauss Jordon
39
GJ Example
Example 1.9
R3/-1
(1/2)R3+R2, (-3/2)R3+R1
R2-R1, R3-2R1
R2/2
R2+R1
40
Iterative Techniques
GAUSS JACOBI / GAUSS SIEDEL (G S) / SOR (SUCCESSIVE OVER
RELAXATION)
( k 1)
1
a11
( k 1)
2
b 2 a 21 x
( k 1)
1
a 23 x
(k)
3
a 24 ......... a 1N x
(k)
N
For G-Jacobi, k
a 22
For G-Siedel,
k+1
x N( k 1)
CONVERGENCE CRITERION:
MOST COMMON:
42
GS Example
Example 1.10
43
xi(k)
a/2
xi,GS(k+1) xi,SOR(k+1)
(k )
(k 1)
X
; i 1, 2,...., N ( ALL)
i
i, GS
1)
1)
x(i ,kSOR
x(i k ) w x(i ,kGS
xi(k ) ; i 1, 2,...., N
44
SOR Example
Example 1.11
[1 2 1]
45
GJ
GS
SOR
1 x 2k 1
x1
2
k 1
k 1
2
x
1
3
x 2k
2
x 3k 4 x 2k 1
1 x 2k 1
x1
2
2 x1k x 3k 1
k
x2
2
x 3k 4 x 2k
k 1
1
x
2
x1k,GS
2
k
k 1
2
x
1,GS
3
x 2k,GS
x 3k,GS
4 x 2k,GS
1.5x
1.5x
k
2 ,GS
x 2k 1
k
3,GS
x 3k 1
MATLAB Exercise
Gauss Elimination
function x=gauss(a,b)
% A = [2 1 0; 1 2 1; 0 1 1]; B = [1 2 4]; p = gauss(A,B);
% a - (n x n) matrix; b - column vector of length n
Steps:
% Step 0: get number of rows in matrix a, get length of b & send
message in case they are not same
% Step 1: form (n,n+1) augmented matrix
% Step 2: Start from row 1 and do for all rows that Pivot row
divided by pivot element
% Step 3: For other rows convert all elements below pivot into 0
% Step 4: begin back substitution
Indian Institute of Technology Hyderabad
a(:,n+1)=b;
for i=1:n
a(i, i:n+1)=a(i, i:n+1)/a(i, i);
for j=i+1:n
a(j, i:n+1) = a(j, i:n+1)
- a(j, i)*a(i, i:n+1);
end
end
for j=n-1:-1:1
a(j,n+1) = a(j,n+1)
a(j,j+1:n)*a(j+1:n,n+1);
end
i = 3 a(3,3:4)=a(3, 3:4)/a(3,3);
2 1 0 1
1 2 1 2
0 1 1 4
1 0 . 5 0 0 .5
0 1 . 5 1 1 .5
0 1 1 4
0
0 .5
1 0 .5
0 1 0.67 1
0 0 0.33 3
0
0 .5
1 0 .5
0 1 0.67 1
0 0
1
9
x3 = 9
x2 + 0.67x3 = 1
x1+ 0.5x2 + 0x3 = 0.5
x3 = 9 = a(3,4)
x2 + 0.67 a(3,4) = 1
x2 = 1 - 0.67 a(3,4) = a(2,4)
x1+ 0.5 a(2,4) + 0 a(3,4) = 0.5
x1 = 0.5 - 0.5 a(2,4) - 0 a(3,4) = a(1,4)
0
0 .5
1 0 .5
0 1 0.67 1
0 0
1
9
0
0 .5
1 0 .5
0 1 0.67 5
0 0
1
9
0
3
1 0.5
0 1 0.67 5
0 0
1
9
Indian Institute of Technology Hyderabad
2 1 0 1
1 2 1 2
0 1 1 4
1 0 . 5 0 0 . 5
0 1 .5 1 1 .5
0 1 1 4
0
0 .5
1 0.5
0 1 0.67 1
0 0 0.33 3
0
0 .5
1 0.5
0 1 0.67 1
0 0
1
9
0
3
0
0.5 1 0.5
1 0.5
0 1 0.67 5 0 1 0.67 5
0 0
1
9
1
9 0 0
54