Vous êtes sur la page 1sur 79

NUMERICAL METHODS

Lecture 6.
Set of linear equations

prof. dr hab. in. Katarzyna Zakrzewska


Numerical Methods - Lecture 6

OUTLINE

Exact methods
Nave Gaussian Elimination
Gauss-Siedel Method
LU Decomposition

Numerical Methods - Lecture 6

System of linear equations

Consider the system of linear equations m


with n unknowns in the form of

a11 x1 a12 x2 a1n x n b1


a 21 x1 a 22 x 2 a 2 n xn b2


a m1 x1 a m 2 x2 a mn xn bm

with coefficients aik and bi that belong to K ( K


= R lub K = C)
Numerical Methods - Lecture 6

System of linear equations

The system of linear equations:


where:

Ax b

A matrix with m rows and n columns


x vector with n unknowns
b vector of m known numbers

possible solutions:

Infinitely many solutions


Exactly one solution
No solution (inconsistent system)
Numerical Methods - Lecture 6

Kronecker-Capelli theorem

Matrix system of equations is called the


coefficient matrix A with variable

a11 a1n
A

a m1 a mn

a11 a1n b1
C

a m1 a mn bm

Expanded matrix is called the matrix C, also


referred to as A / B, formed from the matrix A by
adding to it a column of free terms
Numerical Methods - Lecture 6

Kronecker-Capelli theorem

Kronecker-Capelli theorem
System of m linear equations with n unknowns has
a solution if the rank r of the main matrix equals to
the rank of the expanded matrix :

rank A = rank C = r

For any matrix, the rank is equal to r if and only if there


exists a nonzero minor of rank k of this matrix, and
every minor of rank larger than k is zero.
Numerical Methods - Lecture 6

Kronecker-Capelli theorem

Kronecker-Capelli theorem
If the rank r of both matrices is equal to the number
of unknowns, there is one solution of the system of
equations , i.e., one set of numbers satisfying the
equation can be found; a system is consistent

rank A = rank C = n

Numerical Methods - Lecture 6

Kronecker-Capelli theorem

Kronecker-Capelli theorem
If common order r the both matrix is smaller than
the number of unknowns n, then (n - r) unknowns
can be chosen arbitrarily, and the remaining r
unknowns determined from the equation, then the
system has no unique solution, it depends on (n - r)
parameters

rank A =rank C < n

Numerical Methods - Lecture 6

Kronecker-Capelli theorem

Kronecker-Capelli theorem
if the rank r of the main matrix is smaller than the
rank of an extended matrix, the system of linear
equations has no solution; the system is
inconsistent

rank A rank C

Numerical Methods - Lecture 6

The concept of norms

In the space Rn, whose elements are the vectors: x x1 , x2, ..., xn

x 1 x1 x2 ... xn

x 2 x x ... x

2
1

2
2

2 1/ 2
n

max x1 , x2 , ..., xn

For any vector x Rn, inequalities are valid:

x 2 x1 n x 2 nx

Numerical Methods - Lecture 6

10

Methods of solving sets of linear


algebraic equations
Exact methods - definition
If the solution of equations Ax=b is obtained by the
transformation of A and B, assuming exactly
performed arithmetic operations, after a finite
number of actions we get a solution.

Numerical Methods - Lecture 6

11

Exact methods
Exact methods - features
A small number of calculations needed to determine the
solution
If the task is ill-conditioned numerically, the solution can
be subject to a significant error.
They can be unstable due to rounding off errors
The transformation matrix A uses to a large extent the
machine's memory, especially if the original data A and b
should be kept to a final verification

Numerical Methods - Lecture 6

12

Exact methods - example

Example Cramer's formulas

a11 x1 a12 x2 b1

a21 x1 a22 x2 b2

a22b1 a12b2
x1
a11a22 a21a12

Method 1:

a11b2 a21b1
x2
a11a22 a21a12

We assume accurate to two decimal digits each result before


further calculation is rounded

0,99 x1 0,70 x2 0,54


0,70 x1 0,50 x2 0,38

a11a22 0,99 0,50 0,4950 0,50

a21a12 0,70 0,70 0,4900 0,49

a11a22 a21a12 0,50 0,49 0,01


Numerical Methods - Lecture 6

13

Exact methods - example

a22b1 a12b2 0,50 0,54 0,70 0,38

0,2700 0,2660 0,27 0,27 0

