U5 MatrixInverseGaussElim Notes+HighL
U5 MatrixInverseGaussElim Notes+HighL
Equations
Gaussian Elimination and the LU Decompostion
Dr. M. Bikdash
We cannot divide two matrices like B/A if A is a matrix and we must use
BA 1 where A 1 is the inverse (if it exists)
The matrix inverse is a complicated concept because A can behave like a zero
even when it is not.
Understanding the existence and uniqueness of the inverse is crucial and it
can be tested using many major concepts in matrix theory
Like: determinant, rank, linear independence, eigenvalues, singular values, etc.
The matrix inverse is a useful mathematical notation but it is not useful from
a computational point of view.
Instead, use Gaussian elimination to solve the system Ax = B directly
The inverse of a 2x2 matrix can be computed easily with this trick:
https://www.khanacademy.org/math/precalculus/x9e81a4f98389efdf:matrices/
x9e81a4f98389efdf:…nding-inverse-matrix-with-determinant/v/inverse-of-a-
2x2-matrix
Wikipedia has an extensive article on the matrix inverse
https://en.wikipedia.org/wiki/Invertible_matrix#Blockwise_inversion
In particular, read this mega-theorem which relates the inverse to almost
every other concept in matrix theory and linear algebra:
https://en.wikipedia.org/wiki/Invertible_matrix#The_invertible_matrix_theor
Very quick and useful properties are here:
https://en.wikipedia.org/wiki/Invertible_matrix#Other_properties
1 The plural of FLOP must be FLOPs, which is often confused with FLOPS (Floating-Point
De…nition
A square n n matrix A has an n n inverse B if
AB = BA = I .
D
C 0 = CD + 0 0=I Identity matrix. Good!
0
D DC 0 I 0
C 0 = = not an identity matrix!!!
0 0 0 0 0
1
1 1 = 0
|{z} (3)
| {z } 1
nonzero E
| {z } zero matrix
nonzero F
1 2
Fx = x= with x 2 R (8)
1 2.1
Rule of Thumb
It is safe to premultiply (or postmultiply) by an invertible matrix,
Rule of Thumb
Premultiplying by a singular matrix is dangerous!!
is true but
1 1 1 1 1 2 1 2
= does not imply =
1 1 1 1 1 2 1 2
| {z } that
singular
Nonzero divisors of a zero matrix =) there are also nonzero roots of the zero
matrix.
De…nition. An n n matrix that satis…es the conditions M h = 0 and
M h 1 6= 0, h n is called a nilpotent matrix M of index h.
If M 3 = 0 but M 2 6= 0 then M is a cubic root of the zero matrix.
These matrices are crucial to understanding the eigenvalue problem and
singular systems of di¤erential equations.
Theorem. A k–upper triangular matrix A is nilpotent of index n + 1 k.
Proof. (sketch). Every time we premultiply by A we lose one superdiagonal:
2 3 2 3
0 a b 0 0 ac
A = 4 0 0 c 5 ) A2 = 4 0 0 0 5 ) A3 = 0. (9)
0 0 0 0 0 0
2 3 1 2 3
2 0 0 1/2 0 0 Inverse of lower
4 4 3 0 5 = 4 2/3 1/3 0 5 triangular is (quasi) lower
2 2 1 1/3 2/3 1 triangular. Why??
2 32 3 2 3
2 0 0 x1 1 Solve the system
4 4 3 0 5 4 x2 5 = 4 2 5 directly. No need to
2 2 1 x3 3 compute the inverse!!
The operations have the form: When working with pivot A(k,k),
R1 $ R_i1 (if needed) j>k
R2 R2-A(2,1)/A(2,1)*R1
R3 R3-A(3,1)/A(1,1)*R1 A(k:end, 1:k-1) are already zero
.. Rk really denotes A(k,k+1:end)
.
R2 $ R_i2 (if needed) Rj really denotes A(j,k+1:end)
R3 R3-A(3,2)/A(2,2)*R2
The multiplier -A(j,k)/A(k,k)
R4 R4-A(4,2)/A(2,2)*R2
.. can be stored in A(k,j) which is
. supposedly being zeroed.
R3 $ R_i3 (if needed)
Need to store the swaps: start with
R4 R4-A(4,3)/A(3,3)*R3
.. p=[1,2,...,n] and swap as
. needed p(1)$ p(i1), ...
Algorithm
Naive pseudo-Code for Gauss Elimination
Algorithm
Input is an n n nonsingular matrix A.
Output is a permutation vector p, and a matrix W=U+(L-I) which can overwrite A
The upper triangular matrix U can be found as triu(W)
The unit lower triangular matrix L can be found as
L=(tril(W)-diag(diag(W))+eye(n)). It stores the multipliers.
The permutation matrix P can be found as In=eye(n); P=In(p,:).
(2n 1 ) n (n 1) n3 n2 n
(n 1 )2 + + 12 = = + MAs
6 3 2 3
2n 3
Reduction to Upper-Triangular Form requires O 3 FLOPs
function x = backsubstitution(A, b)
[n,m] = size(A) ; % m rows, n columns
% ... diagonstics skipped ...
x(n) = b(n) / A(n,n) ; % start at the bottom
for i = ( n-1 : -1 :1) % loop over the rows up
c = 1 / A(n,n) ;
x(i) = ( b(i) - A(i,i+1:n)*x(i+1:n) )* c ;
% use c because multiplication is more efficient than division
end
The expressions ABCx and (AB ) (Cx ) and (A (BC )) x and A (B (Cx )) are
mathematically equivalent but not computationally equivalent
Assume A, B , C , are n n matrices and x , y , are n 1 vectors
Matrix-vector multiplication is O n 2
Matrix-matrix multiplication is O (n 3 )
We scale the rows of A so that the elements in the …rst column are all ones:
2 32 3 2 3
10 0 0 0.1 2 200 1 20 2000
4 0 2/10 0 54 5 9 12 5 = 4 1 1.8 2.4 5 = Ā
0 0 1/10 10 90 3000 1 9 300
| {z }| {z }
S 1 (0.1 )S 2 (0.2 )S 3 (0.1 ) A
(11)
Recall that since the pivot’s row will have to be subtracted from the other
row, thus "disturbing" them.
It is obvious that the …rst row is a poor choice, because the element
ā13 = 2000 will overpower ā23 = 2.4 thus endangering the accuracy of the
solution.
Similarly, the third row is a better choice because ā33 = 300 still overpowers
ā23 = 2.4. The best choice for a pivot row is the second row, as it will disturb
the other rows slightly.
If the desired row and/or column permutations are known in advance, they
can be all collected in two permutation matrices P and Q and applied to A
at the onset.
This result in the full pivoting LU decomposition