Top Banner
Gaussian Elimination Major: All Engineering Majors Author(s): Autar Kaw http://numericalmethods.eng.u sf.edu Transforming Numerical Methods Education for STEM Undergraduates
90

Gaussian Elimination

Feb 22, 2016

Download

Documents

stamos

Gaussian Elimination. Major: All Engineering Majors Author(s): Autar Kaw http://numericalmethods.eng.usf.edu Transforming Numerical Methods Education for STEM Undergraduates. Naïve Gauss Elimination. Naïve Gaussian Elimination. - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Gaussian Elimination

Gaussian Elimination

Major: All Engineering Majors

Author(s): Autar Kaw

http://numericalmethods.eng.usf.eduTransforming Numerical Methods Education for STEM

Undergraduates

Page 2: Gaussian Elimination

Naïve Gauss Elimination

Page 3: Gaussian Elimination

Naïve Gaussian EliminationA method to solve simultaneous linear equations of the form [A][X]=[C]Two steps1. Forward Elimination2. Back Substitution

Page 4: Gaussian Elimination

Forward Elimination

2.2792.1778.106

11214418641525

3

2

1

xxx

The goal of forward elimination is to transform the coefficient matrix into an upper triangular matrix

735.021.968.106

7.00056.18.40

1525

3

2

1

xxx

Page 5: Gaussian Elimination

Forward EliminationA set of n equations and n unknowns

11313212111 ... bxaxaxaxa nn

22323222121 ... bxaxaxaxa nn

nnnnnnn bxaxaxaxa ...332211

. . . . . .

(n-1) steps of forward elimination

Page 6: Gaussian Elimination

