This chapter provides methods for the solution of systems of simultaneous linear equations, and associated computations. It provides methods for

- – matrix factorizations;
- – solution of linear equations;
- – estimating matrix condition numbers;
- – computing error bounds for the solution of linear equations;
- – matrix inversion;
- – computing scaling factors to equilibrate a matrix.

For a general introduction to the solution of systems of linear equations, you should turn first to (F04 not in this release). The decision trees, in [Decision Trees] in the F04 class Chapter Introduction, direct you to the most appropriate methods in (F04 not in this release)

**F07**class for solving your particular problem. In particular, (F04 not in this release)**F07**class contain Black Box (or driver) methods which enable some standard types of problem to be solved by a call to a single method. Where possible, methods in (F04 not in this release) call**F07**class methods to perform the necessary computational tasks.
There are two types of driver methods in this chapter: simple drivers which just return the solution to the linear equations; and expert drivers which also return condition and error estimates and, in many cases, also allow equilibration. The simple drivers for real matrices have names of the form
and for complex matrices have names of the form
The expert drivers for real matrices have names of the form
and for complex matrices have names of the form

The methods in this chapter (

**F07**class) handle only dense and band matrices (not matrices with more specialised structures, or general sparse matrices).The methods in this chapter have all been derived from the LAPACK project (see Anderson et al. (1999)). They have been designed to be efficient on a wide range of high-performance computers, without compromising efficiency on conventional serial machines.

# Syntax

C# |
---|

public static class F07 |

Visual Basic |
---|

Public NotInheritable Class F07 |

Visual C++ |
---|

public ref class F07 abstract sealed |

F# |
---|

[<AbstractClassAttribute>] [<SealedAttribute>] type F07 = class end |

# Background to the Problems

This section is only a brief introduction to the numerical solution of systems of linear equations. Consult a standard textbook, for example Golub and Van Loan (1996) for a more thorough discussion.

# Notation

We use the standard notation for a system of simultaneous linear equations:

where $A$ is the coefficient matrix, $b$ is the right-hand side, and $x$ is the solution. $A$ is assumed to be a square matrix of order $n$.

$$Ax=b$$ | (1) |

If there are several right-hand sides, we write

where the columns of $B$ are the individual right-hand sides, and the columns of $X$ are the corresponding solutions.

$$AX=B$$ | (2) |

We also use the following notation, both here and in the method documents:

$\hat{x}$ | a computed solution to $Ax=b$, (which usually differs from the exact solution $x$ because of round-off error) |

$r=b-A\hat{x}$ | the residual corresponding to the computed solution $\hat{x}$ |

${\Vert x\Vert}_{\infty}={\displaystyle \underset{i}{\mathrm{max}}}\phantom{\rule{0.25em}{0ex}}\left|{x}_{i}\right|$ | the $\infty $-norm of the vector $x$ |

${\Vert x\Vert}_{1}={\displaystyle \sum _{j=1}^{n}}\left|{x}_{j}\right|$ | the $1$-norm of the vector $x$ |

${\Vert A\Vert}_{\infty}={\displaystyle \underset{i}{\mathrm{max}}}\phantom{\rule{0.25em}{0ex}}{\displaystyle \sum _{j}}\phantom{\rule{0.25em}{0ex}}\left|{a}_{ij}\right|$ | the $\infty $-norm of the matrix $A$ |

${\Vert A\Vert}_{1}={\displaystyle \underset{j}{\mathrm{max}}}\phantom{\rule{0.25em}{0ex}}{\displaystyle \sum _{i=1}^{n}}\left|{a}_{ij}\right|$ | the $1$-norm of the matrix $A$ |

$\left|x\right|$ | the vector with elements $\left|{x}_{i}\right|$ |

$\left|A\right|$ | the matrix with elements $\left|{a}_{ij}\right|$ |

Inequalities of the form $\left|A\right|\le \left|B\right|$ are interpreted component-wise, that is $\left|{a}_{ij}\right|\le \left|{b}_{ij}\right|$ for all $i,j$.

# Matrix Factorizations

If $A$ is upper or lower triangular, $Ax=b$ can be solved by a straightforward process of backward or forward substitution.

Otherwise, the solution is obtained after first factorizing $A$, as follows.

**General matrices (LU factorization with partial pivoting)**

$$A=PLU$$ |

**Symmetric positive definite matrices (Cholesky factorization)**

$$A={U}^{\mathrm{T}}U\text{\hspace{1em} or \hspace{1em}}A=L{L}^{\mathrm{T}}$$ |

**Symmetric positive semidefinite matrices (pivoted Cholesky factorization)**

