Upload
others
View
20
Download
0
Embed Size (px)
Citation preview
Outlines
Cramer’s Rule and Gauss Elimination
Mike Renfro
September 28, 2004
Mike Renfro Cramer’s Rule and Gauss Elimination
OutlinesPart I: Review of Previous LecturePart II: Cramer’s Rule and Gauss Elimination
Review of Previous Lecture
Mike Renfro Cramer’s Rule and Gauss Elimination
OutlinesPart I: Review of Previous LecturePart II: Cramer’s Rule and Gauss Elimination
Cramer’s Rule and Gauss Elimination
Cramer’s RuleIntroductionExampleAdvantages and Disadvantages
Gauss EliminationIntroduction and RulesExampleMatrix Version and ExampleAdvantages and Disadvantages
Homework
Mike Renfro Cramer’s Rule and Gauss Elimination
Part I
Review of Previous Lecture
Mike Renfro Cramer’s Rule and Gauss Elimination
Review of Previous Lecture
Graphical interpretation
Solvable and unsolvable problems
Linear dependence and independence
Ill-conditioning
Mike Renfro Cramer’s Rule and Gauss Elimination
Cramer’s RuleGauss Elimination
Homework
Part II
Cramer’s Rule and Gauss Elimination
Mike Renfro Cramer’s Rule and Gauss Elimination
Cramer’s RuleGauss Elimination
Homework
IntroductionExampleAdvantages and Disadvantages
Cramer’s Rule (1750)
A linear system of equations can be solved by using Cramer’s rule,which for a system of 2 equations[
a11 a12
a21 a22
]{x1
x2
}=
{b1
b2
}yields
x1 =|[A1]||[A]|
, x2 =|[A2]||[A]|
where
A1 =
[b1 a12
b2 a22
]A2 =
[a11 b1
a21 b2
]
Mike Renfro Cramer’s Rule and Gauss Elimination
Cramer’s RuleGauss Elimination
Homework
IntroductionExampleAdvantages and Disadvantages
Cramer’s Rule Details
For a system of n equations, Cramer’s rule requires that youcalculate n + 1 determinants of n × n matrices.
In the general case for a system of equations [A]{x} = {b},the matrix [Ai ] is obtained by replacing the ith column of theoriginal [A] matrix with the contents of the {b} vector.
Each unknown variable xi is found by dividing the determinant|[Ai ]| by the determinant of the original coefficient matrix|[A]|.
Mike Renfro Cramer’s Rule and Gauss Elimination
Cramer’s RuleGauss Elimination
Homework
IntroductionExampleAdvantages and Disadvantages
Cramer’s Rule Example
Solve the following system of equations using Cramer’s rule:
x1 − x2 + x3 = 3
2x1 + x2 − x3 = 0
3x1 + 2x2 + 2x3 = 15
Convert the system of equations into matrix form: 1 −1 12 1 −13 2 2
x1
x2
x3
=
30
15
Mike Renfro Cramer’s Rule and Gauss Elimination
Cramer’s RuleGauss Elimination
Homework
IntroductionExampleAdvantages and Disadvantages
Cramer’s Rule Example (continued)
[A] =
1 −1 12 1 −13 2 2
, {x} =
x1
x2
x3
, {b} =
30
15
Define matrices [A1], [A2], and [A3] as
[A1] =
3 −1 10 1 −1
15 2 2
, [A2] =
1 3 12 0 −13 15 2
,
[A3] =
1 −1 32 1 03 2 15
Mike Renfro Cramer’s Rule and Gauss Elimination
Cramer’s RuleGauss Elimination
Homework
IntroductionExampleAdvantages and Disadvantages
Cramer’s Rule Example (continued)
Calculate determinants of [A], [A1], [A2], and [A3]:
|[A]| = 12
|[A1]| = 12
|[A2]| = 24
|[A3]| = 48
Unknowns x1, x2, and x3 are then calculated as
x1 =|[A1]||[A]|
=12
12= 1, x2 =
|[A2]||[A]|
=24
12= 2, x3 =
|[A3]||[A]|
=48
12= 4
Mike Renfro Cramer’s Rule and Gauss Elimination
Cramer’s RuleGauss Elimination
Homework
IntroductionExampleAdvantages and Disadvantages
Cramer’s Rule Example (continued)
Be sure to double-check your answers by substituting them intothe original equations:
x1 − x2 + x3 = 1 − 2 + 4 = 3
2x1 + x2 − x3 = 2 + 2 − 4 = 0
3x1 + 2x2 + 2x3 = 3 + 4 + 8 = 15
Mike Renfro Cramer’s Rule and Gauss Elimination
Cramer’s RuleGauss Elimination
Homework
IntroductionExampleAdvantages and Disadvantages
Cramer’s Rule Advantages/Disadvantages
Advantages
Easy to remember steps
Disadvantages
Computationally intensive compared to other methods: themost efficient ways of calculating the determinant of an n × nmatrix require (n − 1)(n!) operations. So Cramer’s rule wouldrequire (n − 1)((n + 1)!) total operations. For 8 equations,that works out to 7(9!) = 2540160 operations, or around 700hours if you can perform one operation per second.
Roundoff error may become significant on large problems withnon-integer coefficients.
Mike Renfro Cramer’s Rule and Gauss Elimination
Cramer’s RuleGauss Elimination
Homework
Introduction and RulesExampleMatrix Version and ExampleAdvantages and Disadvantages
Gauss Elimination
Recall the scaffolding problem from the beginning of Chapter 3. Itsmatrix form was
1 1 −1 −1 0 −10 −9 1 4 0 70 0 1 1 −1 00 0 0 −3 2 00 0 0 0 1 10 0 0 0 0 −4
TA
TB
TC
TD
TE
TF
=
P1
−5P1
P2
−P2
P3
−P3
Notice that its coefficient matrix contains nothing but zeroesbelow the diagonal. This is an example of an upper triangularmatrix, and these systems of equations are very easy to solve.
Mike Renfro Cramer’s Rule and Gauss Elimination
Cramer’s RuleGauss Elimination
Homework
Introduction and RulesExampleMatrix Version and ExampleAdvantages and Disadvantages
Gauss Elimination Introduction (continued)
The original system of equations on the scaffolding problem was
TA +TB −TC −TD −TF = P1
−9TB +TC +4TD +7TF = −5P1
TC +TD −TE = P2
−3TD +2TE = −P2
TE +TF = P3
−4TF = −P3
.
Notice that we can solve for TF using only the sixth equation inthe system. That is, TF = P3
4 . After solving for TF , we can solvefor TE using only the fifth equation. The pattern continues,back-substituting through the system of equations until finally wesolve for TA using the first equation.
Mike Renfro Cramer’s Rule and Gauss Elimination
Cramer’s RuleGauss Elimination
Homework
Introduction and RulesExampleMatrix Version and ExampleAdvantages and Disadvantages
Gauss Elimination Introduction (continued)
The goal of Gauss elimination is to convert any given system ofequations into an equivalent upper triangular form. Onceconverted, we can back-substitute through the equations, solvingfor the unknowns algebraically.
Mike Renfro Cramer’s Rule and Gauss Elimination
Cramer’s RuleGauss Elimination
Homework
Introduction and RulesExampleMatrix Version and ExampleAdvantages and Disadvantages
Gauss Elimination Rules
The operations used in converting a system of equations to uppertriangular form are known as elementary operations and are:
Any equation may be multiplied by a nonzero scalar.
Any equation may be added to (or subtracted from) anotherequation.
The positions of any two equations in the system may beswapped.
Mike Renfro Cramer’s Rule and Gauss Elimination
Cramer’s RuleGauss Elimination
Homework
Introduction and RulesExampleMatrix Version and ExampleAdvantages and Disadvantages
Gauss Elimination Example
2x1 − x2 + x3 = 4 (1)
4x1 + 3x2 − x3 = 6 (2)
3x1 + 2x2 + 2x3 = 15 (3)
To eliminate the 4x1 term in Equation 2, multiply Equation 1 by 2and subtract it from Equation 2. To eliminate the 3x1 term inEquation 3, multiply Equation 1 by 3
2 and subtract it fromEquation 3. This gives a system of equations
2x1 − x2 + x3 = 4 (4)
5x2 − 3x3 = −2 (5)
7
2x2 +
1
2x3 = 9 (6)
Mike Renfro Cramer’s Rule and Gauss Elimination
Cramer’s RuleGauss Elimination
Homework
Introduction and RulesExampleMatrix Version and ExampleAdvantages and Disadvantages
Gauss Elimination Example (continued)
To eliminate the 72x2 term from Equation 6, multiply Equation 5
by 710 and subtract it from Equation 6. This gives a system of
equations
2x1 − x2 + x3 = 4 (7)
5x2 − 3x3 = −2 (8)
13
5x3 =
52
5(9)
Mike Renfro Cramer’s Rule and Gauss Elimination
Cramer’s RuleGauss Elimination
Homework
Introduction and RulesExampleMatrix Version and ExampleAdvantages and Disadvantages
Gauss Elimination Example (continued)
Equation 9 can easily be solved for x3.
x3 =52
5
(5
13
)= 4
Equation 8 can easily be solved for x2, once x3 is known.
x2 =1
5(−2 + 3x3) =
1
5(−2 + 3(4)) = 2
Equation 7 can easily be solved for x1, once both x2 and x3 areknown.
x1 =1
2(4 + x2 − x3) =
1
2(4 + 2 − 4) = 1
Mike Renfro Cramer’s Rule and Gauss Elimination
Cramer’s RuleGauss Elimination
Homework
Introduction and RulesExampleMatrix Version and ExampleAdvantages and Disadvantages
Matrix Version of Gauss Elimination
The Gauss elimination method can be applied to a system ofequations in matrix form. Instead of eliminating terms fromequations, we’ll be replacing certain elements of the coefficientmatrix with zeroes.
Mike Renfro Cramer’s Rule and Gauss Elimination
Cramer’s RuleGauss Elimination
Homework
Introduction and RulesExampleMatrix Version and ExampleAdvantages and Disadvantages
Matrix Version (Step 0)
Start by defining the augmented matrix [C (0)] for the problem:
[C (0)] =
a(0)11 a
(0)12 · · · a
(0)1n a
(0)1,n+1
a(0)21 a
(0)22 · · · a
(0)2n a
(0)2,n+1
......
......
...
a(0)n1 a
(0)n2 · · · a
(0)nn a
(0)n,n+1
where the first n columns are the elements of the original [A]matrix, and the last column is the elements of the original {b}matrix.
Mike Renfro Cramer’s Rule and Gauss Elimination
Cramer’s RuleGauss Elimination
Homework
Introduction and RulesExampleMatrix Version and ExampleAdvantages and Disadvantages
Matrix Version (Step 1)
Zero out the first column of the [C ] matrix, rows 2 · · · n. To turna21 to a zero, multiply row 1 by a21
a11, then subtract the numbers on
row 1 from row 2. To turn a31 to a zero, multiply row 1 by a31a11
,then subtract the numbers on row 1 from row 3. Repeat for rows4 · · · n.
[C (1)] =
a(0)11 a
(0)12 · · · a
(0)1n a
(0)1,n+1
0 a(1)22 · · · a
(1)2n a
(1)2,n+1
......
......
...
0 a(1)n2 · · · a
(1)nn a
(1)n,n+1
Mike Renfro Cramer’s Rule and Gauss Elimination
Cramer’s RuleGauss Elimination
Homework
Introduction and RulesExampleMatrix Version and ExampleAdvantages and Disadvantages
Matrix Version (Step 2)
Zero out the second column of the [C ] matrix, rows 3 · · · n. Toturn a32 to a zero, multiply row 2 by a32
a22, then subtract the
numbers on row 2 from row 3. To turn a42 to a zero, multiply row2 by a42
a22, then subtract the numbers on row 2 from row 4. Repeat
for rows 5 · · · n.
[C (1)] =
a(0)11 a
(0)12 a
(0)13 · · · a
(0)1n a
(0)1,n+1
0 a(1)22 a
(1)13 · · · a
(1)2n a
(1)2,n+1
0 0 a(2)33 · · · a
(2)3n a
(2)3,n+1
......
......
......
0 0 a(2)n3 · · · a
(2)nn a
(2)n,n+1
Mike Renfro Cramer’s Rule and Gauss Elimination
Cramer’s RuleGauss Elimination
Homework
Introduction and RulesExampleMatrix Version and ExampleAdvantages and Disadvantages
Matrix Version (Step n-1)
Zero out the (n − 1)th column of the [C ] matrix, row n. To turnan,n−1 to a zero, multiply row n − 1 by
an,n−1
an−1,n−1, then subtract the
numbers on row n − 1 from row n.
[C (1)] =
a(0)11 a
(0)12 a
(0)13 · · · a
(0)1n a
(0)1,n+1
0 a(1)22 a
(1)13 · · · a
(1)2n a
(1)2,n+1
0 0 a(2)33 · · · a
(2)3n a
(2)3,n+1
......
......
......
0 0 0 · · · a(n−1)nn a
(n−1)n,n+1
Mike Renfro Cramer’s Rule and Gauss Elimination
Cramer’s RuleGauss Elimination
Homework
Introduction and RulesExampleMatrix Version and ExampleAdvantages and Disadvantages
Example
Solve the following system of equations with Gauss elimination: 2 −1 14 3 −13 2 2
x1
x2
x3
=
46
15
First, set up the augmented matrix [C (0)]:
[C (0)] =
2 −1 1 44 3 −1 63 2 2 15
Mike Renfro Cramer’s Rule and Gauss Elimination
Cramer’s RuleGauss Elimination
Homework
Introduction and RulesExampleMatrix Version and ExampleAdvantages and Disadvantages
Example (continued)
Step 1a: eliminate the 4 on row 2, column 1. Multiply all theelements of row 1 by a21
a11= 4
2 = 2, then subtract them from theelements of row 2.
[C ] =
2 −1 1 44 − (2)(2) 3 − (2)(−1) −1 − (2)(1) 6 − (2)(4)
3 2 2 15
=
2 −1 1 40 5 −3 −23 2 2 15
Mike Renfro Cramer’s Rule and Gauss Elimination
Cramer’s RuleGauss Elimination
Homework
Introduction and RulesExampleMatrix Version and ExampleAdvantages and Disadvantages
Example (continued)
Step 1b: eliminate the 3 on row 3, column 1. Multiply all theelements of row 1 by a31
a11= 3
2 = 1.5, then subtract them from theelements of row 3.
[C (1)] =
2 −1 1 40 5 −3 −2
3 − (1.5)(2) 2 − (1.5)(−1) 2 − (1.5)(1) 15 − (1.5)(4)
=
2 −1 1 40 5 −3 −20 3.5 0.5 9
This completes the first elimination step.
Mike Renfro Cramer’s Rule and Gauss Elimination
Cramer’s RuleGauss Elimination
Homework
Introduction and RulesExampleMatrix Version and ExampleAdvantages and Disadvantages
Example (continued)
Step 2: eliminate the 3.5 on row 3, column 2. Multiply all theelements of row 2 by a32
a22= 3.5
5 = 0.7, then subtract them from theelements of row 3.
[C (2)] =
2 −1 1 40 5 −3 −20 3.5 − (0.7)(5) 0.5 − (0.7)(−3) 9 − (0.7)(−2)
=
2 −1 1 40 5 −3 −20 0 2.6 10.4
This completes the second elimination step.
Mike Renfro Cramer’s Rule and Gauss Elimination
Cramer’s RuleGauss Elimination
Homework
Introduction and RulesExampleMatrix Version and ExampleAdvantages and Disadvantages
Example (continued)
We’ve now converted the original system of equations 2 −1 14 3 −13 2 2
x1
x2
x3
=
46
15
into an equivalent upper-triangular system of equations 2 −1 1
0 5 −30 0 2.6
x1
x2
x3
=
4
−210.4
Mike Renfro Cramer’s Rule and Gauss Elimination
Cramer’s RuleGauss Elimination
Homework
Introduction and RulesExampleMatrix Version and ExampleAdvantages and Disadvantages
Example (continued)
The new system of equations can be converted back to algebraicform as:
2x1 − x2 + x3 = 4 (10)
5x2 − 3x3 = −2 (11)
2.6x3 = 10.4 (12)
Solve Equation 12 for x3: x3 = 10.42.6 = 4. Then solve Equation 11
for x2: x2 = 15(−2 + 3x3) = 2. Then solve Equation 10 for x1:
x1 = 12(4 + x2 − x3) = 1.
Mike Renfro Cramer’s Rule and Gauss Elimination
Cramer’s RuleGauss Elimination
Homework
Introduction and RulesExampleMatrix Version and ExampleAdvantages and Disadvantages
Example (continued)
Double-check the solution by substituting the values of x1, x2, andx3 into the original equations:
2x1 − x2 + x3 = 2(1) − 2 + 4 = 4
4x1 − 3x2 − x3 = 4(1) + 3(2) − 4 = 6
3x1 + 2x2 + 2x3 = 3(1) + 2(2) + 2(4) = 15
Mike Renfro Cramer’s Rule and Gauss Elimination
Cramer’s RuleGauss Elimination
Homework
Introduction and RulesExampleMatrix Version and ExampleAdvantages and Disadvantages
Gauss Elimination Advantages/Disadvantages
Advantages
Much less computation required for larger problems. Gausselimination requires n3
3 multiplications to solve a system of nequations. For 8 equations, this works out to around 170operations, versus the roughly 2.5 million operations forCramer’s rule.
Disadvantages
Not quite as easy to remember the procedure for handsolutions.
Roundoff error may become significant, but can be partiallymitigated by using more advanced techniques such as pivotingor scaling.
Mike Renfro Cramer’s Rule and Gauss Elimination
Cramer’s RuleGauss Elimination
Homework
Homework
Solve Problem 3.4 using: Cramer’s rule, Gauss elimination,and MATLAB’s \ operator. Double-check your answers bysubstituting them back into the original equations.
Mike Renfro Cramer’s Rule and Gauss Elimination