36
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 18 LU Decomposition and Matrix Inversion

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

  • View
    222

  • Download
    1

Embed Size (px)

Citation preview

Page 1: ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 18 LU Decomposition and Matrix Inversion

ECIV 301

Programming & Graphics

Numerical Methods for Engineers

Lecture 18

LU Decomposition and Matrix Inversion

Page 2: 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

Page 3: ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 18 LU Decomposition and Matrix Inversion

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

Page 4: ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 18 LU Decomposition and Matrix Inversion

Eliminate Column 1

6150.70

5617.19

85.7

0200.1019000.00

29333.000333.70

2.01.03

Page 5: ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 18 LU Decomposition and Matrix Inversion

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

Page 6: ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 18 LU Decomposition and Matrix Inversion

Eliminate Column 2

0843.70

5617.19

85.7

01200.1000

29333.000333.70

2.01.03

UpperTriangular

Matrix[ U ]

ModifiedRHS

{ b }

Page 7: ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 18 LU Decomposition and Matrix Inversion

LU DecompositionPIVOTS

Column 1PIVOTS

Column 2

03333.0

1.0 02713.0

Page 8: ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 18 LU Decomposition and Matrix Inversion

LU Decomposition

As many as, and in the location of, zeros

UpperTriangular

MatrixU

01200.1000

29333.000333.70

2.01.03

Page 9: ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 18 LU Decomposition and Matrix Inversion

LU DecompositionPIVOTS

Column 1

PIVOTSColumn 2

LowerTriangular

Matrix

1

1

1

0

0

0

L

03333.0

1.0 02713.0

Page 10: ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 18 LU Decomposition and Matrix Inversion

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

Page 11: ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 18 LU Decomposition and Matrix Inversion

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 }

Page 12: ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 18 LU Decomposition and Matrix Inversion

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

Page 13: ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 18 LU Decomposition and Matrix Inversion

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 }

Page 14: ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 18 LU Decomposition and Matrix Inversion

LU Decomposition

• Ax=b

• A=LU - LU Decomposition

• Ly=b- Solve for y

• Ux=y - Solve for x

Page 15: ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 18 LU Decomposition and Matrix Inversion

Matrix Inversion

4.71

3.19

85.7

102.03.0

3.071.0

2.01.03

3

2

1

x

x

x

bxA

Page 16: ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 18 LU Decomposition and Matrix Inversion

Matrix Inversion

[A] [A]-1

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

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

Page 17: ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 18 LU Decomposition and Matrix Inversion

Matrix Inversion

b xA bxA 1A 1A

I

Page 18: ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 18 LU Decomposition and Matrix Inversion

Matrix Inversion

bAx 1

Solution

Page 19: ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 18 LU Decomposition and Matrix Inversion

Matrix Inversion

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

100

010

001

aaa

aaa

aaa

aaa

aaa

aaa

nnn2n1

2n2221

1n1211

nnn2n1

2n2221

1n1211

Page 20: ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 18 LU Decomposition and Matrix Inversion

Matrix Inversion

100

010

001

aaa

aaa

aaa

aaa

aaa

aaa

nnn2n1

2n2221

1n1211

nnn2n1

2n2221

1n1211

Page 21: ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 18 LU Decomposition and Matrix Inversion

Matrix Inversion

100

010

001

aaa

aaa

aaa

aaa

aaa

aaa

nnn2n1

2n2221

1n1211

nnn2n1

2n2221

1n1211

Page 22: ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 18 LU Decomposition and Matrix Inversion

Matrix Inversion

100

010

001

aaa

aaa

aaa

aaa

aaa

aaa

nnn2n1

2n2221

1n1211

nnn2n1

2n2221

1n1211

Page 23: ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 18 LU Decomposition and Matrix Inversion

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

Page 24: ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 18 LU Decomposition and Matrix Inversion

Matrix Inversion

• For example in order to calculate the inverse of:

102.03.0

3.071.0

2.01.03

Page 25: ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 18 LU Decomposition and Matrix Inversion

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

Page 26: ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 18 LU Decomposition and Matrix Inversion

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

Page 27: ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 18 LU Decomposition and Matrix Inversion

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

Page 28: ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 18 LU Decomposition and Matrix Inversion

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

Page 29: ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 18 LU Decomposition and Matrix Inversion

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

Page 30: ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 18 LU Decomposition and Matrix Inversion

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

Page 31: ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 18 LU Decomposition and Matrix Inversion

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

Page 32: ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 18 LU Decomposition and Matrix Inversion

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

Page 33: ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 18 LU Decomposition and Matrix Inversion

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

Page 34: ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 18 LU Decomposition and Matrix Inversion

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

Page 35: ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 18 LU Decomposition and Matrix Inversion

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

Page 36: ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 18 LU Decomposition and Matrix Inversion

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