Sunteți pe pagina 1din 29

Outlines

Jacobi and Gauss-Seidel Iteration Methods, Use


of Software Packages
Mike Renfro
February 20, 2008
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
Outlines
Part I: Review of Previous Lecture
Part II: Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
Review of Previous Lecture
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
Outlines
Part I: Review of Previous Lecture
Part II: Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
Jacobi and Gauss-Seidel Iteration Methods, Use of
Software Packages
Jacobi Iteration Method
Introduction
Example
Notes on Convergence Criteria
Gauss-Seidel Iteration Method
Introduction
Example
Use of Software Packages
MATLAB
Excel
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
Part I
Review of Previous Lecture
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
Review of Previous Lecture
Cramers Rule
Gauss Elimination
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
Jacobi Iteration Method
Gauss-Seidel Iteration Method
Use of Software Packages
Part II
Jacobi and Gauss-Seidel Iteration Method, Use of
Software Packages
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
Jacobi Iteration Method
Gauss-Seidel Iteration Method
Use of Software Packages
Introduction
Example
Notes on Convergence Criteria
Jacobi Iteration Method: Introduction
Consider a system of equations in algebraic form
a
11
x
1
+ a
12
x
2
+ a
13
x
3
+ a
14
x
4
+ + a
1n
x
n
=b
1
a
21
x
1
+ a
22
x
2
+ a
23
x
3
+ a
24
x
4
+ + a
2n
x
n
=b
2
a
31
x
1
+ a
32
x
2
+ a
33
x
3
+ a
34
x
4
+ + a
3n
x
n
=b
3
a
41
x
1
+ a
42
x
2
+ a
43
x
3
+ a
44
x
4
+ + a
4n
x
n
=b
4
.
.
.
a
n1
x
1
+ a
n2
x
2
+ a
n3
x
3
+ a
n4
x
4
+ + a
nn
x
n
=b
n
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
Jacobi Iteration Method
Gauss-Seidel Iteration Method
Use of Software Packages
Introduction
Example
Notes on Convergence Criteria
Jacobi Iteration Method: Introduction
These n equations can be rewritten to isolate an unknown on one
side of each equation:
x
1
=
1
a
11
(b
1
a
12
x
2
a
13
x
3
a
14
x
4
a
1n
x
n
)
x
2
=
1
a
22
(b
2
a
21
x
1
a
23
x
3
a
24
x
4
a
2n
x
n
)
x
3
=
1
a
33
(b
3
a
31
x
1
a
32
x
2
a
34
x
4
a
3n
x
n
)
x
4
=
1
a
44
(b
4
a
41
x
1
a
42
x
2
a
43
x
3
a
4n
x
n
)
.
.
.
x
n
=
1
a
nn
(b
n
a
n1
x
1
a
n2
x
2
a
n3
x
3
a
n,n1
x
n1
)
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
Jacobi Iteration Method
Gauss-Seidel Iteration Method
Use of Software Packages
Introduction
Example
Notes on Convergence Criteria
So Whats the Point?
It looks like all weve done at this point is some useless algebraic
manipulations. But if we substitute some assumed starting values
for x
1
, x
2
, , x
n
on the right hand side of each of the rewritten
equations, well get a new set of x
i
values on the left hand side. If
we repeat the process, substituting the just-calculated x values
into 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 Packages
Jacobi Iteration Method
Gauss-Seidel Iteration Method
Use of Software Packages
Introduction
Example
Notes on Convergence Criteria
Example
Example 3.19 (p.184) Solve the following system of equations
using the Jacobi iteration method with an initial guess of x
i
= 0:
5x
1
x
2
+ 2x
3
=1
2x
1
+ 6x
2
3x
3
=2
2x
1
+ x
2
+ 7x
3
=32
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
Jacobi Iteration Method
Gauss-Seidel Iteration Method
Use of Software Packages
Introduction
Example
Notes on Convergence Criteria
Example
Step 1: reformat the equations, solving the rst one for x
1
, the
second for x
2
, and the third for x
3
:
x
1
=
1
5
(1 + x
2
2x
3
)
x
2
=
1
6
(2 2x
1
+ 3x
3
)
x
3
=
1
7
(32 2x
1
x
2
)
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
Jacobi Iteration Method
Gauss-Seidel Iteration Method
Use of Software Packages
Introduction
Example
Notes on Convergence Criteria
Example
Step 2: Substitute the initial guesses for x
i
into the right-hand side
of the equations:
x
1
=
1
5
(1 + 0 2 (0))
x
2
=
1
6
(2 2 (0) + 3 (0))
x
3
=
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 Packages
Jacobi Iteration Method
Gauss-Seidel Iteration Method
Use of Software Packages
Introduction
Example
Notes on Convergence Criteria
Example
Step 3: Substitute the calculated values for for x
i
into the
right-hand side of the equations:
x
1
=
1
5
(1 + 0.3333 2 (4.5714))
x
2
=
1
6
(2 2 (0.2000) + 3 (4.5714))
x
3
=
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 Packages
Jacobi Iteration Method
Gauss-Seidel Iteration Method
Use of Software Packages
Introduction
Example
Notes on Convergence Criteria
Example
Step 4, 5, : Continue substituting x
i
values into the right-hand
side of the equations and watch for them to converge to nal
values:
Iteration number x
1
x
2
x
3
1 0.0000 0.0000 0.0000
2 -0.2000 0.3333 4.5714
3 1.5619 2.6857 4.5810
4 1.0952 2.1032 3.7415
5 0.8760 1.8390 3.9580
6 1.0154 2.0204 4.0584
7 1.0193 2.0241 3.9927
8 0.9923 1.9899 3.9910
9 0.9984 1.9981 4.0037
10 1.0018 2.0023 4.0007
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
Jacobi Iteration Method
Gauss-Seidel Iteration Method
Use of Software Packages
Introduction
Example
Notes on Convergence Criteria
Notes on Convergence Criteria
Like many of the iterative root-nding methods in Chapter 2, the
Jacobi iteration method is not guaranteed to converge on the exact
answer 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 converge
regardless of the starting guess for x.
Diagonal dominance is dened as the condition where the
coecient along the diagonal on any row is larger in absolute value
than the sum of the absolute values of the other coecients on the
same row.
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
Jacobi Iteration Method
Gauss-Seidel Iteration Method
Use of Software Packages
Introduction
Example
Notes on Convergence Criteria
Is Example 3.19 Diagonally Dominant?
5x
1
x
2
+ 2x
3
=1
2x
1
+ 6x
2
3x
3
=2
2x
1
+ x
2
+ 7x
3
=32
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
Jacobi Iteration Method
Gauss-Seidel Iteration Method
Use of Software Packages
Introduction
Example
Notes on Convergence Criteria
Is Example 3.19 Diagonally Dominant?
_
_
5 1 2
2 6 3
2 1 7
_
_
_
_
_
x
1
x
2
x
3
_
_
_
=
_
_
_
1
2
32
_
_
_
| 5| > | 1| + |2|
|6| > |2| + | 3|
|7| > |2| + |1|
Yes, this system of equations is diagonally dominant. We will
converge to the exact solution regardless of the values of x
i
we
start with.
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
Jacobi Iteration Method
Gauss-Seidel Iteration Method
Use of Software Packages
Introduction
Example
Gauss-Seidel Iteration: Introduction
Gauss-Seidel iteration is similar to Jacobi iteration, except that
new values for x
i
are used on the right-hand side of the equations
as soon as they become available. It improves upon the Jacobi
method in two respects:
Convergence is quicker, since you benet from the newer,
more accurate x
i
values earlier.
Memory requirements are reduced by 50%, since you only
need to keep track of one set of x
i
values, not two sets.
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
Jacobi Iteration Method
Gauss-Seidel Iteration Method
Use of Software Packages
Introduction
Example
Example
Example 3.20 (p.186) Solve the following system of equations
using the Gauss-Seidel iteration method with an initial guess of
x
i
= 0:
5x
1
x
2
+ 2x
3
=1
2x
1
+ 6x
2
3x
3
=2
2x
1
+ x
2
+ 7x
3
=32
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
Jacobi Iteration Method
Gauss-Seidel Iteration Method
Use of Software Packages
Introduction
Example
Example
Step 1: reformat the equations, solving the rst one for x
1
, the
second for x
2
, and the third for x
3
:
x
1
=
1
5
(1 + x
2
2x
3
)
x
2
=
1
6
(2 2x
1
+ 3x
3
)
x
3
=
1
7
(32 2x
1
x
2
)
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
Jacobi Iteration Method
Gauss-Seidel Iteration Method
Use of Software Packages
Introduction
Example
Example
Step 2a: Substitute the initial guesses for x
i
into the right-hand
side of the rst equation:
x
(2)
1
=
1
5
(1 + 0 2 (0)) = 0.2000
Step 2b: Substitute the new x
1
value with the initial guess for x
3
into the second equation:
x
(2)
2
=
1
6
(2 2 (0.2000) + 3 (0)) = 0.4000
Step 2c: Substitute the new x
1
and x
2
values into the third
equation:
x
(2)
3
=
1
7
(32 2 (0.2000) (0.4000)) = 4.5714
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
Jacobi Iteration Method
Gauss-Seidel Iteration Method
Use of Software Packages
Introduction
Example
Example
Step 3, 4, : Repeat step 2 and watch for the x
i
values to
converge to an exact solution.
Iteration number x
1
x
2
x
3
1 0.0000 0.0000 0.0000
2 -0.2000 0.4000 4.5714
3 1.5486 2.1029 3.8286
4 0.9109 1.9440 4.0335
5 1.0246 2.0085 3.9918
6 0.9950 1.9975 4.0018
7 1.0012 2.0005 3.9996
8 0.9997 1.9999 4.0001
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
Jacobi Iteration Method
Gauss-Seidel Iteration Method
Use of Software Packages
MATLAB
Excel
Example 3.27
Find the solution to the following system of equations:
_