a11b2 a21b1 0,99 0,38 0,70 0,54

0,3762 0,3780 0,38 0,38 0


0
0
0,01
0
x2
0
0,01
x1

The exact solution to this system of equations gives the result:

x1 0,80

Numerical Methods - Lecture 6

x2 0,36

14

Exact methods - example

Method 2: Gaussian elimination method 0,99 x1 0,70 x2 0,54

0,70 x1 0,50 x2 0,38

We eliminate the unknown x1 from the second equation of the


system of equations. For this purpose multiplying the first
equation by:
a
0,70
21

We receive:

a11

0,99

0,7070 0,71

0,70 x1 0,4949 x2 0,3818


0,70 x1 0,50 x2 0,38

By subtracting the equations, after having rounded to two digits:

0,00 x2 0,00

The system has infinitely many solutions.


Numerical Methods - Lecture 6

15

Systems of equations with triangular matrix


Triangular matrix definition
Triangular matrix is called lower (upper) triangular matrix,
where all the elements of above (under) diagonal are equal
to zero.

lower triangular matrix


Numerical Methods - Lecture 6

upper triangular matrix


16

Systems of equations with triangular matrix

Calculating the determinant of a triangular matrix comes


down to the multiplication of elements lying on the main
diagonal:

det( L) li ,i l1,1 l2, 2 ...ln ,n


n

i 1

det(U ) ui ,i u1,1 u2, 2 ...un ,n


n

i 1

Numerical Methods - Lecture 6

17

Systems of equations with triangular matrix

If the matrix A system of n equations with n unknowns Ax=b


is a triangular matrix (upper or lower), then the solution x of
this system of equations can be obtained by performing a
small number of arithmetic operations and for small rounding
errors

a11 x1 a12 x2 ... a1,n 1 xn 1 a1n xn b1

a22 x2 ... a2,n 1 xn1 a2 n xn b2

.....................................................
Generally

xi

an 1,n 1 xn1 an1,n xn bn 1

bi ain xn ... aii 1 xi 1


aii

Numerical Methods - Lecture 6

ann xn bn

bn
xn
ann

i n 1, n 2, ..., 1

18

Systems of equations with triangular matrix


Calculation cost:

To determine the vector x should be performed M


multiplications and divisions and D additions:

1 2 1
M n n
2
2
1 2 1
D n n
2
2

Numerical Methods - Lecture 6

19

