Graphics Programs Reference
In-Depth Information
Matrix inversion has another serious drawback—a bandedmatrix loses its struc-
ture during inversion. In otherwords, if A is banded or otherwise sparse, then A 1 is
fullypopulated. However, the inverse of a triangular matrix remainstriangular.
EXAMPLE 2.13
Write a function that inverts amatrix using LU decompositionwith pivoting. Test the
function by inverting
0
.
6
0
.
4 1
.
0
A
=
0
.
3
0
.
2 0
.
5
0
.
6
1
.
00
.
5
Solution The function matInv listedbelow inverts any martix A
.
function Ainv = matInv(A)
% Inverts martix A with LU decomposition.
% USAGE: Ainv = matInv(A)
n = size(A,1);
Ainv = eye(n); % Store RHS vectors in Ainv.
[A,perm] = LUdecPiv(A); % Decompose A.
% Solve for each RHS vector and store results in Ainv
% replacing the corresponding RHS vector.
fori=1:n
Ainv(:,i) = LUsolPiv(A,Ainv(:,i),perm);
end
The following test program computes the inverse of the givenmatrix and checks
whether AA 1
=
I :
% Example 2.13 (Matrix inversion)
A=[0.6-0.41.0
-0.3 0.2 0.5
0.6 -1.0 0.5];
Ainv = matInv(A)
check = A*Ainv
Here are the results:
>> Ainv =
1.6667
-2.2222
-1.1111
1.2500
-0.8333
-1.6667
0.5000
1.0000
0
Search WWH ::




Custom Search