ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 18 LU Decomposition and...

Preview:

Citation preview

ECIV 301

Programming & Graphics

Numerical Methods for Engineers

Lecture 18

LU Decomposition and Matrix Inversion

EXAMPLE

4.71

3.19

85.7

102.03.0

3.071.0

2.01.03

3

2

1

x

x

x

Eliminate Column 1

3

1.0

PIVOTS

4.71

3.19

85.7

102.03.0

3.071.0

2.01.03

3

3.0

1,11

11 ia

apivot i

i

njapivotaa jiijij ,,2,1,11

Eliminate Column 1

6150.70

5617.19

85.7

0200.1019000.00

29333.000333.70

2.01.03

Eliminate Column 2

00333.7

19000.0

PIVOTS

6150.70

5617.19

85.7

0200.1019000.00

29333.000333.70

2.01.03

2,22

22 ia

apivot i

i

njapivotaa jiijij ,,2,1,22

Eliminate Column 2

0843.70

5617.19

85.7

01200.1000

29333.000333.70

2.01.03

UpperTriangular

Matrix[ U ]

ModifiedRHS

{ b }

LU DecompositionPIVOTS

Column 1PIVOTS

Column 2

03333.0

1.0 02713.0

LU Decomposition

As many as, and in the location of, zeros

UpperTriangular

MatrixU

01200.1000

29333.000333.70

2.01.03

LU DecompositionPIVOTS

Column 1

PIVOTSColumn 2

LowerTriangular

Matrix

1

1

1

0

0

0

L

03333.0

1.0 02713.0

LU Decomposition

102713.01.0

0103333.0

001

=

This is the original matrix!!!!!!!!!!

01200.1000

29333.000333.70

2.01.03

102.03.0

3.071.0

2.01.03

LU Decomposition

4.71

3.19

85.7

102713.01.0

0103333.0

001

3

2

1

y

y

y

4.71

3.19

85.7

102.03.0

3.071.0

2.01.03

3

2

1

x

x

x

[ L ] { y } { b }

[ A ] { x } { b }

LU Decomposition

4.71

3.19

85.7

102713.01.0

0103333.0

001

3

2

1

y

y

y

L y b

85.71 y

5617.190333.03.19 12 yy

0843.70)02713.0(1.04.71 213 yyy

LU Decomposition85.71 y

5617.190333.03.19 12 yy

0843.70)02713.0(1.04.71 213 yyy

0843.70

5617.19

85.7

01200.1000

29333.000333.70

2.01.03

ModifiedRHS

{ b }

LU Decomposition

• Ax=b

• A=LU - LU Decomposition

• Ly=b- Solve for y

• Ux=y - Solve for x

Matrix Inversion

4.71

3.19

85.7

102.03.0

3.071.0

2.01.03

3

2

1

x

x

x

bxA

Matrix Inversion

[A] [A]-1

[A] [A]-1=[I]

If [A]-1 does not exist[A] is singular

Matrix Inversion

b xA bxA 1A 1A

I

Matrix Inversion

bAx 1

Solution

Matrix Inversion

[A] [A]-1=[I]

100

010

001

aaa

aaa

aaa

aaa

aaa

aaa

nnn2n1

2n2221

1n1211

nnn2n1

2n2221

1n1211

Matrix Inversion

100

010

001

aaa

aaa

aaa

aaa

aaa

aaa

nnn2n1

2n2221

1n1211

nnn2n1

2n2221

1n1211

Matrix Inversion

100

010

001

aaa

aaa

aaa

aaa

aaa

aaa

nnn2n1

2n2221

1n1211

nnn2n1

2n2221

1n1211

Matrix Inversion

100

010

001

aaa

aaa

aaa

aaa

aaa

aaa

nnn2n1

2n2221

1n1211

nnn2n1

2n2221

1n1211

Matrix Inversion

• To calculate the invert of a nxn matrix solve n times :

nj

2j

1j

nj

2j

1j

nnn2n1

2n2221

1n1211

a

a

a

aaa

aaa

aaa

nj ,,2,1

otherwise

ji if

0

1ij

Matrix Inversion

• For example in order to calculate the inverse of:

102.03.0

3.071.0

2.01.03

Matrix Inversion

• First Column of Inverse is solution of

0

0

1

a

a

a

102.03.0

3.071.0

2.01.03

31

21

11

Matrix Inversion

0

1

0

a

a

a

102.03.0

3.071.0

2.01.03

32

22

12

• Second Column of Inverse is solution of

Matrix Inversion

• Third Column of Inverse is solution of:

1

0

0

a

a

a

102.03.0

3.071.0

2.01.03

33

23

13

Use LU Decomposition

102713.01.0

0103333.0

001

01200.1000

29333.000333.70

2.01.03

102.03.0

3.071.0

2.01.03

A

Use LU Decomposition – 1st column

• Forward SUBSTITUTION

0

0

1

y

y

y

102713.01.0

0103333.0

001

31

21

11

111 y

03333.00333.00 1121 yy

1009.002713.01.00 211131 yyy

Use LU Decomposition – 1st column

• Back SUBSTITUTION

1009.0

0333.0

1

a

a

a

01200.1000

29333.000333.70

2.01.03

31

21

11

010078.0012.10/1009.0a31

00518.000333.7/a2933.00333.0a 3121

332489.03/a2.0a1.01a 312111

Use LU Decomposition – 2nd Column

• Forward SUBSTITUTION

0

1

0

y

y

y

102713.01.0

0103333.0

001

32

22

12

012 y

122 y

02713.002713.01.00 221232 yyy

Use LU Decomposition – 2nd Column

• Back SUBSTITUTION

02713.0

1

0

a

a

a

01200.1000

29333.000333.70

2.01.03

32

22

12

002709.0012.10/02713.0a32

1429.000333.7/a2933.01a 3222

004944.03/a2.0a1.00a 322212

Use LU Decomposition – 3rd Column

• Forward SUBSTITUTION

1

0

0

y

y

y

102713.01.0

0103333.0

001

33

23

13

013 y

023 y

102713.01.01 231333 yyy

Use LU Decomposition – 3rd Column

• Back SUBSTITUTION

1

0

0

a

a

a

01200.1000

29333.000333.70

2.01.03

33

23

13

09988.0012.10/1a33

004183.000333.7/a2933.00a 3323

006798.03/a2.0a1.00a 332313

Result

102.03.0

3.071.0

2.01.03

A

09988.000271.001008.0

004183.0142903.000518.0

006798.0004944.0332489.0

A 1

Test It

09988.000271.001008.0

004183.0142903.000518.0

006798.0004944.0332489.0

102.03.0

3.071.0

2.01.03

11046.30

1047.31106736.8

0108.11

18

1818

18

Recommended