2.9.Exploiting matrix structure¶
A common situation in computation is that a problem has certain properties or structure that can be used to get a faster or more accurate solution. There are many properties of a matrix that can affect LU factorization. Here is an easy one to check.
Diagonal dominance has a computationally useful implication.
We next consider three other types of matrices that cause the LU factorization to be specialized in some important way.
2.9.1Banded matrices¶
If row pivoting is not used, the and factors preserve the lower and upper bandwidths of . This fact implies computational savings in both the factorization and the triangular substitutions, because the zeros appear predictably and we can skip multiplication and addition with them.
In order to exploit the savings offered by sparsity, we would need to make modifications to Function 2.4.1 and the triangular substitution routines. Alternatively, we can get Julia to take advantage of the structure automatically by converting the matrix into a special type called sparse. Sparse matrices are covered in more detail in Chapters 7 and 8.
2.9.2Symmetric matrices¶
Recall from Definition 2.2.2 that a symmetric matrix is a square matrix satisfying . Symmetric matrices arise frequently in applications because many types of interactions, such as gravitation and social-network befriending, are inherently symmetric. Symmetry in linear algebra simplifies many properties and algorithms. As a rule of thumb, if your matrix has symmetry, you want to exploit and preserve it.
In we arbitrarily required the diagonal elements of , but not , to be one. That breaks symmetry, so we need to modify the goal to
where is unit lower triangular and is diagonal. To find an algorithm for this factorization, we begin by generalizing (2.4.4) a bit without furnishing proof.
Let’s derive the LDL factorization for a small example.
In practice, we don’t actually have to carry out any arithmetic in the upper triangle of as we work, since the operations are always the mirror image of those in the lower triangle. As a result, it can be shown that LDL factorization takes about half as much work as the standard LU.
Just as pivoting is necessary to stabilize LU factorization, the LDL factorization without pivoting may be unstable or even fail to exist. We won’t go into the details, because our interest is in specializing the factorization to matrices that also possess another important property.
2.9.3Symmetric positive definite matrices¶
Suppose that is and . Observe that is the product of , , and matrices, so it is a scalar, sometimes referred to as a quadratic form. It can be expressed as
The definiteness property is usually difficult to check directly from the definition. There are some equivalent conditions, though. For instance, a symmetric matrix is positive definite if and only if its eigenvalues are all real positive numbers. SPD matrices have important properties and appear in applications in which the definiteness is known for theoretical reasons.
Let us consider what definiteness means to the LDL factorization. We compute
where . Note that since is unit lower triangular, it is nonsingular, so . By taking for , we can read the equalities from right to left and conclude that for all . That permits us to write a kind of square root formula:[1]
Now we have , where is an upper triangular matrix whose diagonal entries are positive.
While the unpivoted LDL factorization is not stable and not even always possible, in the SPD case one can prove that pivoting is not necessary for the existence nor the stability of the Cholesky factorization.
The speed and stability of the Cholesky factorization make it the top choice for solving linear systems with SPD matrices. As a side benefit, the Cholesky algorithm fails (in the form of an imaginary square root or division by zero) if and only if the matrix is not positive definite. This is often the best way to test the definiteness of a symmetric matrix about which nothing else is known.
2.9.4Exercises¶
✍ For each matrix, use (2.9.1) to determine whether it is diagonally dominant.
⌨ For each matrix, use inspection or a numerical Cholesky factorization to determine whether it is SPD.
✍ Show that the diagonal entries of a symmetric positive definite matrix are positive numbers. (Hint: Apply certain special cases of (2.9.5).)
⌨ Using Function 2.4.1 as a guide, write a function luband that accepts as inputs a banded matrix and its upper and lower bandwidths, and returns the LU factors (without pivoting). The function should avoid doing arithmetic using the locations that are known to stay zero. (Hint: Refer to the more efficient form of lufact given in Efficiency of matrix computations. You only need to limit the rows and columns that are accessed within the loop.)
Test your function on a matrix with lower bandwidth 1 and upper bandwidth 2 whose entries are given by
⌨ (Julia-specific) The Tridiagonal matrix type invokes a specialized algorithm for solving a linear system.
(a) Set n=2000 and t=0. In a loop that runs 100 times, generate a linear system via
A = triu( tril(rand(n, n),1), -1)
b = ones(n)
x = A \ bUsing @elapsed, increment t by the time it takes to perform A\b. Print out the final value of t.
(b) Repeat the experiment of part (a), but generate the matrix via
A = Tridiagonal(rand(n,n))What is the ratio of running times for part (a) and (b)?
(c) Now perform the experiment of part (b) for , keeping the total time for each value of in a vector. Plot running time as a function of on a log-log scale. Is the time most like , , or ? (If the answer is unclear, try increasing the number of solves per value of to 100 or more.)
✍ Prove that if is any real invertible square matrix, then is SPD. (Hint: First, verify symmetry. Then show that for all . Finally, explain why zero is ruled out if .)
Except for this diagonal, positive definite case, it’s not trivial to define the square root of a matrix, so don’t generalize the notation used here.