$$A=P{U}^{\mathrm{T}}U{P}^{\mathrm{T}}\text{\hspace{1em}or\hspace{1em}}A=PL{L}^{\mathrm{T}}{P}^{\mathrm{T}}$$ |

**Symmetric indefinite matrices (Bunch–Kaufman factorization)**

$$A=PUD{U}^{\mathrm{T}}{P}^{\mathrm{T}}\text{\hspace{1em} or \hspace{1em}}A=PLD{L}^{\mathrm{T}}{P}^{\mathrm{T}}$$ |

# Solution of Systems of Equations

Given one of the above matrix factorizations, it is straightforward to compute a solution to $Ax=b$ by solving two subproblems, as shown below, first for $y$ and then for $x$. Each subproblem consists essentially of solving a triangular system of equations by forward or backward substitution; the permutation matrix $P$ and the block diagonal matrix $D$ introduce only a little extra complication:

**General matrices (**LU

**factorization)**

$$\begin{array}{l}Ly={P}^{\mathrm{T}}b\\ Ux=y\end{array}$$ |

**Symmetric positive definite matrices (Cholesky factorization)**

$$\begin{array}{l}{U}^{\mathrm{T}}y=b\\ Ux=y\end{array}\text{\hspace{1em} or \hspace{1em}}\begin{array}{l}Ly=b\\ {L}^{\mathrm{T}}x=y\end{array}$$ |

**Symmetric indefinite matrices (Bunch–Kaufman factorization)**

$$\begin{array}{l}PUDy=b\\ {U}^{\mathrm{T}}{P}^{\mathrm{T}}x=y\end{array}\text{\hspace{1em} or \hspace{1em}}\begin{array}{l}PLDy=b\\ {L}^{\mathrm{T}}{P}^{\mathrm{T}}x=y\end{array}$$ |

# Sensitivity and Error Analysis

# Normwise error bounds

Frequently, in practical problems the data $A$ and $b$ are not known exactly, and it is then important to understand how uncertainties or perturbations in the data can affect the solution.

If $x$ is the exact solution to $Ax=b$, and $x+\delta x$ is the exact solution to a perturbed problem $\left(A+\delta A\right)\left(x+\delta x\right)=\left(b+\delta b\right)$, then

where $\kappa \left(A\right)$ is the condition number of $A$ defined by

$$\frac{\Vert \delta x\Vert}{\Vert x\Vert}\le \kappa \left(A\right)\left(\frac{\Vert \delta A\Vert}{\Vert A\Vert}+\frac{\Vert \delta b\Vert}{\Vert b\Vert}\right)+\cdots \left(\text{second-order terms}\right)$$ |

$$\kappa \left(A\right)=\Vert A\Vert .\Vert {A}^{-1}\Vert \text{.}$$ | (3) |

In other words, relative errors in $A$ or $b$ may be amplified in $x$ by a factor $\kappa \left(A\right)$. [Estimating condition numbers] discusses how to compute or estimate $\kappa \left(A\right)$.

Similar considerations apply when we study the effects of rounding errors introduced by computation in finite precision. The effects of rounding errors can be shown to be equivalent to perturbations in the original data, such that $\frac{\Vert \delta A\Vert}{\Vert A\Vert}$ and $\frac{\Vert \delta b\Vert}{\Vert b\Vert}$ are usually at most $p\left(n\right)\epsilon $, where $\epsilon $ is the machine precision and $p\left(n\right)$ is an increasing function of $n$ which is seldom larger than $10n$ (although in theory it can be as large as ${2}^{n-1}$).

In other words, the computed solution $\hat{x}$ is the exact solution of a linear system $\left(A+\delta A\right)\hat{x}=b+\delta b$ which is close to the original system in a normwise sense.

# Estimating condition numbers

The previous section has emphasized the usefulness of the quantity $\kappa \left(A\right)$ in understanding the sensitivity of the solution of $Ax=b$. To compute the value of $\kappa \left(A\right)$ from equation (3) is more expensive than solving $Ax=b$ in the first place. Hence it is standard practice to estimate $\kappa \left(A\right)$, in either the $1$-norm or the $\infty $-norm, by a method which only requires $\mathit{O}\left({n}^{2}\right)$ additional operations, assuming that a suitable factorization of $A$ is available.

The method used in this chapter is Higham's modification of Hager's method (see Higham (1988)). It yields an estimate which is never larger than the true value, but which seldom falls short by more than a factor of $3$ (although artificial examples can be constructed where it is much smaller). This is acceptable since it is the order of magnitude of $\kappa \left(A\right)$ which is important rather than its precise value.

Because $\kappa \left(A\right)$ is infinite if $A$ is singular, the methods in this chapter actually return the reciprocal of $\kappa \left(A\right)$.

