12/17/2015 du 1 Simultaneous Linear Equations Topic: Gaussian Elimination

Preview:

Citation preview

04/21/23 http://numericalmethods.eng.usf.edu

1

Simultaneous Linear Equations

Topic: Gaussian Elimination

Gaussian Elimination

One of the most popular techniques for solving simultaneous linear equations of the form

Consists of 2 steps

1. Forward Elimination of Unknowns.

2. Back Substitution

CXA

Forward Elimination

The goal of Forward Elimination is to transform the coefficient matrix into an Upper Triangular Matrix

7.000

56.18.40

1525

112144

1864

1525

Forward Elimination

Linear Equations

A set of n equations and n unknowns

11313212111 ... bxaxaxaxa nn

22323222121 ... bxaxaxaxa nn

nnnnnnn bxaxaxaxa ...332211

. . . . . .

Forward Elimination

Transform to an Upper Triangular Matrix

Step 1: Eliminate x1 in 2nd equation using equation 1 as the pivot equation

)(1

2111

aa

Eqn

Which will yield

111

211

11

21212

11

21121 ... b

a

axa

a

axa

a

axa nn

Forward Elimination

Zeroing out the coefficient of x1 in the 2nd equation.

Subtract this equation from 2nd equation

111

2121

11

212212

11

2122 ... b

a

abxa

a

aaxa

a

aa nnn

'2

'22

'22 ... bxaxa nn

nnn aa

aaa

aa

aaa

111

212

'2

1211

2122

'22

Or Where

Forward Elimination

Repeat 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

. . . . . . . . .

Forward Elimination

Step 2: Eliminate x2 in the 3rd equation.

Equivalent to eliminating x1 in the 2nd equation using equation 2 as the pivot equation.

)(2

3 3222

aa

EqnEqn

Forward Elimination

This procedure is repeated for the remaining equations to reduce the set of equations as

11313212111 ... bxaxaxaxa nn '2

'23

'232

'22 ... bxaxaxa nn

"3

"33

"33 ... bxaxa nn

""3

"3 ... nnnnn bxaxa

. . . . . .

Forward Elimination

Continue this procedure by using the third equation as the pivot equation and so on.

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

'2

'23

'232

'22 ... bxaxaxa nn

"3

"3

"33 ... bxaxa nn

11 nnn

nnn bxa

. . . . . .

11313212111 ... bxaxaxaxa nn

Forward Elimination

At the end of the Forward Elimination steps

)-(nnn

3

2

1

nnn

n

n

n

b

b

b

b

x

x

x

x

a

aa

aaa

aaaa

1

"3

'2

1

)1(

"3

"33

'2

'23

'22

1131211

Back Substitution

The goal of Back Substitution is to solve each of the equations using the upper triangular matrix.

3

2

1

3

2

1

33

2322

131211

x

x

x

00

0

b

b

b

a

aa

aaa

Example of a system of 3 equations

Back Substitution

Start with the last equation because it has only one unknown

)1(

)1(

n

nn

nn

n a

bx

Solve the second from last equation (n-1)th using xn solved for previously.

This solves for xn-1.

Back Substitution

Representing Back Substitution for all equations by formula

1

1

11

iii

n

ijj

iij

ii

i a

xabx For i=n-1, n-2,….,1

and

)1(

)1(

n

nn

nn

n a

bx

Example: Rocket Velocity

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

Time, t Velocity, v

s m/s

5 106.8

8 177.2

12 279.2

The velocity data is approximated by a polynomial as:

12.t5 , 322

1 atatatv

Find: The Velocity at t=6,7.5,9, and 11 seconds.

Example: Rocket Velocity

Assume

12.t5 ,atatatv 322

1

3

2

1

323

222

121

1

1

1

v

v

v

a

a

a

tt

tt

tt

3

2

1

Results in a matrix template of the form:

Using date from the time / velocity table, the matrix becomes:

2.279

2.177

8.106

112144

1864

1525

3

2

1

a

a

a

Example: Rocket Velocity

Forward Elimination: Step 1

)64(

25

12

RowRow

Yields

2.279

21.96

81.106

a

a

a

112144

56.18.40

1525

3

2

1

Example: Rocket Velocity

)144(

25

13

RowRow

0.336

21.96

8.106

a

a

a

76.48.160

56.18.40

1525

3

2

1

Yields

Forward Elimination: Step 1

Example: Rocket Velocity

Yields

)8.16(8.4

23

RowRow

735.0

21.96

8.106

a

a

a

7.000

56.18.40

1525

3

2

1

This is now ready for Back Substitution

Forward Elimination: Step 2

Example: Rocket Velocity

Back Substitution: Solve for a3 using the third equation

735.07.0 3 a

70

7350

.

.a 3

0501. a 3

Example: Rocket Velocity

Back Substitution: Solve for a2 using the second equation

21.9656.18.4 32 aa

8.4

56.121.96 32

aa

84

05015612196

.-

...-a 2

7019.a 2

Example: Rocket Velocity

Back Substitution: Solve for a1 using the first equation

8.106525 321 aaa

25

58.106 32

1

aaa

25

050.170.1958.1061

a

2900.01 a

Example: Rocket Velocity

Solution:The solution vector is

050.1

70.19

2900.0

3

2

1

a

a

a

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

322

1 atatatv

125 ,050.170.192900.0 2 ttt

Example: Rocket Velocity

Solution:

Substitute each value of t to find the corresponding velocity

.s/m1.165

050.15.770.195.72900.05.7v 2

.s/m8.201

050.1970.1992900.09v 2

.s/m8.252

050.11170.19112900.011v 2

./ 69.129

050.1670.1962900.06 2

sm

v

Pitfalls

Two Potential Pitfalls-Division by zero: May occur in the forward elimination steps. Consider the set of equations:

655

901.33099.26

7710

321

321

32

xxx

xxx

xx

- Round-off error: Prone to round-off errors.

Pitfalls: Example

Consider the system of equations:

Use five significant figures with chopping

515

6099.23

0710

3

2

1

x

x

x

6

901.3

7

=

At the end of Forward Elimination

1500500

6001.00

0710

3

2

1

x

x

x

15004

001.6

7

=

Pitfalls: Example

Back Substitution

99993.015005

150043 x

5.1 001.0

6001.6 32

x

x

3500.010

077 321

xxx

15004

001.6

7

1500500

6001.00

0710

3

2

1

x

x

x

Pitfalls: Example

Compare the calculated values with the exact solution

99993.0

5.1

35.0

3

2

1

x

x

x

X calculated

1

1

0

3

2

1

x

x

x

X exact

Improvements

Increase the number of significant digits

Decreases round off error

Does not avoid division by zero

Gaussian Elimination with Partial Pivoting

Avoids division by zero

Reduces round off error

Partial Pivoting

pka

Gaussian Elimination with partial pivoting applies row switching to normal Gaussian Elimination.

How?

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 pth row, ,npk

then switch rows p and k.

Partial Pivoting

What does it Mean?

Gaussian Elimination with Partial Pivoting ensures that each step of Forward Elimination is performed with the pivoting element |akk| having the largest absolute value.

Partial Pivoting: Example

Consider the system of equations

6x5xx5

901.3x3x099.2x3

7x7x10

321

321

21

In matrix form

515

6099.23

0710

3

2

1

x

x

x

6

901.3

7

=

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

Partial Pivoting: Example

Forward 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.

6

901.3

7

515

6099.23

0710

3

2

1

x

x

x

5.2

001.6

7

55.20

6001.00

0710

3

2

1

x

x

x

Performing Forward Elimination

Partial Pivoting: Example

Forward 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.2

001.6

7

55.20

6001.00

0710

3

2

1

x

x

x

001.6

5.2

7

6001.00

55.20

0710

3

2

1

x

x

x

Performing the row swap

Partial Pivoting: Example

Forward Elimination: Step 2

Performing the Forward Elimination results in:

002.6

5.2

7

002.600

55.20

0710

3

2

1

x

x

x

Partial Pivoting: Example

Back Substitution

Solving the equations through back substitution

1002.6

002.63 x

15.2

55.2 22

xx

010

077 321

xxx

002.6

5.2

7

002.600

55.20

0710

3

2

1

x

x

x

Partial Pivoting: Example

1

1

0

3

2

1

x

x

x

X exact

1

1

0

3

2

1

x

x

x

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

Summary

-Forward Elimination

-Back Substitution

-Pitfalls

-Improvements

-Partial Pivoting

Recommended