Gaussian Elimination
The first phase (the phase of the elimination of the
"forward coefficient)

a11 x1 a12 x2 a13 x3 ... a1n xn b1


a21 x1 a22 x2 a23 x3 ... a2 n xn b2

.....................
an1 x1 an 2 x2 an 3 x3 ... ann xn bn
n-1 steps of elimination are required

Numerical Methods - Lecture 6

20

Gaussian Elimination
Step 1. From the second row subtracting the first one, divided by
a11 and multiplied by a21

a11 x1 a12 x2 a13 x3 ... a1n xn b1

a21
a11

a21
a21
a21
a21 x1
a12 x2 ...
a1n xn
b1
a11
a11
a11

a21 x1 a22 x2 a23 x3 ... a2 n xn b2


We receive:

a21
a21
a21
a22
a12 x2 ... a2 n
a1n xn b2
b1
a11
a11
a11

Numerical Methods - Lecture 6

21

Gaussian Elimination

Similarly, acting with the rest of rows:

a11 x1 a12 x2 a13 x3 ... a1n xn b1

'
'
a22
x2 a23
x3 ... a2' n xn b2'

'
'
a32
x2 a33
x3 ... a3' n xn b3'

.....................

'
an' 2 x2 an' 3 x3 ... ann
xn bn'

'
where: a22
a22

.
.
.

a2' n a2 n
Numerical Methods - Lecture 6

a21
a12
a11
a21
a1n
a11

22

Gaussian Elimination
Step 2. We repeat the procedure step 1 for the third
row
a '32
'
'
'
'

a22 x2 a23 x3 ... a2 n xn b2

'
a32
x2

'
a23

a'22

'
'
'
a32
a32
' a32
'
x

...

a
x

b
3
2n '
n
2
'
'
a22
a22
a22

'
'
a32
x2 a33
x3 ... a3' n xn b3'

We receive :

'

a '32
a '32
a '32
a33
a '23 x3 ... a '3n
a '2 n xn b'3
b '2
a '22
a '22
a '22

Numerical Methods - Lecture 6

23

Gaussian Elimination

After second step we receive

'
'
a22
x2 a23
x3 ... a2' n xn b2'

"
a33
x3 ... a3" n xn b3"

.....................

a x ... a x b
"
n3 3

Numerical Methods - Lecture 6

"
nn n

"
n

24

Gaussian Elimination
At the end of step n-1 the system of equations takes
the form:

a11 x1 a12 x 2 a13 x3 ... a1n x n b1


'
'
a22
x2 a23
x3 ... a2' n xn b2'

"
a33
x3 ... a3" n xn b3"
.....................

n 1

ann xn bn
n 1

Numerical Methods - Lecture 6

25

Gaussian Elimination
After the n-1 step elimination of variables resulting
equations can be written in matrix form:

a11 a12
0 a'
22

0
0

0
0

a1n x1 b1
a'2 n x2 b2'

"
"
a3n x3 b3


(n 1 )
xn bn(n-1 )
0 ann

a13

a'23
a"33

The resulting matrix is a triangular matrix!


Numerical Methods - Lecture 6

26

Gaussian Elimination

The second phase called back substitution

Start with the last equation because it has only one unknown

bn( n 1)
x n ( n 1)
a nn

xi

bii 1 ai,ii11 xi 1 ai,ii12 xi 2 ... ai,in1 xn

xi
Numerical Methods - Lecture 6

aii

i 1

bi

i 1

aiji 1 x j
n

j i 1
i 1
ii

for i n 1,...,1

for i n 1,...,1
27

Gaussian Elimination
Gaussian Elimination computational cost

The total number multiplications and of divisions:

1 3
1
2
M n n n
3
3

The total number of additions:


1
1
5
D n3 n2 n
3
2
6
Numerical Methods - Lecture 6

28

Example:

Gaussian Elimination - example


Time t
(s)
5

Velocity
(m/s)

12

106.8
177.2

279.2

The velocity data is approximated by a polynomial as:

vt a1t 2 a 2 t a3 ,

Find the velocity at t=6 seconds .

Numerical Methods - Lecture 6

5 t 12.

29

Gaussian Elimination - example

v t a 1 t 2 a 2 t a 3 , 5 t 12.

t 12
2
t2
t 32

t1

t2
t3

t1 5 s , v ( 5 ) 106 , 8 m / s
t 2 8 s , v ( 5 ) 177 , 2 m / s
t 3 12 s , v ( 5 ) 279 , 2 m / s

25
64

144

Numerical Methods - Lecture 6

5
8

12

1
1

a1
v1
a v
2
2
a 3
v 3

1
1
1

a 1 106 . 8
a 177 . 2
2

a 3 279 . 2

30

Gaussian Elimination - example


25 5 1 106.8
64 8 1 177.2

144 12 1 279.2

25

Divide equation 1 by
25 and multiply by 64

64
2.56
25

5 1 106.8 2.56 64 12.8 2.56 273.408

Subtract the result of


equation 2

We receive :
Numerical Methods - Lecture 6

64
64
0

12.8

2.56

4.8 1.56

177.2

273.408

96.208

5
1
106.8
25
0 4.8 1.56 96.208

144 12
1
279.2

31

Gaussian Elimination - example


5
1
106.8 Divide equation 1 by
25
0 4.8 1.56 96.208

25 and multiply by 144


144 12
1
279.2

25

5 1 106.8 5.76 144


.

Subtract the result of


equation 3

After the first step of


elimination
Numerical Methods - Lecture 6

144
144
0

144
5.76
25

28.8 5.76 615.168


12
28.8

1
5.76

16.8 4.76

279.2
615.168

335.968

5
1

106.8
25
0 4.8 1.56 96.208

0 16.8 4.76 335.968

32

Gaussian Elimination - example


5
1

106.8
25
0 4.8 1.56 96.208

0 16.8 4.76 335.968

Divide equation 2
by -4.8 and multiply
by -16.8

16.8
3 .5
4 .8

4.8 1.56 96.208 3.5 0 16.8 5.46 336.728

Subtract the result of


equation 3
After the second step of
elimination
Numerical Methods - Lecture 6

0
0
0

16.8 4.76

335.968

16.8 5.46 336.728


0

0.7

0.76

5
1
106.8
25
0 4.8 1.56 96.208

0
0
0.7
0.76

33

Gaussian Elimination - example


5
1
106.8 25
5
1 a1 106.8
25
0 4.8 1.56 96.2 0 4.8 1.56 a 96.208

0
0
0.7 0.7 0
0
0.7 a3 0.76
Back Substitution

Solving for a3

Numerical Methods - Lecture 6

0.7 a3 0.76

0.76
0 .7
a3 1.08571
a3

34

Gaussian Elimination - example

Solving for a2

5
1 a1 106.8
25
0 4.8 1.56 a 96.208

0
0
0.7 a3 0.76

4.8a2 1.56a3 96.208

96.208 1.56a3
a3 1.08571
a2
4.8
96.208 1.56 1.08571
a2
4.8
a2 19.6905

Numerical Methods - Lecture 6

35

Gaussian Elimination - example


5
1 a1 106.8
25
0 4.8 1.56 a 96.2

0
0
0.7 a3 0.76

Solving for
a1

a3 1.08571

a2 19.6905

25a1 5a2 a3 106.8

Numerical Methods - Lecture 6

106.8 5a2 a3
a1
25
106.8 5 19.6905 1.08571

25
0.290472
36

Gaussian Elimination - example

Solution:

25
64

144

5
8

12

1
1

a1 106 .8
a 177 .2
2

a 3 279 .2

a1 0.290472
a 19.6905
2

a3 1.08571

v t a1t 2 a2t a3 0.290472 t 2 19.6905t 1.08571, 5 t 12


v6 0.2904726 19.69056 1.08571 129.686 m/s.
2

Numerical Methods - Lecture 6

37

Gaussian Elimination

Disadvantages of the method:

May stop the process of calculation due to a division by


zero.
It is particularly susceptible to accumulation of rounding
errors.
Advantages of the method:
The number of operations in the method of Gaussian
elimination is much smaller than in the method of Cramer
In case of 15 equations
M=1345 multiplications in the method of Gaussian Elimination and
M=51012 for Cramer formulas

Digital machine performs 106 multiplications per second: 0,01 s in


method of Gaussian Elimination and more than a year to formulas
Cramer

Numerical Methods - Lecture 6

38

Gaussian Elimination
Division by zero can occur any time during elimination
of variables

12 10 7 x1 15
6 5
3 x2 14


24 1 5 x3 28

12 10 7 x1 15
0
x 6.5
0
6
.
5

2
0 21 19 x3 2

In the next step, division by zero


Numerical Methods - Lecture 6

39

Gaussian Elimination

The system of equations:

15
10 x1 45
20
3 2.249 7 x 1.751

1
3 x3 9
5

Exact solution

x1
x
2
x3

1
1

1

The solution with an


accuracy 6
decimal digits at
each step

Numerical Methods - Lecture 6

x1 0.9625
x 1.05
2

x3 0.999995

The solution with an


accuracy 5 decimal
digits at each step

x1 0.625
x 1.5
2

x3 0.99995
40

Gaussian Elimination
Partial pivoting method
- with a partial choice of the base element

Prevents division by zero


Reduces the numerical error

The basic element is called the element of matrix A, with which


eliminates the variable of further equations. So far as the basic
elements chose the element lying on the diagonal

akk

Using partial choice the base element to select of the elements


of the k-th column in the k-th matrix, which has the largest
module. By changing sequence of rows in the matrix, you can
get the basic element lying on the diagonal
Numerical Methods - Lecture 6

41

Gaussian Elimination
Example :

25 5 1 a1 106.8
64 8 1 a 177.2

144 12 1 a3 279.2

The values in the first column are:

25 , 64 , 144

25 5 1 106.8
144 12 1 279.2
64 8 1 177.2
64 8 1 177.2

144 12 1 279.2
25 5 1 106.8
Exchange the third row and the first row

Numerical Methods - Lecture 6

42

Gaussian Elimination
25 5 1
A 64 8 1
144 12 1

Calculate the determinant of a matrix [A]

After Gauss elimination

5
1
25
B 0 4.8 1.56
0
0
0.7

Useful Theorem: If the matrix B is formed from the matrix


A by adding or subtracting from one row another row
multiplied by the number, the determinant remains the
same
det(A)=det(B)=25 (-4,8) (0.7)=-84,00

Numerical Methods - Lecture 6

43

Gaussian Elimination
Following application of the
method with partial selection of
basic element , we have
received matrix[C]

12
1
144
C 0 2.917 0.8264
0
0
0.2

Useful Theorem: If the matrix B is formed from the matrix


A by exchanging one row with another, then a change
of sign of the determinant occurs
det(C)=(-)(-)det(B)=144 (2.917) (-0.2)=-84,00

Numerical Methods - Lecture 6

44

Gaussian Elimination

144 12 1 279.2
64 8 1 177.2

25 5 1 106.8

144

Divide row 1 by 144


and multiply by 64

64
0.4444
144

12 1 279.2 0.4444 63.99 5.333 0.4444 124.1

Subtract the result


of equation 2

Numerical Methods - Lecture 6

64
63.99
0

1 177.2

5.333 0.4444

124.1

2.667 0.5556 53.10

12
1
279.2
144
0 2.667 0.5556 53.10

25
5
1
106.8

45

Gaussian Elimination
12
1
279.2
144
0 2.667 0.5556 53.10

25
5
1
106.8

144

Divide equation 1 by
144 and multiply by
25

25
0.1736
144

12 1 279.2 0.1736 25.00 2.083 0.1736 48.47

Subtract the result


of equation 3

Numerical Methods - Lecture 6

25
25
0

1 106.8

2.083 0.1736 48.47

2.917

0.8264 58.33

12
1
279.2
144
0 2.667 0.5556 53.10

0 2.917 0.8264 58.33


46

Gaussian Elimination
The values in the second column of the second and
third row is:
2.667 , 2.917
Maximum is 2.917 in the third row
Replace the third row of the second
12
1
279.2
12
1
279.2
144
144
0 2.667 0.5556 53.10 0 2.917 0.8264 58.33

0 2.917 0.8264 58.33


0 2.667 0.5556 53.10
Numerical Methods - Lecture 6

47

Gaussian Elimination
12
1
279.2 Divide equation 2 by
144
0 2.917 0.8264 58.33 2.917 and multiply by

2.667
0 2.667 0.5556 53.10

2.917

2.667
0.9143.
2.917

0.8264 58.33 0.9143 0 2.667 0.7556 53.33

Subtract the result


of equation 3

Numerical Methods - Lecture 6

0
0
0

2.667 0.5556
2.667 0.7556
0

53.10
53.33

0.2 0.23

12
1
279.2
144
0 2.917 0.8264 58.33

0
0
0.2 0.23

48

Gaussian Elimination

1
144 12
0 2.917 0.8264

0
0.2
0

Solving for a2

a1 279.2
a 58.33
2

a3 0.23

2.917a2 0.8264a3 58.33

Numerical Methods - Lecture 6

58.33 0.8264a3
a2
2.917
58.33 0.8264 1.15

2.917
19.67

49

Gaussian Elimination
1
144 12
0 2.917 0.8264

0
0.2
0

Solving for a1

a1 279.2
a 58.33
2

a3 0.23

144a1 12a2 a3 279.2

Numerical Methods - Lecture 6

279.2 12a2 a3
a1
144
279.2 12 19.67 1.15

144
0.2917

50

Solution:

25
64

144

Numerical Methods - Lecture 6

Gaussian Elimination

5
8

12

1
1

a 1 106 .8
a 177 .2
2

a 3 279 .2

a1 0.2917
a 19.67
2

a3 1.15
51

Gauss-Seidel Method
System of n equations with n unknowns:

a11 x1 a12 x2 a13 x3 ... a1n xn b1

a21 x1 a22 x2 a23 x3 ... a2n xn b2


.
.
.

.
.
.

.
.
.

an1 x1 an 2 x2 an 3 x3 ... ann xn bn


Numerical Methods - Lecture 6

52

Gauss-Seidel Method

The transformation equations to the form:

b1 a12 x2 a13 x3 a1n xn


x1
a11
b2 a21 x1 a23 x3 a2 n xn
x2
a22

from equation 1

from equation 2
with n-1

bn 1 an 1,1 x1 an 1,2 x2 an 1,n 2 xn 2 an 1,n xn


xn 1
an 1,n 1
bn an1 x1 an 2 x2 an,n1 xn 1
xn
ann
Numerical Methods - Lecture 6

from equation n

53

Gauss-Seidel Method
General form of the i - th equation

bi aij x j
n

xi

j 1
j i

aii

, i 1,2,, n.

This is an iterative method

Numerical Methods - Lecture 6

54

Gauss-Seidel Method
We assume the initial values of x1 to xn and substitute
them into previously transformed equations
Calculate the Absolute Relative Approximate Error

a i

xinew xiold

100
new
xi

x1
x
2


xn -1
xn

The iterations are stopped when the absolute relative


approximate error is less than a prespecified tolerance for all
unknowns.
Numerical Methods - Lecture 6

55

Example:

Gauss-Seidel Method
Time t
(s)
5

Velocity
(m/s)

12

106.8
177.2

279.2

The velocity data is approximated by a polynomial as:

vt a1t 2 a 2 t a3 ,

5 t 12.

Find coefficients a1, a2, a3 by Gauss-Seidel method


and velocity in time t = 6 s
Numerical Methods - Lecture 6

56

Gauss-Seidel Method
Using a Matrix
template of the
form:
The system of
equations
becomes:
Initial Guess: Assume an
initial guess of
Numerical Methods - Lecture 6

t12
2
t 2
t32

t1
t2
t3

1 a1 v1

1 a2 v2
1 a3 v3

25 5 1 a1 106 .8
64 8 1 a 177 .2

144 12 1 a3 279 .2

a1 1
a 2
2
a3 5

57

Gauss-Seidel Method
Rewriting each equation:

25 5 1 a1 106 .8
64 8 1 a 177 .2

144 12 1 a3 279 .2

Numerical Methods - Lecture 6

106.8 5a 2 a 3
a1
25

177.2 64a1 a 3
a2
8
279.2 144 a1 12a 2
a3
1
58

Gauss-Seidel Method
The first iteration:

a1 1
a 2
2
a3 5

106.8 5( 2) (5)
a1
3.6720
25

177.2 643.6720 5
a2
7.8510
8

279.2 1443.6720 12 7.8510


a3
155.36
1

Numerical Methods - Lecture 6

59

Gauss-Seidel Method

Finding the absolute relative approximate error:


a i

xinew xiold

100
new
xi

a 1

3.6720 1.0000
100 72.76%
3.6720

a 2

7.8510 2.0000
100 125.47%
7.8510

a 3

155.36 5.0000
100 103.22%
155.36

Numerical Methods - Lecture 6

At the end of the first


iteration:
a1 3.6720
a 7.8510
2

a 3 155 .36

The maximum
absolute relative
approximate error
is 125.47%
60

Gauss-Seidel Method
Second iteration:

106.8 5 7.8510 155.36


a1
12.056
25

a1 3.6720
a 7.8510
2

a3 155.36

The results of the


first iteration:
a3

Numerical Methods - Lecture 6

177.2 6412.056 155.36


a2
54.882
8

279.2 14412.056 12 54.882


798.34
1

61

Gauss-Seidel Method
Finding the absolute relative approximate error:
12.056 3.6720
a 1
x100 69.543%
12.056

54.882 7.8510

x100 85.695%
54.882

a1 12.056
a 54.882
2

a3 798.54

The maximum
absolute
798.34 155.36
relative
a 3
x100 80.540%
798.34
approximate
error is
85.695%

Numerical Methods - Lecture 6

62

Gauss-Seidel Method

Iteration

1
2
3
4
5
6

a1

3.6720
12.056
47.182
193.33
800.53
3322.6

a 1 %

72.767
69.543
74.447
75.595
75.850
75.906

a2

7.8510
54.882
255.51
1093.4
4577.2
19049

Repeating more iterations, the


following values are obtained:

a 2 %

125.47
85.695
78.521
76.632
76.112
75.972

a3

155.36
798.34
3448.9
14440
60072
24958
0

a 3 %

103.22
80.540
76.852
76.116
75.963
75.931

a 1 0.29048
a 19.690
2

a 3 1.0857

When this method is consistent?


Numerical Methods - Lecture 6

63

Gauss-Seidel Method
If the matrix is strongly diagonally dominant the
Gauss-Seidel method is convergent

aii aij
n

j 1, j i

aii aij
n

j 1, j i

Numerical Methods - Lecture 6

for all i

for at least one i

64

Gauss-Seidel Method
Example of a matrix diagonally dominant

12 3 5
1 5 3

3 7 13

a11 a12 a13 8

a22 a21 a23 4

a33 a31 a32 10


Numerical Methods - Lecture 6

65

LU Decomposition
LU Decomposition is another method to solve a set of
simultaneous linear equations

Ax b

The matrix A can be represented as:

A LU

where:
L lower triangular matrix
U upper triangular matrix
Numerical Methods - Lecture 6

66

LU Decomposition
If solving a set of linear
equations:

Multiply by:
but:

L L I

unit matrix

Numerical Methods - Lecture 6

L U X C

A LU

AX C

L LU X L C
1

I U X L C
1

but:
therefore:

I U U
1
U X L C

L1 C Z

LZ C

U X Z

67

LU Decomposition

U X L C
1

You can save

U X Z L1 C Z

LZ C
Numerical Methods - Lecture 6

68

LU Decomposition
Given:

AX C

Decompose [A] into [L] and [U]


Solve [L][Z] = [C] for [Z]
Solve [U][X] = [Z] for [X]
Numerical Methods - Lecture 6

69

LU Decomposition
[A] Decompose to [L] and [U]

1
A LU 21
31

32

0 u11
0 0
1 0

u12

u 22
0

u13
u 23
u 33

[U] is the same as the coefficient matrix at the end of


the forward elimination step.
[L] is obtained using the multipliers that were used in
the forward elimination process
Numerical Methods - Lecture 6

70

LU Decomposition - example

To find the shape of the object with images of the surface in three
dimensions, for example, you need to solve the following system
of equations:
0,2425

0,2357

0
0,2425

0,2357

0,9701 x 1 247
0,9701 x 2 248
0,9428 x 3 239

On the right are the intensity of light from the center of the image.
The matrix coefficients depend on the direction of the light source
relative to the camera. Unknowns are the intensity of the image,
which will determine the shape of the object. We find values x1,
x2, x3 using LU decomposition.
Numerical Methods - Lecture 6

71

Solution:

LU Decomposition example

1
A LU 21
31

0
1
32

0 u11
0 0
1 0

u12
u 22
0

u13
u 23
u 33

We are looking for a matrix [L] and [U].


Matrix [U] will be calculated using Gaussian elimination.
Numerical Methods - Lecture 6

72

LU Decomposition - example

First step:
0
0,9701
0,2425
row1
0

row2

(
0
)

0
,
2425

0
,
9701

0,2425
0,2357 0,2357 0,9428
0
0,9701
0,2425
row1
0

row3

0
,
2357
)

