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. For example, an n×n matrix A is diagonally dominant if
If row pivoting is not used, the L and U factors preserve the lower and upper bandwidths of A. 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.
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 A=LU we arbitrarily required the diagonal elements of L, but not U, to be one. That breaks symmetry, so we need to modify the goal to
where L is unit lower triangular and D 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 LDLT factorization for a small example.
In practice we don’t actually have to carry out any arithmetic in the upper triangle of A 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 LDLT factorization takes about half as much work as the standard LU.
Just as pivoting is necessary to stabilize LU factorization, the LDLT 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.
Suppose that A is n×n and x∈Rn. Observe that xTAx is the product of 1×n, n×n, and n×1 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 LDLT factorization. We compute
where z=LTx. Note that since L is unit lower triangular, it is nonsingular, so x=L−Tz. By taking z=ek for k=1,…,n, we can read the equalities from right to left and conclude that Dkk>0 for all k. That permits us to write a kind of square root formula:[1]
Now we have A=LD1/2D1/2LT=RTR, where R=D1/2LT is an upper triangular matrix whose diagonal entries are positive.
While the unpivoted LDLT 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 A is not positive definite. This is often the best way to test the definiteness of a symmetric matrix about which nothing else is known.
that accepts upper and lower bandwidth values and returns LU factors (without pivoting) in a way that avoids 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.)
⌨ The Tridiagonal matrix type invokes a specialized algorithm for solving a linear system.
(a) Set n=1000 and t=0. In a loop that runs 50 times, generate a linear system via
A = triu( tril(rand(n,n),1), -1)
b = ones(n)
Using @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 n=1000,1200,1400,…,3000, keeping the total time for each value of n in a vector. Plot running time as a function of n on a log-log scale. Is the time most like O(n), O(n2), or O(n3)? (If the answer is unclear, try increasing the number of solves per value of n to 100 or more.)
✍ Prove that if A is any real invertible square matrix, then ATA is SPD. (Hint: First show that xTATAx≥0 for all x. Then explain why zero is ruled out if x=0.)