_
4 1 1 0
1 4 0 1
1 0 4 1
0 1 1 4
_

_
_

_
x
1
x
2
x
3
x
4
_

_
=
_

_
200
400
0
200
_

_
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
Jacobi Iteration Method
Gauss-Seidel Iteration Method
Use of Software Packages
MATLAB
Excel
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=[ -200; -400; 0; -200]
b =
-200
-400
0
-200
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
Jacobi Iteration Method
Gauss-Seidel Iteration Method
Use of Software Packages
MATLAB
Excel
2 MATLAB Solutions
>> x=inv(A)*b
x =
100.0000
150.0000
50.0000
100.0000
>> x=A\b
x =
100.0000
150.0000
50.0000
100.0000
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
Jacobi Iteration Method
Gauss-Seidel Iteration Method
Use of Software Packages
MATLAB
Excel
Example 3.29 (Corrected)
Use MATLAB to nd the inverse of the matrix [A] given by
[A] =
_

_
1
1
2
1
3

1
n
1
2
1
3
1
4

1
n+1
1
3
1
4
1
5

1
n+2
.
.
.
.
.
.
.
.
.
.
.
.
1
n
1
n+1
1
n+2

1
2n1
_

_
, n = 50
and nd the error in the inverse matrix by calculating
[C] = [A][A]
1
and summing up the absolute values of the matrix
elements. If there was no error at all, the sum would be n.
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
Jacobi Iteration Method
Gauss-Seidel Iteration Method
Use of Software Packages
MATLAB
Excel
MATLAB Solution 1
>> A=hilb (50);
>> result=inv(A)*A;
Warning: Matrix is close to singular or badly scaled.
Results may be inaccurate. RCOND = 1.603366e -020.
>> err=sum(abs(result (:)))
err =
7.3886e+011
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
Jacobi Iteration Method
Gauss-Seidel Iteration Method
Use of Software Packages
MATLAB
Excel
MATLAB Solution 2
>> A=hilb (50);
>> result=A\A;
Warning: Matrix is close to singular or badly scaled.
Results may be inaccurate. RCOND = 1.603366e -020.
>> err=sum(abs(result (:)))
err =
192.9856
>>
The error on this version is much, much lower. This is why we
dont use the inv() function on ill-conditioned matrices.
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages
Jacobi Iteration Method
Gauss-Seidel Iteration Method
Use of Software Packages
MATLAB
Excel
Excel
Microsoft Excel can also do matrix inversion, but its a bit
cumbersome. However, if its the only tool you have at some
point, its better than nothing. See the the matrix inversion.xls
le located with the lecture slides on the web.
Mike Renfro Jacobi and Gauss-Seidel Iteration Methods, Use of Software Packages

S-ar putea să vă placă și