jacobi and gauss-seidel iteration methods, use of software packages
TRANSCRIPT
-
7/29/2019 Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
1/29
Outlines
Jacobi and Gauss-Seidel Iteration Methods, Useof Software Packages
Mike Renfro
February 20, 2008
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software P
-
7/29/2019 Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
2/29
OutlinesPart I: Review of Previous LecturePart II: Jacobi and Gauss-Seidel Iteration Methods, Use of Softw
Review of Previous Lecture
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software P
-
7/29/2019 Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
3/29
OutlinesPart I: Review of Previous LecturePart II: Jacobi and Gauss-Seidel Iteration Methods, Use of Softw
Jacobi and Gauss-Seidel Iteration Methods, Use ofSoftware Packages
Jacobi Iteration MethodIntroduction
ExampleNotes on Convergence Criteria
Gauss-Seidel Iteration MethodIntroductionExample
Use of Software PackagesMATLABExcel
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software P
-
7/29/2019 Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
4/29
Part I
Review of Previous Lecture
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software P
-
7/29/2019 Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
5/29
Review of Previous Lecture
Cramers Rule
Gauss Elimination
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software P
J bi It ti M th d
-
7/29/2019 Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
6/29
Jacobi Iteration MethodGauss-Seidel Iteration Method
Use of Software Packages
Part II
Jacobi and Gauss-Seidel Iteration Method, Use ofSoftware Packages
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software P
Jacobi Iteration Method Introduction
-
7/29/2019 Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
7/29
Jacobi Iteration MethodGauss-Seidel Iteration Method
Use of Software Packages
IntroductionExampleNotes on Convergence Criteria
Jacobi Iteration Method: Introduction
Consider a system of equations in algebraic form
a11x1 + a12x2 + a13x3 + a14x4 + + a1nxn =b1
a21x1 + a22x2 + a23x3 + a24x4 + + a2n
xn
=b2a31x1 + a32x2 + a33x3 + a34x4 + + a3nxn =b3
a41x1 + a42x2 + a43x3 + a44x4 + + a4nxn =b4...
an1x1 + an2x2 + an3x3 + an4x4 + + annxn =bn
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software P
Jacobi Iteration Method Introduction
-
7/29/2019 Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
8/29
Jacobi Iteration MethodGauss-Seidel Iteration Method
Use of Software Packages
IntroductionExampleNotes on Convergence Criteria
Jacobi Iteration Method: Introduction
These n equations can be rewritten to isolate an unknown on oneside of each equation:
x1 =1
a11(b1 a12x2 a13x3 a14x4 a1nxn)
x2 =
1
a22 (b2 a21x1 a23x3 a24x4 a2nxn)
x3 =1
a33(b3 a31x1 a32x2 a34x4 a3nxn)
x4 =1
a44
(b4 a41x1 a42x2 a43x3 a4nxn)
...
xn =1
ann(bn an1x1 an2x2 an3x3 an,n1xn1)
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software P
Jacobi Iteration Method Introduction
-
7/29/2019 Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
9/29
Jacobi Iteration MethodGauss-Seidel Iteration Method
Use of Software Packages
IntroductionExampleNotes on Convergence Criteria
So Whats the Point?
It looks like all weve done at this point is some useless algebraicmanipulations. But if we substitute some assumed starting valuesfor x1, x2, , xn on the right hand side of each of the rewrittenequations, well get a new set of xi values on the left hand side. Ifwe repeat the process, substituting the just-calculated x valuesinto the right hand side of the equations, we should get closer and
closer to the actual values of x that solve the equations.
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software P
Jacobi Iteration Method Introduction
-
7/29/2019 Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
10/29
Jacobi Iteration MethodGauss-Seidel Iteration Method
Use of Software Packages
IntroductionExampleNotes on Convergence Criteria
Example
Example 3.19 (p.184) Solve the following system of equationsusing the Jacobi iteration method with an initial guess of xi = 0:
5x1 x2 + 2x3 =1
2x1 + 6x2 3x3 =2
2x1 + x2 + 7x3 =32
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software P
Jacobi Iteration Method Introduction
-
7/29/2019 Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
11/29
Jacobi Iteration MethodGauss-Seidel Iteration Method
Use of Software Packages
IntroductionExampleNotes on Convergence Criteria
Example
Step 1: reformat the equations, solving the first one for x1, thesecond for x2, and the third for x3:
x1 = 15
(1 + x2 2x3)
x2 =1
6(2 2x1 + 3x3)
x3 =
1
7 (32 2x1 x2)
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software P
Jacobi Iteration Method Introduction
-
7/29/2019 Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
12/29
Gauss-Seidel Iteration MethodUse of Software Packages
ExampleNotes on Convergence Criteria
Example
Step 2: Substitute the initial guesses for xi into the right-hand sideof the equations:
x1 = 1
5(1 + 0 2 (0))
x2 = 16
(2 2 (0) + 3 (0))
x3 =1
7(32 2(0) (0))
x(2)1 = 0.2000
x(2)2 =0.3333
x(2)3 =4.5714
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software P
Jacobi Iteration Method Introduction
-
7/29/2019 Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
13/29
Gauss-Seidel Iteration MethodUse of Software Packages
ExampleNotes on Convergence Criteria
Example
Step 3: Substitute the calculated values for for xi into theright-hand side of the equations:
x1 = 1
5(1 + 0.3333 2 (4.5714))
x2 = 16
(2 2 (0.2000) + 3 (4.5714))
x3 =1
7(32 2 (0.2000) (0.3333))
x(3)1 =1.5619
x(3)2 =2.6857
x(3)3 =4.5810
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software P
Jacobi Iteration Method Introduction
-
7/29/2019 Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
14/29
Gauss-Seidel Iteration MethodUse of Software Packages
ExampleNotes on Convergence Criteria
Example
Step 4, 5, : Continue substituting xi values into the right-handside of the equations and watch for them to converge to finalvalues:
Iteration number x1 x2 x31 0.0000 0.0000 0.00002 -0.2000 0.3333 4.57143 1.5619 2.6857 4.58104 1.0952 2.1032 3.74155 0.8760 1.8390 3.9580
6 1.0154 2.0204 4.05847 1.0193 2.0241 3.99278 0.9923 1.9899 3.99109 0.9984 1.9981 4.0037
10 1.0018 2.0023 4.0007
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software P
Jacobi Iteration MethodG S id l I i M h d
IntroductionE l
-
7/29/2019 Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
15/29
Gauss-Seidel Iteration MethodUse of Software Packages
ExampleNotes on Convergence Criteria
Notes on Convergence Criteria
Like many of the iterative root-finding methods in Chapter 2, theJacobi iteration method is not guaranteed to converge on the exactanswer in every possible case and every possible initial guess.
However, if the equations in the system are diagonally dominant,then the Jacobi iteration method is guaranteed to convergeregardless of the starting guess for x.Diagonal dominance is defined as the condition where the
coefficient along the diagonal on any row is larger in absolute valuethan the sum of the absolute values of the other coefficients on thesame row.
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software P
Jacobi Iteration MethodG S id l It ti M th d
IntroductionE l
-
7/29/2019 Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
16/29
Gauss-Seidel Iteration MethodUse of Software Packages
ExampleNotes on Convergence Criteria
Is Example 3.19 Diagonally Dominant?
5x1 x2 + 2x3 =1
2x1 + 6x2 3x3 =2
2x1 + x2 + 7x3 =32
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software P
Jacobi Iteration MethodGauss Seidel Iteration Method
IntroductionExample
-
7/29/2019 Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
17/29
Gauss-Seidel Iteration MethodUse of Software Packages
ExampleNotes on Convergence Criteria
Is Example 3.19 Diagonally Dominant?
5 1 22 6 32 1 7
x1x2x3
=
12
32
| 5| > | 1| + |2|
|6| > |2| + | 3|
|7| > |2| + |1|
Yes, this system of equations is diagonally dominant. We willconverge to the exact solution regardless of the values of xi westart with.
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software P
Jacobi Iteration MethodGauss Seidel Iteration Method
Introduction
-
7/29/2019 Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
18/29
Gauss-Seidel Iteration MethodUse of Software Packages
Example
Gauss-Seidel Iteration: Introduction
Gauss-Seidel iteration is similar to Jacobi iteration, except thatnew values for xi are used on the right-hand side of the equationsas soon as they become available. It improves upon the Jacobimethod in two respects:
Convergence is quicker, since you benefit from the newer,more accurate xi values earlier.
Memory requirements are reduced by 50%, since you onlyneed to keep track of one set of xi values, not two sets.
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software P
Jacobi Iteration MethodGauss-Seidel Iteration Method
Introduction
-
7/29/2019 Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
19/29
Gauss-Seidel Iteration MethodUse of Software Packages
Example
Example
Example 3.20 (p.186) Solve the following system of equationsusing the Gauss-Seidel iteration method with an initial guess of
xi = 0:
5x1 x2 + 2x3 =1
2x1 + 6x2 3x3 =2
2x1 + x2 + 7x3 =32
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software P
Jacobi Iteration MethodGauss-Seidel Iteration Method
IntroductionE l
-
7/29/2019 Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
20/29
Gauss Seidel Iteration MethodUse of Software Packages
Example
Example
Step 1: reformat the equations, solving the first one for x1, thesecond for x2, and the third for x3:
x1 = 15
(1 + x2 2x3)
x2 =1
6(2 2x1 + 3x3)
x3 =
1
7 (32 2x1 x2)
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software P
Jacobi Iteration MethodGauss-Seidel Iteration Method
IntroductionE l
-
7/29/2019 Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
21/29
Use of Software PackagesExample
Example
Step 2a: Substitute the initial guesses for xi into the right-handside of the first equation:
x(2)1 =
1
5(1 + 0 2(0)) = 0.2000
Step 2b: Substitute the new x1 value with the initial guess for x3into the second equation:
x(2)2 =
1
6(2 2 (0.2000) + 3 (0)) = 0.4000
Step 2c: Substitute the new x1 and x2 values into the thirdequation:
x(2)3 =
1
7(32 2 (0.2000) (0.4000)) = 4.5714
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software P
Jacobi Iteration MethodGauss-Seidel Iteration Method
IntroductionExample
-
7/29/2019 Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
22/29
Use of Software PackagesExample
Example
Step 3, 4, : Repeat step 2 and watch for the xi values toconverge to an exact solution.
Iteration number x1 x2 x3
1 0.0000 0.0000 0.00002 -0.2000 0.4000 4.57143 1.5486 2.1029 3.82864 0.9109 1.9440 4.03355 1.0246 2.0085 3.9918
6 0.9950 1.9975 4.00187 1.0012 2.0005 3.99968 0.9997 1.9999 4.0001
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software P
Jacobi Iteration MethodGauss-Seidel Iteration Method
MATLABExcel
-
7/29/2019 Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
23/29
Use of Software PackagesExcel
Example 3.27
Find the solution to the following system of equations:
4 1 1 01 4 0 11 0 4 10 1 1 4
x1x2x3x4
=
200400
0200
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software P
Jacobi Iteration MethodGauss-Seidel Iteration Method
MATLABExcel
-
7/29/2019 Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
24/29
Use of Software PackagesExcel
MATLAB Setup
>> A =[ -4 1 1 -0; 1 -4 0 1; 1 0 -4 1; 0 1 1 -4]
A =
-4 1 1 0
1 -4 0 1
1 0 -4 1
0 1 1 -4
> > b = [ -2 00; -400; 0; -200]
b =
-200
-4000
-200
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software P
Jacobi Iteration MethodGauss-Seidel Iteration Method
U f S f P k
MATLABExcel
-
7/29/2019 Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
25/29
Use of Software PackagesExcel
2 MATLAB Solutions
> > x = in v (A )* b
x =
1 0 0 . 0 0 0 0
1 5 0 . 0 0 0 0
5 0 . 0 0 0 01 0 0 . 0 0 0 0
> > x =A \b
x =
1 0 0 . 0 0 0 0
1 5 0 . 0 0 0 05 0 . 0 0 0 0
1 0 0 . 0 0 0 0
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software P
Jacobi Iteration MethodGauss-Seidel Iteration Method
U f S ft P k
MATLABExcel
-
7/29/2019 Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
26/29
Use of Software Packages
Example 3.29 (Corrected)
Use MATLAB to find the inverse of the matrix [A] given by
[A] =
1 1213
1n
1
2
1
3
1
4 1
n+113
14
15
1n+2
......
......
1n
1n+1
1n+2
12n1
, n = 50
and find the error in the inverse matrix by calculating[C] = [A][A]1 and summing up the absolute values of the matrixelements. If there was no error at all, the sum would be n.
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software P
Jacobi Iteration MethodGauss-Seidel Iteration Method
Use of Software Packages
MATLABExcel
-
7/29/2019 Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
27/29
Use of Software Packages
MATLAB Solution 1
> > A = h i lb ( 50 );
> > r es u lt = i nv ( A ) * A ;
W ar ni ng : M at ri x is c lo se to s in gu la r or b ad ly s ca le d .R es ul ts m ay be i na cc ur at e . R CO ND = 1 .6 03 36 6 e - 02 0.
> > e rr = s u m ( a bs ( r e su lt ( :) ))
err =
7 . 3 8 8 6 e + 0 1 1
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software P
Jacobi Iteration MethodGauss-Seidel Iteration Method
Use of Software Packages
MATLABExcel
-
7/29/2019 Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
28/29
Use of Software Packages
MATLAB Solution 2
> > A = h i lb ( 50 );
> > r es u lt = A \ A ;
W ar ni ng : M at ri x is c lo se to s in gu la r or b ad ly s ca le d .
R es ul ts m ay be i na cc ur at e . R CO ND = 1 .6 03 36 6 e - 02 0.> > e rr = s u m ( a bs ( r e su lt ( :) ))
err =
1 9 2 . 9 8 5 6
>>
The error on this version is much, much lower. This is why wedont use the inv() function on ill-conditioned matrices.
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software P
Jacobi Iteration MethodGauss-Seidel Iteration Method
Use of Software Packages
MATLABExcel
-
7/29/2019 Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
29/29
Use of Software Packages
Excel
Microsoft Excel can also do matrix inversion, but its a bitcumbersome. However, if its the only tool you have at somepoint, its better than nothing. See the the matrix inversion.xlsfile located with the lecture slides on the web.
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software P