Documente Academic
Documente Profesional
Documente Cultură
_
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