# Scaling and Equilibration

The condition of a matrix and hence the accuracy of the computed solution, may be improved by scaling; thus if ${D}_{1}$ and ${D}_{2}$ are diagonal matrices with positive diagonal elements, then

is the scaled matrix. A general matrix is said to be equilibrated if it is scaled so that the lengths of its rows and columns have approximately equal magnitude. Similarly a general matrix is said to be row-equilibrated (column-equilibrated) if it is scaled so that the lengths of its rows (columns) have approximately equal magnitude. Note that row scaling can affect the choice of pivot when partial pivoting is used in the factorization of $A$.

$$B={D}_{1}A{D}_{2}$$ |

A symmetric or Hermitian positive definite matrix is said to be equilibrated if the diagonal elements are all approximately equal to unity.

For further information on scaling and equilibration see Section 3.5.2 of Golub and Van Loan (1996), Section 7.2, 7.3 and 9.8 of Higham (1988) and Section 5 of Chapter 4 of Wilkinson (1965).

Methods are provided to return the scaling factors that equilibrate a matrix for general, general band, symmetric and Hermitian positive definite and symmetric and Hermitian positive definite band matrices.

# Componentwise error bounds

A disadvantage of normwise error bounds is that they do not reflect any special structure in the data $A$ and $b$ – that is, a pattern of elements which are known to be zero – and the bounds are dominated by the largest elements in the data.

Componentwise error bounds overcome these limitations. Instead of the normwise relative error, we can bound the relative error in each component of $A$ and $b$:

where the component-wise backward error bound $\omega $ is given by

$$\underset{ijk}{\mathrm{max}}\phantom{\rule{0.25em}{0ex}}\left(\frac{\left|\delta {a}_{ij}\right|}{\left|{a}_{ij}\right|},\frac{\left|\delta {b}_{k}\right|}{\left|{b}_{k}\right|}\right)\le \omega $$ |

$$\omega =\underset{i}{\mathrm{max}}\phantom{\rule{0.25em}{0ex}}\frac{\left|{r}_{i}\right|}{{\left(\left|A\right|.\left|\hat{x}\right|+\left|b\right|\right)}_{i}}\text{.}$$ |

Methods are provided in this chapter which compute $\omega $, and also compute a forward error bound which is sometimes much sharper than the normwise bound given earlier:

$$\frac{{\Vert x-\hat{x}\Vert}_{\infty}}{{\Vert x\Vert}_{\infty}}\le \frac{{\Vert \left|{A}^{-1}\right|.\left|r\right|\Vert}_{\infty}}{{\Vert x\Vert}_{\infty}}\text{.}$$ |

Care is taken when computing this bound to allow for rounding errors in computing $r$. The norm ${\Vert \left|{A}^{-1}\right|.\left|r\right|\Vert}_{\infty}$ is estimated cheaply (without computing ${A}^{-1}$) by a modification of the method used to estimate $\kappa \left(A\right)$.

# Iterative refinement of the solution

If $\hat{x}$ is an approximate computed solution to $Ax=b$, and $r$ is the corresponding residual, then a procedure for iterative refinement of $\hat{x}$ can be defined as follows, starting with ${x}_{0}=\hat{x}$:

- for $i=0,1,\dots \text{}$, until convergence
compute ${r}_{i}=b-A{x}_{i}$ solve $A{d}_{i}={r}_{i}$ compute ${x}_{i+1}={x}_{i}+{d}_{i}$

In (F04 not in this release), methods are provided which perform this procedure using additional precision to compute $r$, and are thus able to reduce the forward error to the level of machine precision.

The methods in this chapter do not use additional precision to compute $r$, and cannot guarantee a small forward error, but can guarantee a small backward error (except in rare cases when $A$ is very ill-conditioned, or when $A$ and $x$ are sparse in such a way that $\left|A\right|.\left|x\right|$ has a zero or very small component). The iterations continue until the backward error has been reduced as much as possible; usually only one iteration is needed.

# Matrix Inversion

It is seldom necessary to compute an explicit inverse of a matrix. In particular, do not attempt to solve $Ax=b$ by first computing ${A}^{-1}$ and then forming the matrix-vector product $x={A}^{-1}b$; the procedure described in [Solution of Systems of Equations] is more efficient and more accurate.

However, methods are provided for the rare occasions when an inverse is needed, using one of the factorizations described in [Matrix Factorizations].

# Packed Storage Formats

Methods which handle symmetric matrices are usually designed so that they use either the upper or lower triangle of the matrix; it is not necessary to store the whole matrix. If the upper or lower triangle is stored conventionally in the upper or lower triangle of a two-dimensional array, the remaining elements of the array can be used to store other useful data.