0
,
2425

0
,
9701

0,2425
0
0,2357 1,8857

Numerical Methods - Lecture 6

73

LU Decomposition - example

Second step:
0
0,9701
0,2425
row2
0

row3

0
,
2357
)

0
,
2425

0
,
9701

0,2425
0
0
2,8286

Coefficient matrix [U] is:

0
0,9701
0,2425
U 0 0,2425 0,9701
0
0
2,8286
Numerical Methods - Lecture 6

we determine
matrix [L]:
0
1
[ L] 21 1
31 32

0
0
1

74

LU Decomposition - example
Finding the L matrix:
1

21
31

32

0
0 the first step of
1 finding the matrix U

the second step of


finding the matrix
L
Numerical Methods - Lecture 6

a 21
0
21

0
a11 0,2425

a 31 0,2357
31

0,97196
a 11
0,2425

32

a 32 0,2357

0,97196
a 22
0,2425

75

LU Decomposition - example

When matrix [L] and [U] are known, we will try to solve
the system [L][Z]=[C]:
1

0,97196

0
1

0,97196

0 z1 247
0 z 2 248
1 z 3 239

z1 247

z 2 248

z3 239 ( 0,97196 ) z1 ( 0,97196 ) z 2


z3 720 ,12
Numerical Methods - Lecture 6

76

LU Decomposition - example
z1 247
[ Z ] z 2 248
z 3 720 ,12

Knowing already [Z] we solve


the system [U][X]=[Z]

0,2425
0

0
Numerical Methods - Lecture 6

0
0,2425
0

0,9701 x 1 247
0,9701 x 2 248
2,8286 x 3 720 ,12
77

LU Decomposition - example

Solving system of equations:

0,2425 x1 ( 0,9701) x3 247

0,2425 x2 ( 0,9701) x3 248


2,8286 x3 720 ,12

we get vector x:

Numerical Methods - Lecture 6

x 1 0,10905
x 4,2328
2

x 3 254 ,59
78

LU Decomposition - example

Homework:
Solve the system of describing the three-phase AC
circuit:

Numerical Methods - Lecture 6

79

Vous aimerez peut-être aussi