Algorithm for Gauss elimination 1) first eliminate for each eq. j, j=1 to n-1

23
Algorithm for Gauss elimination 1) first eliminate for each eq. j, j=1 to n-1 for all eq.s k greater than j a) multiply eq. j by a kj /a jj b) subtract the result from eq. K This leads to upper triangular

description

Algorithm for Gauss elimination 1) first eliminate for each eq. j, j=1 to n-1 for all eq.s k greater than j a) multiply eq. j by a kj /a jj b) subtract the result from eq. K This leads to upper triangular. 2) now backsubstitute a) determine x n from b) put x n into n-1 eq. - PowerPoint PPT Presentation

Transcript of Algorithm for Gauss elimination 1) first eliminate for each eq. j, j=1 to n-1

Page 1: Algorithm for Gauss elimination 1) first eliminate for each eq. j, j=1 to n-1

Algorithm for Gauss elimination

1) first eliminate

for each eq. j, j=1 to n-1

for all eq.s k greater than j

a) multiply eq. j by akj/ajj

b) subtract the result from eq. K

This leads to upper triangular

Page 2: Algorithm for Gauss elimination 1) first eliminate for each eq. j, j=1 to n-1

2) now backsubstitute

a) determine xn from

b) put xn into n-1 eq.

c) solve for xn-1

d) repeat from b), moving back to n-2, n-3, etc. until all equations are solved

n

n

nn

n a

bx

1

1

Page 3: Algorithm for Gauss elimination 1) first eliminate for each eq. j, j=1 to n-1

Matlab code

Page 4: Algorithm for Gauss elimination 1) first eliminate for each eq. j, j=1 to n-1

Operation counting

Important as matrix gets large

For Gauss elimination

• elimination routine uses on the order ofoperations

• backsubstitution uses

3

3n

2

2nO

Page 5: Algorithm for Gauss elimination 1) first eliminate for each eq. j, j=1 to n-1

Problems with Gauss elimination (as done last time)

1) division by zero

2) round off errors

3) ill conditioned systems

Page 6: Algorithm for Gauss elimination 1) first eliminate for each eq. j, j=1 to n-1

Division by zero

1522

457

523

321

321

32

xxx

xxx

xx

Using first eq. to eliminate x1 in second eq. means dividing by 0

1522

42*0

153*

0

170*

0

11

523

321

321

32

xxx

xxx

xx

Page 7: Algorithm for Gauss elimination 1) first eliminate for each eq. j, j=1 to n-1

Pivoting developed to avoid this

find row with largest absolute value under pivot element

switch rows

More later

Page 8: Algorithm for Gauss elimination 1) first eliminate for each eq. j, j=1 to n-1

Round off errors

With more than n3/3 operations, get a lot of chopping.

More important - error is propagted

More than 100 equations - round can be very important - system dependent

Page 9: Algorithm for Gauss elimination 1) first eliminate for each eq. j, j=1 to n-1

Ill conditioned systems - small changes in coefficients lead to large changes in solution

Round-off errors especially important in ill-conditioned systems

Page 10: Algorithm for Gauss elimination 1) first eliminate for each eq. j, j=1 to n-1

Recall ill conditioned system from graphical methods

7.07.1

15.15.2

21

21

xx

xx

-2

-1

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6

x1

x2

2222121

1212111

bxaxa

bxaxa

Page 11: Algorithm for Gauss elimination 1) first eliminate for each eq. j, j=1 to n-1

Can write as

22

21

22

212

12

11

12

112

a

bx

a

ax

a

bx

a

ax

Since slopes are almost equal

22

21

12

11

a

a

a

a

Page 12: Algorithm for Gauss elimination 1) first eliminate for each eq. j, j=1 to n-1

22

21

12

11

a

a

a

a

21122211 aaaa becomes

021122211 aaaa

0det2221

1211

aa

aa

05.055.25.217.1

5.15.2det

Page 13: Algorithm for Gauss elimination 1) first eliminate for each eq. j, j=1 to n-1

Determinant close to zero indicates ill-conditioned set of equations.

How close?

No clear answer

Problem of scale

Page 14: Algorithm for Gauss elimination 1) first eliminate for each eq. j, j=1 to n-1

Multiply our set of equations by 100

70100170

100150250

21

21

xx

xx

500500,25000,25100170

150250det

Page 15: Algorithm for Gauss elimination 1) first eliminate for each eq. j, j=1 to n-1

-2

-1

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6

x1

x2

However, graphically

No change

Page 16: Algorithm for Gauss elimination 1) first eliminate for each eq. j, j=1 to n-1

Scaling

Make maximum element in any row =1

4118.05882.0

4.06.0

21

21

xx

xx70100170

100150250

21

21

xx

xx

0118.05882.01

6.01det

Page 17: Algorithm for Gauss elimination 1) first eliminate for each eq. j, j=1 to n-1

Another problem - singular systems

Two equations in the set are the same

Determinant is 0.

Page 18: Algorithm for Gauss elimination 1) first eliminate for each eq. j, j=1 to n-1

Calculating determinant using Gauss elimination

Given

nn

n

n

n

n

a

aa

aaa

aaaa

A

1

333

22322

1131211

''''

'''

nn

naaaaA 1332211 '''det

then

Page 19: Algorithm for Gauss elimination 1) first eliminate for each eq. j, j=1 to n-1

How to avoid pitfalls

•higher precision

•pivoting

•scaling

Page 20: Algorithm for Gauss elimination 1) first eliminate for each eq. j, j=1 to n-1

Partial Pivoting

Determine the largest coefficient in the column below pivot element

Then switch rows

(Compete pivot switches columns also, but is rarely used.)

Page 21: Algorithm for Gauss elimination 1) first eliminate for each eq. j, j=1 to n-1

Example:

4

11

3

7

653

3210

451

1273

Exchange rows 2 and 3

4

3

11

7

653

451

3210

1273

And now eliminate

Page 22: Algorithm for Gauss elimination 1) first eliminate for each eq. j, j=1 to n-1

Algorithm for Gauss elimination using improvements

1) first eliminate

for each eq. j, j=1 to n-1

first scale each equation k greater than jthen pivotnow

a) multiply eq. j by akj/ajj

b) subtract the result from eq. k

Page 23: Algorithm for Gauss elimination 1) first eliminate for each eq. j, j=1 to n-1

The Gauss Jordan method

Major difference - eliminate unknowns from all rows, not just subsequent ones

Normalize matrix so all entries are 1

Leads to identity matrix instead of upper triangular

Backsubstitution is easy

3

2

1

3

2

1

'

'

'

1

1

1

b

b

b

x

x

x