However, that is not always convenient, and if it is important to economize on storage, the upper or lower triangle can be stored in a one-dimensional array of length $n\left(n+1\right)/2$ or a two-dimensional array with $n\left(n+1\right)/2$ elements; in other words, the storage is almost halved.

The one-dimensional array storage format is referred to as packed storage; it is described in [Packed storage]. The two-dimensional array storage format is referred to as Rectangular Full Packed (RFP) format; it is described in [Rectangular Full Packed (RFP) Storage]. They may also be used for triangular matrices.

Methods designed for these packed storage formats perform the same number of arithmetic operations as methods which use conventional storage. Those using a packed one-dimensional array are usually less efficient, especially on high-performance computers, so there is then a trade-off between storage and efficiency. The RFP methods are as efficient as for conventional storage, although only a small subset of methods use this format.

# Band and Tridiagonal Matrices

A band matrix is one whose nonzero elements are confined to a relatively small number of subdiagonals or superdiagonals on either side of the main diagonal. A tridiagonal matrix is a special case of a band matrix with just one subdiagonal and one superdiagonal. Algorithms can take advantage of bandedness to reduce the amount of work and storage required. The storage scheme used for band matrices is described in [Band storage].

The $LU$ factorization for general matrices, and the Cholesky factorization for symmetric and Hermitian positive definite matrices both preserve bandedness. Hence methods are provided which take advantage of the band structure when solving systems of linear equations.

The Cholesky factorization preserves bandedness in a very precise sense: the factor $U$ or $L$ has the same number of superdiagonals or subdiagonals as the original matrix. In the $LU$ factorization, the row-interchanges modify the band structure: if $A$ has ${k}_{l}$ subdiagonals and ${k}_{u}$ superdiagonals, then $L$ is not a band matrix but still has at most ${k}_{l}$ nonzero elements below the diagonal in each column; and $U$ has at most ${k}_{l}+{k}_{u}$ superdiagonals.

The Bunch–Kaufman factorization does not preserve bandedness, because of the need for symmetric row-and-column permutations; hence no methods are provided for symmetric indefinite band matrices.

The inverse of a band matrix does not in general have a band structure, so no methods are provided for computing inverses of band matrices.

# Block Partitioned Algorithms

Many of the methods in this chapter use what is termed a block partitioned algorithm. This means that at each major step of the algorithm a block of rows or columns is updated, and most of the computation is performed by matrix-matrix operations on these blocks. The matrix-matrix operations are performed by calls to the Level 3 BLAS
(see

**F06**class), which are the key to achieving high performance on many modern computers. See Golub and Van Loan (1996) or Anderson et al. (1999) for more about block partitioned algorithms.The performance of a block partitioned algorithm varies to some extent with the block size – that is, the number of rows or columns per block. This is a machine-dependent parameter, which is set to a suitable value when the library is implemented on each range of machines. You do not normally need to be aware of what value is being used. Different block sizes may be used for different methods. Values in the range $16$ to $64$ are typical.

On some machines there may be no advantage from using a block partitioned algorithm, and then the methods use an unblocked algorithm (effectively a block size of $1$), relying solely on calls to the Level 2 BLAS
(see

**F06**class again).The only situation in which you need some awareness of the block size is when it affects the amount of workspace to be supplied to a particular method. This is discussed in [Length of work arrays].

# Mixed Precision LAPACK Routines

Some LAPACK routines use mixed precision arithmetic in an effort to solve problems more efficiently on modern hardware. They work by converting a double precision problem into an equivalent single precision problem, solving it and then using iterative refinement in double precision to find a full precision solution to the original problem. The method may fail if the problem is too ill-conditioned to allow the initial single precision solution, in which case the methods fall back to solve the original problem entirely in double precision. The vast majority of problems are not so ill-conditioned, and in those cases the technique can lead to significant gains in speed without loss of accuracy. This is particularly true on machines where double precision arithmetic is significantly slower than single precision.

# References

Anderson E, Bai Z, Bischof C, Blackford S, Demmel J, Dongarra J J, Du Croz J J, Greenbaum A, Hammarling S, McKenney A and Sorensen D (1999)

*LAPACK Users' Guide*(3rd Edition) SIAM, PhiladelphiaGolub G H and Van Loan C F (1996)

*Matrix Computations*(3rd Edition) Johns Hopkins University Press, BaltimoreHigham N J (1988) Algorithm 674: Fortran codes for estimating the one-norm of a real or complex matrix, with applications to condition estimation

*ACM Trans. Math. Software***14**381–396Wilkinson J H (1965)

*The Algebraic Eigenvalue Problem*Oxford University Press, Oxford