Forward EliminationStep 1 For Equation 2, divide Equation 1 by and multiply by .

)...( 1131321211111

21 bxaxaxaxaaa

nn

111

211

11

21212

11

21121 ... b

aaxa

aaxa

aaxa nn

11a21a

Page 7: Gaussian Elimination

Forward Elimination

111

211

11

21212

11

21121 ... b

aaxa

aaxa

aaxa nn

111

2121

11

212212

11

2122 ... b

aabxa

aaaxa

aaa nnn

'2

'22

'22 ... bxaxa nn

22323222121 ... bxaxaxaxa nn Subtract the result from Equation 2.

−_________________________________________________

or

Page 8: Gaussian Elimination

Forward EliminationRepeat this procedure for the remaining equations to reduce the set of equations as

11313212111 ... bxaxaxaxa nn '2

'23

'232

'22 ... bxaxaxa nn

'3

'33

'332

'32 ... bxaxaxa nn

''3

'32

'2 ... nnnnnn bxaxaxa

. . . . . . . . .

End of Step 1

Page 9: Gaussian Elimination

Step 2Repeat the same procedure for the 3rd term of Equation 3.

Forward Elimination

11313212111 ... bxaxaxaxa nn

'2

'23

'232

'22 ... bxaxaxa nn

"3

"33

"33 ... bxaxa nn

""3

"3 ... nnnnn bxaxa

. . . . . .

End of Step 2

Page 10: Gaussian Elimination

Forward EliminationAt the end of (n-1) Forward Elimination steps, the system of equations will look like

'2

'23

'232

'22 ... bxaxaxa nn

"3

"33

"33 ... bxaxa nn

11 nnn

nnn bxa

. . . . . .

11313212111 ... bxaxaxaxa nn

End of Step (n-1)

Page 11: Gaussian Elimination

Matrix Form at End of Forward Elimination

)(n-n

"

'

n)(n

nn

"n

"

'n

''n

b

bbb

x

xxx

a

aaaaaaaaa

1

3

2

1

3

2

1

1

333

22322

1131211

0000

000

Page 12: Gaussian Elimination

Back SubstitutionSolve each equation starting from the last equation

Example of a system of 3 equations

735.021.968.106

7.00056.18.40

1525

3

2

1

xxx

Page 13: Gaussian Elimination

Back Substitution Starting Eqns

'2

'23

'232

'22 ... bxaxaxa nn

"3

"3

"33 ... bxaxa nn

11 nnn

nnn bxa

. .

. . . .

11313212111 ... bxaxaxaxa nn

Page 14: Gaussian Elimination

Back SubstitutionStart with the last equation because it has only one unknown

)1(

)1(

nnn

nn

n ab

x

Page 15: Gaussian Elimination

Back Substitution

1,...,1for11

11

nia

xabx i

ii

n

ijj

iij

ii

i

)1(

)1(

nnn

nn

n ab

x

1,...,1for...

1

1,2

12,1

11,

1

nia

xaxaxabx i

ii

ninii

iiii

iii

ii

i

Page 16: Gaussian Elimination

THE END

Page 17: Gaussian Elimination

Example 1The upward velocity of a rocket is given at three different times

Time, Velocity, 5 106.88 177.212 279.2

The velocity data is approximated by a polynomial as:

12.t5 , 322

1 atatatv

Find the velocity at t=6 seconds .

s t m/s vTable 1 Velocity vs. time data.

Page 18: Gaussian Elimination

Example 1 Cont. Assume

12.t5 ,atatatv 322

1

3

2

1

323

222

121

111

vvv

aaa

tttttt

3

2

1

Results in a matrix template of the form:

Using data from Table 1, the matrix becomes:

2.2792.1778.106

11214418641525

3

2

1

aaa

Page 19: Gaussian Elimination

Example 1 Cont.

22791121442177186481061525

227921778106

11214418641525

3

2

1

.

.

.

.

.

.

aaa

1. Forward Elimination2. Back Substitution

Page 20: Gaussian Elimination

Forward Elimination

Page 21: Gaussian Elimination

Number of Steps of Forward Elimination

Number of steps of forward elimination is

(n1)(31)2

Page 22: Gaussian Elimination

Divide Equation 1 by 25 andmultiply it by 64, .

Forward Elimination: Step 1

.

408.27356.28.126456.28.1061525

208.96 56.18.4 0

408.273 56.2 8.1264177.2 1 8 64

2.2791121442.17718648.1061525

2.279112144208.9656.18.408.1061525

56.22564

Subtract the result from Equation 2

Substitute new equation for Equation 2

Page 23: Gaussian Elimination

Forward Elimination: Step 1 (cont.)

.

168.61576.58.2814476.58.1061525

2.279112144208.9656.18.408.1061525

968.335 76.48.16 0

168.615 76.5 8.28 144279.2 1 12 144

968.33576.48.160208.9656.18.408.1061525

Divide Equation 1 by 25 andmultiply it by 144, .

76.525

144

Subtract the result from Equation 3

Substitute new equation for Equation 3

Page 24: Gaussian Elimination

Forward Elimination: Step 2

728.33646.58.1605.3208.9656.18.40

968.33576.48.160208.9656.18.408.1061525

.760 7.0 0 0

728.33646.516.80335.968 76.416.80

76.07.000208.9656.18.408.1061525

Divide Equation 2 by −4.8and multiply it by −16.8, .

5.38.48.16

Subtract the result from Equation 3

Substitute new equation for Equation 3

Page 25: Gaussian Elimination

Back Substitution

Page 26: Gaussian Elimination

Back Substitution

76.0208.968.106

7.00056.18.40

1525

7.07.0002.9656.18.408.1061525

3

2

1

aaa

08571.17.076.076.07.0

3

3

3

a

a

aSolving for a3

Page 27: Gaussian Elimination

Back Substitution (cont.)

Solving for a2

690519. 4.8

1.085711.5696.208

8.456.1208.96

208.9656.18.4

2

2

32

32

a

a

aa

aa

76.0208.968.106

7.00056.18.40

1525

3

2

1

aaa

Page 28: Gaussian Elimination

Back Substitution (cont.)

Solving for a1

290472.025

08571.16905.1958.1062558.106

8.106525

321

321

aaa

aaa

76.02.968.106

7.00056.18.40

1525

3

2

1

aaa

Page 29: Gaussian Elimination

Naïve Gaussian Elimination Solution

227921778106

11214418641525

3

2

1

.

.

.

aaa

08571.16905.19

290472.0

3

2

1

aaa

Page 30: Gaussian Elimination

Example 1 Cont.SolutionThe solution vector is

08571.16905.19

290472.0

3

2

1

aaa

The polynomial that passes through the three data points is then:

125 ,08571.16905.19290472.0 2

322

1

ttt

atatatv

.m/s 686.129

08571.166905.196290472.06 2

v

Page 31: Gaussian Elimination

Naïve Gauss EliminationPitfalls

Page 32: Gaussian Elimination

95511326

3710

321

321

32

xxxxxx

xx

Pitfall#1. Division by zero

9113

5153267100

3

2

1

xxx

Page 33: Gaussian Elimination

Is division by zero an issue here?

95514356

1571012

321

321

321

xxxxxx

xxx

91415

51535671012

3

2

1

xxx

Page 34: Gaussian Elimination

Is division by zero an issue here? YES

2852414356

1571012

321

321

321

xxxxxx

xxx

281415

512435671012

3

2

1

xxx

25.6

15

1921125.60071012

3

2

1

xxx

Division by zero is a possibility at any step of forward elimination

Page 35: Gaussian Elimination

Pitfall#2. Large Round-off Errors

9751.145

3157249.23

101520

3

2

1

xxx

Exact Solution

111

3

2

1

xxx

Page 36: Gaussian Elimination

Pitfall#2. Large Round-off Errors

9751.145

3157249.23

101520

3

2

1

xxx

Solve it on a computer using 6 significant digits with chopping

999995.005.1

9625.0

3

2

1

xxx

Page 37: Gaussian Elimination

Pitfall#2. Large Round-off Errors

9751.145

3157249.23

101520

3

2

1

xxx

Solve it on a computer using 5 significant digits with chopping

99995.05.1

625.0

3

2

1

xxx

Is there a way to reduce the round off error?

Page 38: Gaussian Elimination

Avoiding PitfallsIncrease the number of significant digits• Decreases round-off error• Does not avoid division by zero

Page 39: Gaussian Elimination

Avoiding Pitfalls

Gaussian Elimination with Partial Pivoting

• Avoids division by zero• Reduces round off error

Page 40: Gaussian Elimination

THE END

Page 41: Gaussian Elimination

Gauss Elimination with Partial Pivoting

Page 42: Gaussian Elimination

Pitfalls of Naïve Gauss Elimination

• Possible division by zero• Large round-off errors

Page 43: Gaussian Elimination

Avoiding PitfallsIncrease the number of significant digits• Decreases round-off error• Does not avoid division by zero

Page 44: Gaussian Elimination

Avoiding PitfallsGaussian Elimination with Partial

Pivoting• Avoids division by zero• Reduces round off error

Page 45: Gaussian Elimination

What is Different About Partial Pivoting?

pka

At the beginning of the kth step of forward elimination, find the maximum of

nkkkkk aaa .......,,........., ,1

If the maximum of the values is in the p th row, ,npk then switch rows p

and k.

Page 46: Gaussian Elimination

Matrix Form at Beginning of 2nd Step of Forward Elimination

'

'3

2

1

3

2

1

''4

'32

'3

'3332

22322

1131211

0

00

n

'

nnnnn'n

n'

'n

''n

b

bbb

x

xxx

aaaa

aaaaaaaaaa

Page 47: Gaussian Elimination

Example (2nd step of FE)

3986

5

43111217086239011112402167067.31.5146

5

4

3

2

1

xxxxx

Which two rows would you switch?

Page 48: Gaussian Elimination

Example (2nd step of FE)

69835

21670862390111124043111217067.31.5146

5

4

3

2

1

xxxxx

Switched Rows

Page 49: Gaussian Elimination

Gaussian Elimination with Partial Pivoting

A method to solve simultaneous linear equations of the form [A][X]=[C]

Two steps1. Forward Elimination2. Back Substitution

Page 50: Gaussian Elimination

Forward EliminationSame as naïve Gauss elimination

method except that we switch rows before each of the (n-1) steps of forward elimination.

Page 51: Gaussian Elimination

Example: Matrix Form at Beginning of 2nd Step of

Forward Elimination

'

'3

2

1

3

2

1

''4

'32

'3

'3332

22322

1131211

0

00

n

'

nnnnn'n

n'

'n

''n

b

bbb

x

xxx

aaaa

aaaaaaaaaa

Page 52: Gaussian Elimination

Matrix Form at End of Forward Elimination

)(n-n

"

'

n)(n

nn

"n

"

'n

''n

b

bbb

x

xxx

a

aaaaaaaaa

1

3

2

1

3

2

1

1

333

22322

1131211

0000

000

Page 53: Gaussian Elimination

Back Substitution Starting Eqns

'2

'23

'232

'22 ... bxaxaxa nn

"3

"3

"33 ... bxaxa nn

11 nnn

nnn bxa

. .

. . . .

11313212111 ... bxaxaxaxa nn

Page 54: Gaussian Elimination

Back Substitution

1,...,1for11

11

nia

xabx i

ii

n

ijj

iij

ii

i

)1(

)1(

nnn

nn

n ab

x

Page 55: Gaussian Elimination

THE END

Page 56: Gaussian Elimination

Gauss Elimination with Partial Pivoting

Example

Page 57: Gaussian Elimination

Example 2

227921778106

11214418641525

3

2

1

.

.

.

aaa

Solve the following set of equations by Gaussian elimination with partial pivoting

Page 58: Gaussian Elimination

Example 2 Cont.

227921778106

11214418641525

3

2

1

.

.

.

aaa

1. Forward Elimination2. Back Substitution

2.2791121442.17718648.1061525

Page 59: Gaussian Elimination

Forward Elimination

Page 60: Gaussian Elimination

Number of Steps of Forward Elimination

Number of steps of forward elimination is (n1)=(31)=2

Page 61: Gaussian Elimination

Forward Elimination: Step 1• Examine absolute values of first column, first row

and below.144,64,25

• Largest absolute value is 144 and exists in row 3.

• Switch row 1 and row 3.

8.10615252.17718642.279112144

2.2791121442.17718648.1061525

Page 62: Gaussian Elimination

Forward Elimination: Step 1 (cont.)

.

1.1244444.0333.599.634444.02.279112144

8.10615252.17718642.279112144

10.53.55560667.2 0

124.1 0.44445.33363.99177.21 8 64

8.106152510.535556.0667.20

2.279112144

Divide Equation 1 by 144 andmultiply it by 64, .

4444.014464

Subtract the result from Equation 2

Substitute new equation for Equation 2

Page 63: Gaussian Elimination

Forward Elimination: Step 1 (cont.)

.

47.481736.0083.200.251736.0279.2112144

33.588264.0 917.20

48.470.17362.08325106.81 5 25

8.106152510.535556.0667.20

2.279112144

33.588264.0917.2010.535556.0667.20

2.279112144

Divide Equation 1 by 144 andmultiply it by 25, .

1736.014425

Subtract the result from Equation 3

Substitute new equation for Equation 3

Page 64: Gaussian Elimination

Forward Elimination: Step 2• Examine absolute values of second column, second

row and below. 2.917,667.2

• Largest absolute value is 2.917 and exists in row 3.

• Switch row 2 and row 3.

10.535556.0667.2033.588264.0917.20

2.279112144

33.588264.0917.2010.535556.0667.20

2.279112144

Page 65: Gaussian Elimination

Forward Elimination: Step 2 (cont.)

.

33.537556.0667.209143.058.330.82642.9170

10.535556.0667.2033.588264.0917.202.279112144

23.02.0 0 0

53.33 0.75562.667053.10 0.55562.6670

23.02.00033.588264.0917.202.279112144

Divide Equation 2 by 2.917 andmultiply it by 2.667, .9143.0

917.2667.2

Subtract the result from Equation 3

Substitute new equation for Equation 3

Page 66: Gaussian Elimination

Back Substitution

Page 67: Gaussian Elimination

Back Substitution

1.152.023.023.02.0

3

3

a

a

Solving for a3

2303358

2279

20008264091720112144

23.02.00033.588264.0917.20

2.279112144

3

2

1

...

aaa

.

..

Page 68: Gaussian Elimination

Back Substitution (cont.)

Solving for a2

6719.917.2

15.18264.033.58917.2

8264.033.5833.588264.0917.2

32

32

aa

aa

2303358

2279

20008264091720112144

3

2

1

...

aaa

.

..

Page 69: Gaussian Elimination

Back Substitution (cont.)

Solving for a1

2917.0144

15.167.19122.279144122.279

2.27912144

321

321

aaa

aaa

2303358

2279

20008264091720112144

3

2

1

...

aaa

.

..

Page 70: Gaussian Elimination

Gaussian Elimination with Partial Pivoting Solution

227921778106

11214418641525

3

2

1

.

.

.

aaa

15.167.19

2917.0

3

2

1

aaa

Page 71: Gaussian Elimination

Gauss Elimination with Partial Pivoting

Another Example

Page 72: Gaussian Elimination

Partial Pivoting: ExampleConsider the system of equations

655901.36099.23

7710

321

321

21

xxxxxx

xx

In matrix form

5156099.230710

3

2

1

xxx

6901.37

=

Solve using Gaussian Elimination with Partial Pivoting using five significant digits with chopping

Page 73: Gaussian Elimination

Partial Pivoting: ExampleForward Elimination: Step 1

Examining the values of the first column

|10|, |-3|, and |5| or 10, 3, and 5

The largest absolute value is 10, which means, to follow the rules of Partial Pivoting, we switch row1 with row1.

6901.37

5156099.230710

3

2

1

xxx

5.2001.67

55.206001.000710

3

2

1

xxx

Performing Forward Elimination

Page 74: Gaussian Elimination

Partial Pivoting: ExampleForward Elimination: Step 2

Examining the values of the first column

|-0.001| and |2.5| or 0.0001 and 2.5

The largest absolute value is 2.5, so row 2 is switched with row 3

5.2001.67

55.206001.000710

3

2

1

xxx

001.65.2

7

6001.0055.200710

3

2

1

xxx

Performing the row swap

Page 75: Gaussian Elimination

Partial Pivoting: ExampleForward Elimination: Step 2

Performing the Forward Elimination results in:

002.65.2

7

002.60055.200710

3

2

1

xxx

Page 76: Gaussian Elimination

Partial Pivoting: ExampleBack Substitution

Solving the equations through back substitution

1002.6002.6

3 x

15.255.2 3

2

xx

010

077 321

xxx

002.65.2

7

002.60055.200710

3

2

1

xxx

Page 77: Gaussian Elimination

Partial Pivoting: Example

11

0

3

2

1

xxx

X exact

11

0

3

2

1

xxx

X calculated

Compare the calculated and exact solution

The fact that they are equal is coincidence, but it does illustrate the advantage of Partial Pivoting

Page 78: Gaussian Elimination

THE END

Page 79: Gaussian Elimination

Determinant of a Square Matrix

Using Naïve Gauss EliminationExample

Page 80: Gaussian Elimination

Theorem of Determinants If a multiple of one row of [A]nxn is added or subtracted to another row of [A]nxn to result in [B]nxn then det(A)=det(B)

Page 81: Gaussian Elimination

Theorem of Determinants The determinant of an upper triangular matrix [A]nxn is given by

nnii aaaa ......Adet 2211

n

iiia

1

Page 82: Gaussian Elimination

Forward Elimination of a Square Matrix

Using forward elimination to transform [A]nxn

to an upper triangular matrix, [U]nxn. nnnn UA

UA detdet

Page 83: Gaussian Elimination

Example

11214418641525

Using naïve Gaussian elimination find the determinant of the following square matrix.

Page 84: Gaussian Elimination

Forward Elimination

Page 85: Gaussian Elimination

Forward Elimination: Step 1

.

56.28.126456.21525 56.18.40

56.2 8.12641 8 64

11214418641525

11214456.18.40

1525

Divide Equation 1 by 25 andmultiply it by 64, .

56.22564

Subtract the result from Equation 2

Substitute new equation for Equation 2

Page 86: Gaussian Elimination

Forward Elimination: Step 1 (cont.)

.

76.58.2814476.51525 76.48.16 0

76.5 8.281441 12 144

76.48.16056.18.40

1525

11214456.18.40

1525

Divide Equation 1 by 25 andmultiply it by 144, .

76.525

144

Subtract the result from Equation 3

Substitute new equation for Equation 3

Page 87: Gaussian Elimination

Forward Elimination: Step 2

.

76.48.16056.18.40

1525

46.58.1605.356.18.40

7.0 0 0

46.58.16076.48.160

7.00056.18.40

1525

Divide Equation 2 by −4.8and multiply it by −16.8, .

5.38.48.16

Subtract the result from Equation 3

Substitute new equation for Equation 3

Page 88: Gaussian Elimination

Finding the Determinant

.

7.00056.18.40

1525

11214418641525

After forward elimination

00.84

7.08.425Adet 332211

uuu

Page 89: Gaussian Elimination

Summary- Forward Elimination- Back Substitution- Pitfalls- Improvements- Partial Pivoting- Determinant of a Matrix

Page 90: Gaussian Elimination

THE END