Systems of Linear Equations Systems of Linear Equations
The purpose of computing is insight, not numbers. Richard Wesley Hamming
1
y g Fall 2010
Systems of Linear Equations Systems of Linear Equations The purpose - - PowerPoint PPT Presentation
Systems of Linear Equations Systems of Linear Equations The purpose of computing is insight, not numbers. Richard Wesley Hamming y g 1 Fall 2010 Topics to Be Discussed Topics to Be Discussed This is a long unit and will include the
The purpose of computing is insight, not numbers. Richard Wesley Hamming
1
y g Fall 2010
2
a11x1 + a12x2 + a13x3 + …… + a1nxn = b1 a21x1 + a22x2 + a23x3 + …… + a2nxn = b2 a21x1 a22x2 a23x3 …… a2nxn b2
………………………………………
an1x1 + an2x2 + an3x3 + …… + annxn = bn
3
n1 1 n2 2 n3 3 nn n n
n 11 12 1 1 1
n 21 22 2 2 2
n n nn n n 1 2
4
5
6
×(-3)+
7
x is eliminated from equations 2 and 3
×(-5/3)+
i li i d f i 3
8
y is eliminated from equation 3 Equation 2 only has z!
9
a a a a
i i n 11 1 1 1 1
, +
a a a
i i i i i n 1
, ,
+
×(-ai+1,i/ai,i)+ ×(-an,i/ai,i)+
a a a
i i i i i n 1 1 1 1
, ,
+ + + + 10
a a a
n i n i n n 1
, ,
+
a a a a
i i i i i j i n
+1
i i i i i j i n , , , ,
+1
a a a a
k i k i k j k n , , , ,
+1
DO i = 1, n-1 ! using row i, i.e., a(i,*) DO k = i+1, n ! we want to eliminate a(k,i) zero here DO k i+1, n ! we want to eliminate a(k,i) S = -a(k,i)/a(i,i) ! compute the multiplier DO j = i+1, n ! for each entry on row k a(k,j) = a(k,j) + S*a(i,j) ! update its value ( ,j) ( ,j) ( ,j) p END DO a(k,i) = 0 ! set a(k,i) to 0 b(k) = b(k) + S*b(i) ! don’t forget to update b(k)
11
END DO END DO
a a a a
i i n 11 1 1 1 1
, +
a a a
i i i i i n 1
, , , , +
a a a
i i i n n n 1 1 1
, + + +
n n ,
, , 1 1 , i i i i i i i n n i
+ +
n,n n n, n n n,n
n-1,n n) n-1,n-1
, , 1 1 , i i i i i i i n n i
+ +
⎛ ⎞ 1
x a b a x
i i i i i k k k i n
= − ⎛ ⎝ ⎜ ⎞ ⎠ ⎟
= +
1
1 , ,
DO i = n, 1, -1 ! going backward, row i S = b(i) ! initialize S to b(i) DO k = i+1, n ! sum all terms to the right DO k i+1, n ! sum all terms to the right S = S – a(i,k)*x(k) ! of a(i,i) END DO x(i) = S/a(i,i) ! compute x(i)
13
( ) / ( , ) p ( ) END DO
14
Fixing i, the inner-most j loop executes n-i times, and uses g , j p , n-i multiplications. One more is needed to update bk. Therefore, the total is n-i+1. Since k goes from i+1 to n and the inner-most j loop executes n-i times, there are (n-i)(n-i+1) multiplications.
n−1
Since i goes from 1 to n-1, the total is
DO i = 1, n-1 DO k = i+1, n
( )( ) n i n i
i
− − +
=
1
1
DO k i+1, n S = -a(k,i)/a(i,i) DO j = i+1, n a(k,j) = a(k,j) + S*a(i,j) This j loop uses n-i *’s ( ,j) ( ,j) ( ,j) END DO a(k,j) = 0 b(k) = b(k) + S*b(i) One more * here
15
END DO END DO Thus, one i iteration uses n-i+1 *’s
1 2 1 2 1 + + = +
n
n n ( )
1 2 3 1 6 2 3
2 2 2 2 3 2
+ + + + = + +
n
n n n
n n n
− − −
2 1 3 1 1
3) l
i i i
− = =
2 1 3 1 1
16
( ) ( ) n i n n
n
− = −
−
1
1 1
( ) ( ) n i n n
i
=
=
1
2 1
17
n
(f i)
18
, , ,
i i i j j j i
= ≠
1
(for every i)
,
19
a a a a
i i n 11 1 1 1 1
, +
a a a a a a
i i i i i n i i i i i n 1 1 1 1 1
, ,
+ + + + +
a a a
i i i i i n 1 1 1 1 1
, ,
+ + + +
find the maximum here followed by a swap
20
a a a
n i n i n n 1 , , ,
+
DO i = 1, n-1 ! going through rows i+1 to n Max = i ! assume |a(i,i)| is the max DO k = i+1, n ! find the largest in Max IF (ABS(a(Max,i)) < ABS(a(k,i)) Max = k END DO DO j = i, n ! swap row Max and row i swap a(Max,j) and a(i,j) O END DO swap b(Max) and b(i) ! don’t forget to swap b(i) … do the elimination step … END DO
21
END DO
1 -2 3 1 3 A b 3 -2 1 5 7 A b
3 -2 1 5 7 1 1 5 3 8 0 -1/3 -4/3 7/3 2/3 0 -4/3 8/3 -2/3 2/3 1/3 14/3 4/3 17/3 1 -1 5 3 8 0 -1/3 14/3 4/3 17/3
row swap elimination
3 -2 1 5 7 A b
×(2/3)+ ×(-1/3)+ ×(-1/3)+ elimination
3 -2 1 5 7
1 -2 3 1 3
×(2/3)+ ×( 1/3)+ ×( 1/3)+
22
1 -1 5 3 8
3 -2 1 5 7 1/3 4/3 7/3 2/3 A b 3 -2 1 5 7 4/3 8/3 2/3 2/3 A b 0 -1/3 -4/3 7/3 2/3 0 -4/3 8/3 -2/3 2/3 0 -1/3 14/3 4/3 17/3 0 -4/3 8/3 -2/3 2/3 0 0
4 3/2 11/2 0 -1/3 14/3 4/3 17/3 0 0 4 3/2 11/2
row swap elimination
3 -2 1 5 7 A b
row swap elimination
3 -2 1 5 7 0 -4/3 8/3 -2/3 2/3 0 -1/3 -4/3 7/3 2/3
×(-1/4)+ ×(-1/4)+
23
0 -1/3 14/3 4/3 17/3
3 -2 1 5 7 A b 3 -2 1 5 7 A b 0 -4/3 8/3 -2/3 2/3 0 0
0 -4/3 8/3 -2/3 2/3 0 0 4 3/2 11/2 0 0 4 3/2 11/2 0 0 0 13/4 13/4
elimination x1 = x2 = x3 = x4 = 1
3 2 1 5 7 A b
row swap elimination
3 -2 1 5 7 0 -4/3 8/3 -2/3 2/3 4 3/2 11/2 ×(1/2)+
24
0 0 4 3/2 11/2 0 0
( )
, , ,
25
a a a a
i i n 11 1 1 1 1
, +
a a a a a a
i i i i i n 1 1 1 1 1
, ,
+
row i
a a a a a a
i i i i i n 1 1 1 1
, ,
+ + + +
row p
26
a a a
n i n i n n 1
, ,
+
column i column q
27
28
29
×(-1/0.0003)+
elimination
exact arithmetic yields x = 1/3 and y = 2/3
30
Possible cancellation here, as 3×(6666/9999)≈2.0001!
Precision y x 4 0 6667 4 0.6667 0 5 0.66667 0.3 6 0.666667 0.33
inaccurate
31
7 0.6666667 0.333
inaccurate
elimination
1.0000x + 1.0000y = 1.0000 0 0003x + 3 0000y = 2 0001 1.0000x + 1.0000y = 1.0000 2 9997y = 1 9998 0.0003x + 3.0000y = 2.0001 2.9997y = 1.9998
Backward substitution
Backward substitution
Precision y x 4 0 6667=2/3 0 3333 4 0.6667=2/3 0.3333 5 0.66667 0.33333 6 0.666667 0.333333
32
7 0.6666667 0.3333333
i,i
33
34
lower triangular upper triangular
1,1 1,2 1, 1,1 1,2 1, 2 1 2 2 2 2 1 2 2 2
1 1
n n n n
a a a u u u a a a l u u ⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥
upper triangular
2,1 2,2 2, 2,1 2,2 2, 1 2 1 2
1
n n n n n n n n n n
a a a l l u ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ =
⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦
,1 ,2 , ,1 ,2 , n n n n n n n n
⎣ ⎦ ⎣ ⎦ ⎣ ⎦
36
u u u u x y
i n 1 1 1 2 1 1 1 1 , , , ,
⎢ ⎤ ⎥ ⎡ ⎢ ⎤ ⎥ ⎡ ⎢ ⎤ ⎥ u u u x y
i n 2 2 2 2 2 2 , , ,
⎢ ⎢ ⎢ ⎥ ⎥ ⎥ ⎥ ⎢ ⎢ ⎢ ⎢ ⎥ ⎥ ⎥ ⎥ ⎢ ⎢ ⎢ ⎢ ⎥ ⎥ ⎥ ⎥ u u x y
i i i n i i , ,
⎢ ⎢ ⎢ ⎥ ⎥ ⎥ ⎥ ⋅ ⎢ ⎢ ⎢ ⎢ ⎥ ⎥ ⎥ ⎥ = ⎢ ⎢ ⎢ ⎢ ⎥ ⎥ ⎥ ⎥
37
u x y
n n n n ,
⎢ ⎢ ⎦ ⎥ ⎥ ⎣ ⎢ ⎦ ⎥ ⎣ ⎢ ⎦ ⎥
2
,1 1 ,2 2 , 1 1 i i i i i i i
− −
1 ,1 1 ,2 2 , 1 1 , 1 i i i i i i i i i i k k k
y b l y l y l y b l y
− − − =
= − + + + = −∑
1
2 1 1 2 1 2
y y b b
,
⎡ ⎢ ⎢ ⎢ ⎤ ⎥ ⎥ ⎥ ⎡ ⎢ ⎢ ⎢ ⎤ ⎥ ⎥ ⎥ ⎡ ⎢ ⎢ ⎢ ⎤ ⎥ ⎥ ⎥
row i
1
1 2
l y b
i i i i , ,
⎢ ⎢ ⎢ ⎢ ⎥ ⎥ ⎥ ⎥ ⋅ ⎢ ⎢ ⎢ ⎢ ⎥ ⎥ ⎥ ⎥ = ⎢ ⎢ ⎢ ⎢ ⎥ ⎥ ⎥ ⎥
38
1
1 2
l l y b
n n n i n n , , ,
⎣ ⎢ ⎢ ⎢ ⎦ ⎥ ⎥ ⎥ ⎣ ⎢ ⎢ ⎦ ⎥ ⎥ ⎣ ⎢ ⎢ ⎦ ⎥ ⎥
1 1 1 2 2 1 1 i i i i i i i i i i k k
y b l y l y l y b l y
−
= − + + + = −∑
,1 1 ,2 2 , 1 1 , 1 i i i i i i i i i k k k
y b l y l y l y b l y
− − =
+ + +
y1 = b1 y1 b1 DO i = 2, n yi = bi DO k = 1, i-1 yi = yi – Li,k*yk END DO This is an O(n2) method Do it yourself.
39
END DO END DO
40
41
3 2
42
elimination is still needed
43
2,1
1 1 a ⎡ ⎤ ⎢ ⎥ ⎢ ⎥
, 1,1 3,1 3,2
1 1 a a a ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ column i
1,1 2,2 1 2
1
i i
a a a a ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥
,1 ,2 1,1 2,2 1,1 1,2 1,
1 1
i i i i i i
a a L a a a
+ + +
⎢ ⎥ ⎢ ⎥ ⎢ ⎥ = ⎢ ⎥ ⎢ ⎥
1,1 2,2 , 1 2 i i k k k i
a a a a a a ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥
,1 ,2 , 1,1 2,2 ,
1
k k k i i i
a a a a a a ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥
44
, ,1 ,2 , 1,1 2,2 , ,
1
n j n n n i i i j j
a a a a a a a a ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎣ ⎦
DO i = 1, n-1 ! using row i, i.e., a(i,i) DO k = i+1, n ! we want to eliminate a(k,i) S = a(k,i)/a(i,i) DO j = i+1, n ! for each entry on row k (k j) (k j) * (i j) d i l a(k,j) = a(k,j) - S*a(i,j) ! update its value END DO a(k,i) = S ! save this “multiplier” END DO ! don’t forget to pdate b(k)
45
END DO ! don’t forget to update b(k) END DO
1,1 1,2 1,3 1, 1, i n
2,1 2,2 2,3 2, 2, 3 1 3 2 3 3 3 3 i n i n
3,2 3,3 3, 3, i n
,2 ,3 , , i i i i i i n
,1 ,2 ,3 , , n n n n i n n
4 0 1 1 3 1 3 1
×(-3/4)+ ×(-0/4)+ ×(-3/4)+
0 1 2 0 3 2 4 1 4 0 1 1 ¾ 1 9/4 ¼ 1 2 0 ¾ 2 13/4 1/4
column 1
47
¾ 2 13/4 1/4
×(-1/1)+ ×(-2/1)+
4 0 1 1 ¾ 1 9/4 ¼ 1 2 0 ¾ 2 13/4 1/4 4 1 1
column 2
4 0 1 1 ¾ 1 9/4 ¼ 1
48
1 ¼ ¼ ¾ 2
4 0 1 1 ¾ 1 9/4 ¼
×(-5)+
1
¾ 2
4 1 1
column 3
4 0 1 1 ¾ 1 9/4 ¼ 1
49
1 ¼ ¼ ¾ 2 5 1
50
1,1 1,2 1,3 1, 1, 2 1 2 2 2 3 2 2 i n i n
u u u u u l u u u u ⎡ ⎤ ⎢ ⎥ ⎢ ⎥
DO i = 2, n
2,1 2,2 2,3 2, 2, 3,1 3,2 3,3 3, 3, i n i n
l l u u u A ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ = ⎢ ⎥
yi = bi DO k = 1, i-1
,1 ,2 ,3 , , i i i i i i n
l l l u u ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥
END DO END DO
,1 ,2 ,3 , , n n n n i n n
l l l l u ⎢ ⎥ ⎣ ⎦
51
ai,k is actually li,k
1,1 1,2 1,3 1, 1, 2 1 2 2 2 3 2 2 i n
u u u u u l u u u u ⎡ ⎤ ⎢ ⎥ ⎢ ⎥
S = y
2,1 2,2 2,3 2, 2, 3,1 3,2 3,3 3, 3, i n i n
l u u u u l l u u u A ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ = ⎢ ⎥
DO k = i+1,n S = S - ai k*xk
,1 ,2 ,3 , , i i i i i i n
l l l u u ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥
k
END DO xi = S/ai,i
,1 ,2 ,3 , , n n n n i n n
l l l l u ⎢ ⎥ ⎢ ⎥ ⎣ ⎦
52
ai,k here is ui,k!
2 1
1 a ⎡ ⎤ ⎢ ⎥ ⎢ ⎥
1,1 ,1 1,1 i i
a a a a ⎛ ⎞ − × + ⎜ ⎟ ⎜ ⎟ ⎝ ⎠
2,1 1,1 1,1 1,2 1,3 1, 1, 3,1 2,1 2,2 2,3 2, 2,
1 1
i n i n
a a a a a a a a a a a a a ⎢ ⎥ − ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ − ⎢ ⎥
1,2 1,3 1, 1, 2,2 2,3 2, 2, i n i n
a a a a a a a a a ⎡ ⎤ ⎡ ⎤ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥
3,1 3,2 3,3 3, 3, ,1 ,2 ,3 , ,1
1
i n i i i i i i
a a a a a a a a a a a a ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ − ⎢ ⎥
3,3 3, 3, , ,2 ,3 , , i n i n i i i i i n
a a a a a a a a ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ = ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥
1
1 1
n
a a ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥
,2 ,3 , , ,2 ,3 , , n n n n i n n n n n i n n
a a a a a a a a a ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎣ ⎦ ⎣ ⎦
53
,1 1,1
1
n
a ⎢ ⎥ − ⎢ ⎥ ⎣ ⎦
row i
2 1 11
1,1 3,1 1,1
t i l !
1 ,1 1,1
i
1 /
n n n
,1 , n n n
2,2
t i l !
2 ,2 2,2
i
55
2 2 2
2,2
n
1 ⎡ ⎤ ⎢ ⎥ ⎢ ⎥
1
i i
a + ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ − ⎢ ⎥
2,
1
i i i i i
a E a + ⎢ ⎥ ⎢ ⎥ = ⎢ ⎥ − ⎢ ⎥
i i
a ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥
, ,
1
n i i i
a a ⎢ ⎥ − ⎢ ⎥ ⎣ ⎦
1,1 1, 1, 1 1, 2 1,
1 1
i i i n
a a a a a
+ +
⎡ ⎤ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥
1, 1, 1 1, 2 1, i i i n
a a a a a a
+ +
⎡ ⎤ ⎢ ⎥ ⎢ ⎥
⎤ ⎢ ⎥ ⎢ ⎥
1, , , 1 , 2 , , 1, 1, 1 1, 2 1, 2, 2 2
1
i i i i i i i i i n i i i i i i i i i n i i i i i i
a a a a a a a a a a a a a
+ + + + + + + + + + + + +
⎢ ⎥ ⎢ ⎥ − ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ − ⎢ ⎥
, , 1 , 2 , 1, 1 1, 2 1, 1 2 2 2 2 1 2 2 2 n i i i i i i i n i i i i i n i i i n i i i i i n
a a a a a a a a a a a a a
+ + + + + + + + + + + + + + +
⎢ ⎥ ⎢ ⎥ ⎢ ⎥ = ⎢ ⎥ ⎢ ⎥ ⎢ ⎥
⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥
2, 2, , ,
1
i i i i i i n i
a a a
+ + +
⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ − ⎢ ⎥ ⎣ ⎦
2, 2 2, 2, 1 2, 2 2, , , 1 , 2 , , 1 , 2 , i i i n i i i i i n n i n i n i n n n i n i n n
a a a a a a a
+ + + + + + + + + + + +
⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎣ ⎦
⎥ ⎢ ⎥ ⎢ ⎥ ⎣ ⎦
E ⋅E ⋅ ⋅E ⋅E ⋅A E ⋅E ⋅E ⋅ ⋅E ⋅E ⋅A
57
, i i
a ⎢ ⎥ ⎣ ⎦
Ei Ei-1⋅Ei-2⋅…⋅E2⋅E1⋅A Ei⋅Ei-1⋅Ei-2⋅…⋅E2⋅E1⋅A
1 2 n 1
2⋅…⋅E2⋅E1)-1⋅U, where T-1 means the inverse
58
1 1 ⎡ ⎤ ⎡ ⎤ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥
column i
1 1
1 1 1 1
i i
m m I
+ +
⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ − ⎢ ⎥ ⎢ ⎥ ⋅ = ⎢ ⎥ ⎢ ⎥
1 1
n k k
I m m ⋅ = ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ − ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥
59
1 1
n n
m m ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ − ⎢ ⎥ ⎢ ⎥ ⎣ ⎦ ⎣ ⎦
1
1 1 1 1
−
⎡ ⎤ ⎡ ⎤ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥
1,
1 1 1 1
i i i i i i i i
a a a a
+ +
⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ − ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥
, , , ,
1 1
i i i i k i k i
a a ⎢ ⎥ ⎢ ⎥ = ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥
,
1 1
i i i i
a a ⎢ ⎥ ⎢ ⎥ − ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥
, , , ,
1 1
n i n i i i i i
a a a a ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ − ⎢ ⎥ ⎢ ⎥ ⎣ ⎦ ⎣ ⎦
1 1
n n n n n n
− −
61
E1
2 1
1 a ⎡ ⎤ ⎢ ⎥ ⎢ ⎥ 1 2 n-2 n-1
2,1 1,1 3,1 3,2
1 1 a a a a ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥
1,1 2,2 ,1 ,2
1
i i
a a a a ⎢ ⎥ ⎢ ⎥ ⎢ ⎢ ⎢ ⎢
⎥ ⎥ ⎥
1,1 2,2 1 1 1 1 2 1 1,1 1,2 1, 11 2 2
1 1
n i i i i i i
a a E E E a a a a a a
− − − − + + +
⎢ ⎢ ⎢ = ⎢ ⎢ ⎢ i ii ⎥ ⎥ ⎥ ⎥ ⎥ ⎥
Verify this yourself!
1,1 2,2 , ,1 ,2 ,
1
i i k k k i
a a a a a a ⎢ ⎢ ⎢ ⎢ ⎢
⎥ ⎥ ⎥ ⎥
y y
1,1 2,2 , , ,1 ,2 ,
1
i i n j n n n i
a a a a a a a ⎢ ⎢ ⎢ ⎢ ⎢
⎥ ⎥ ⎥ ⎥
Note that the ai,j’s are not the
62
1,1 2,2 , ,
1
i i j j
a a a a ⎢ ⎢ ⎣ ⎦
⎥
computed intermediate results in the elimination process
63
64
index array
4 0 1 1 3 1 3 1 0 2 2 0
×(-3/4)+ ×(-0/4)+ ×(-3/4)+
1 2 3
array
0 2 2 0 3 3 4 1 3 4 4 0 1 1 ¾ 1 9/4 ¼ 2 2 0 ¾ 3 13/4 ¼
column 1
65
¾ 3 13/4 ¼
index array index ×(-2/3)+ ×(-1/3)+
4 0 1 1 ¾ 1 9/4 ¼ 1 2
array
4 0 1 1 ¾ 3 13/4 ¼ 1 4
array
2 2 0 ¾ 3 13/4 ¼ 3 4 2 2 0 ¾ 1 9/4 ¼ 3 2
column 2
4 1 1 1
index array
4 0 1 1 ¾ 3 13/4 ¼ 2/3 -1/6
1 4 3
66
2/3 1/6 1/6 ¾ 1/3 7/6 1/6 3 2
index index
4 0 1 1 ¾ 3 13/4 ¼ 1 4
array
4 0 1 1 ¾ 3 13/4 ¼ 1 4
array ×(1/7)+
2/3 -1/6 -1/6 ¾ 1/3 7/6 1/6 3 2 ¾ 1/3 7/6 1/6 2/3 -1/6 -1/6 2 3 4 1 1 1
index array column 3
4 0 1 1 ¾ 3 13/4 ¼ ¾ 1/3 7/6 1/6 1 4 2
67
¾ 1/3 7/6 1/6 0 2/3 -1/7 -3/21 2 3
index array
68
69
70
71
i i i i i i n n i , , , , 1 1 2 2
x b a x a x a x a x b a x
i i i i i i i i i i i i k k n
= − + + + + + = − ⎡ ⎢ ⎤ ⎥
1 1
1 1 1 1 1 1
x a b a x a x a x a x a b a x
i i i i i i i i i i i i n n i i i i k k k k i
+ + + + + ⎣ ⎢ ⎦ ⎥
− − + + = ≠
1 1 1 1 1 1 1 , , , , , , , ,
Start with an initial guess x0 = [x1, x2, …, xn] Plug this xi into the above equations to compute xi+1 Plug this xi into the above equations to compute xi+1 Repeat this process until A•xk ≈ b for some k.
72
2x + 6y - 3z = 2 x = -(1 + y - 2z)/5 y = (2 - 2x + 3z)/6
transformation
2x + y + 7z = 32 z = (32 - 2x - y)/7
1
1 1 1 2 32 + × ⎛ ⎜ ⎞ ⎡ ⎢ ⎤ ⎥ x2 5 1 3 2 7 1 6 2 2 1 5 3 32 7 15619 2 6857 4 5810 = − + − × ⎛ ⎝ ⎜ ⎞ ⎠ − × − + × ⎛ ⎝ ⎜ ⎞ ⎠ ⎟ ⎢ ⎢ ⎢ ⎢ ⎢ ⎥ ⎥ ⎥ ⎥ ⎥ = − ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ . .
Converge in approx. 10 iterations with x≈0.998, y≈1.997, z≈3.991
73
1 7 32 2 1 5 1 3 4 5810 − × − − ⎛ ⎝ ⎜ ⎞ ⎠ ⎟ ⎣ ⎢ ⎢ ⎢ ⎦ ⎥ ⎥ ⎥ ⎣ ⎢ ⎦ ⎥ .
, y ,
a a a n ⎡ ⎢ ⎤ ⎥
1 2 1 3 1
! Given system is A•x = b
a a a a a a a a a
n n
− − − − − − ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎤ ⎥ ⎥ ⎥ ⎥ ⎥
1 2 1 1 1 3 1 1 1 1 1 2 1 2 2 2 3 2 2 2 2 2 , , , , , , , , ,
! working arrays
C a a a a a a
n
= − − − ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥
2 2 2 2 2 2 3 1 3 3 3 2 3 3 3 3 3 , , , , , , , , ,
DO j = 1, n C(i,j) = -A(i,j)/A(i,i)
a a a a a a
n n n n n n n n n
− − − ⎣ ⎢ ⎢ ⎦ ⎥ ⎥
1 2 3 , , , , , ,
⎡ ⎤
C(i,j) A(i,j)/A(i,i) END DO C(i,i) = 0 d(i) = b(i)/A(i i)
b a b a ⎡ ⎢ ⎢ ⎢ ⎢ ⎤ ⎥ ⎥ ⎥ ⎥
1 1 1 2 ,
d(i) = b(i)/A(i,i) END DO
d a b a = ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥
2 2 3 3 3 , ,
74
b a
n n n
⎣ ⎢ ⎢ ⎢ ⎢ ⎦ ⎥ ⎥ ⎥ ⎥
,
before starting iteration!
DO x new = C*x + d x_new = C*x + d IF (ABS(A*x_new - b) < Tol) EXIT x = x_new END DO END DO
ABS(A* b) < T l th b l t l ABS(A*x_new-b) < Tol means the absolute value
You may just use the equations for computation instead of the above matrix form.
75
1
76
2x + 6y - 3z = 2 2 7 32 x = -(1 + y - 2z)/5 y = (2 - 2x + 3z)/6
transformation
2x + y + 7z = 32 z = (32 - 2x - y)/7
77
2x + 6y - 3z = 2 2 7 32 x = -(1 + y - 2z)/5 y = (2 - 2x + 3z)/6
transformation
2x + y + 7z = 32 z = (32 - 2x - y)/7
78
DO DO DO i = 1, n ! Update xi EQN_i = 0 DO j = 1, n EQN_i = EQN_i + C(i,j)*x(j) END DO x(i) = EQN_i + d(i) END DO IF (ABS(A*x – b) < Tol) EXIT
79
( ( ) ) END DO
n
(for every i)
, , ,
i i i j j j i
= ≠
1
(for every i)
80
#1 #1
x x2 x1
#2
x0
81
3x+y=3 x+2y=2 x=1-y/3 y=1-x/2
#1
X0
X2
#2
X3
82
#2
X1
#1 #1
x1
#2
x0 x2
83
#2
3x+y=3 x+2y=2 x=1-y/3 y=1-x/2
#1
X0
X1
#2
X1 X2
84
#2
85
Make copies of A to A’ and A” and b to b’ U ” t t ” L*U ! ” i d t d Use A” to compute A” = L*U ! A” is destroyed Apply an elimination method to solve A’*x=b’ Let the solution be x DO r = b – A * x ! compute residual IF (ABS(r) < Tol) EXIT Solve for ∆ from (L*U)*∆ = r ! compute correction x = x + ∆ ! update x END DO
86
END DO
⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤ 2 5 b ⎡ ⎤ = ⎢ ⎥ ⎣ ⎦
A = ⎡ ⎣ ⎢ ⎤ ⎦ ⎥ = ⎡ ⎣ ⎢ ⎤ ⎦ ⎥ ⋅ ⎡ ⎣ ⎢ ⎤ ⎦ ⎥ 1 1 2 3 1 2 1 1 1 1
87
1 2
88
1
2
new
89
90
1,1 1, 1, 1, i n i
, , ,
i i i i n i i
91
,1 ,1 , , n n n n n i
1,1 1, 1, 1, i n i
, , ,
i i i i n i i
92
,1 ,1 , , n n n n n i
93
⎡ ⎢ ⎤ ⎥ ⎡ ⎢ ⎢ ⎤ ⎥ ⎥ 1 3 4 1 9 A L U = ⋅ = ⎣ ⎢ ⎢ ⎢ ⎦ ⎥ ⎥ ⎥ ⋅ − ⎢ ⎢ ⎢ ⎢ ⎥ ⎥ ⎥ ⎥ 3 4 1 1 1 1 9 4 1
94
⎣ ⎦ ⎣ ⎢ ⎢ ⎦ ⎥ ⎥ 1 1 1 4
⎡ ⎤ 1 3 1 4 1 1 9 1 ⎡ ⎢ ⎢ ⎤ ⎥ ⎥ ⋅ ⎡ ⎢ ⎢ ⎢ ⎤ ⎥ ⎥ ⎥ ⋅ = ⎡ ⎢ ⎢ ⎤ ⎥ ⎥ X 4 1 1 1 1 4 1 4
1
⎣ ⎢ ⎢ ⎦ ⎥ ⎥ ⋅ − ⎣ ⎢ ⎢ ⎢ ⎢ ⎦ ⎥ ⎥ ⎥ ⎥ ⋅ = ⎣ ⎢ ⎢ ⎦ ⎥ ⎥ X
4 ⎣ ⎢ ⎦ ⎥
1
95
⎡ ⎤ 1 3 1 4 1 1 9 1 ⎡ ⎢ ⎢ ⎤ ⎥ ⎥ ⋅ ⎡ ⎢ ⎢ ⎢ ⎤ ⎥ ⎥ ⎥ ⋅ = ⎡ ⎢ ⎢ ⎤ ⎥ ⎥ X 4 1 1 1 1 4 1 1
2
⎣ ⎢ ⎢ ⎦ ⎥ ⎥ ⋅ − ⎣ ⎢ ⎢ ⎢ ⎢ ⎦ ⎥ ⎥ ⎥ ⎥ ⋅ = ⎣ ⎢ ⎢ ⎦ ⎥ ⎥ X
⎣ ⎢ ⎦ ⎥
2
96
⎡ ⎤ 1 3 1 4 1 1 9 ⎡ ⎢ ⎢ ⎤ ⎥ ⎥ ⋅ ⎡ ⎢ ⎢ ⎢ ⎤ ⎥ ⎥ ⎥ ⋅ = ⎡ ⎢ ⎢ ⎤ ⎥ ⎥ X 4 1 1 1 1 4 1 1
3
⎣ ⎢ ⎢ ⎦ ⎥ ⎥ ⋅ − ⎣ ⎢ ⎢ ⎢ ⎢ ⎦ ⎥ ⎥ ⎥ ⎥ ⋅ = ⎣ ⎢ ⎢ ⎦ ⎥ ⎥ X
⎣ ⎢ ⎦ ⎥
3
97
1
1
−1
98
99
row swap column swap
product is 74
×( 1/2)+
row swap ×(-1/2)+
100
(-1)374=-74
3 swaps means (-1)3
101
102