
Systems of linear algebraic equations occur in most fields of science and engineering, for example,
due to, for example, the discretisation of ordinary or partial differential equations or integral equations.
A linear equation is an equation that can be expressed as,
a1x1 + a2x2 +
+ anxn = b
where a0, a1 and b are constants.
A set of linear equations is called a system of linear equations or a linear system.
A linear system of n linear equations in n variables,
a1,1x1 + a1,2x2 + a1,nxn = b1can be expressed in the explicit matrix form as
or more conveniently still, by matrix notation as
Ax = bwhere A is an n × n matrix containing the values of i,j s and x and b are n element vectors storing the values of xi s and bi s.
There are two methods to solve a system of linear equations, direct or iterative.
Direct Methods solve systems of linear equations by rearranging matrix A so that values of b can be substituted for x. They are finite methods; that is they will find a solution in a finite, predetermined number of steps.
One of the oldest and most useful methods of solving a system of linear equations Ax = b, is Gaussian elimination. The method uses the systematic subtraction of multiples of equations from other equations to eliminate variables equation by equation until the system is upper triangular. This triangularisation process is referred to as decomposition.
In an upper triangular system, the matrix has only zeros below the main diagonal; the first equation contains all the variables, the second equation is missing x1, the third equation is missing x1 and x2 ... and the last (nth) equation only contains xn. The last equation gives xn. This is then back substituted into the next to last equation to find xn-1. This process of back‐substitution is repeated until the first equation is reached and x1, is solved using the calculated values of x2 ... xn.
Gaussian elimination and back‐substitution are easily programmed and a C++ implementation, based on the FORTRAN code in Chemical Engineering Volume 3 2nd Edition page 317 and Pascal programs Gauss and Solve, Numerical Methods for Engineers and Computer Scientists pages 77 and 83, is provided here, Gaussian Elimination Solver.
Another direct method to solve the system of equations is Gauss‐Jordan elimination. This involves complete elimination, in which zeros are produced for all off‐diagonal elements, both above and below the diagonal.
For large systems the multiplication and division work for Gaussian triangularisation with back substitution tends towards a factor of two‐thirds of the work for Gauss‐Jordan complete reduction, [Numerical Methods for Engineers and Computer Scientists]. Therefore, I haven't implemented Gauss‐Jordan elimination as a routine. A C++ routine is provided in Numerical Recipes in C++ page 42.
Both Gaussian elimination and Gauss‐Jordan elimination have the disadvantage that all right‐hand sides must be known in advance. If they are not known LU decomposition can be used.
The basis of LU decomposition is to write matrix A as the product of two matrices
The solution of a triangular set of equations is quite trivial, as used in the back substitution in Gauss elimination and Gauss‐Jordan solvers. Equation 3 is solved by forward substitution and equation 4 is solved by back substitution as is done for Gauss elimination and Gauss‐Jordan solvers.
I have not implemented an LU decomposition algorithm, as I have already implemented Gaussian elimination with back substitution as it is the algorithm provided in most textbooks and so was the algorithm I came across when I was first trying to solve a system of linear equations. And going forward I expect to be using iterative methods to solve a set of linear equations as iterative solvers overcome the following problems with Direct Methods. A C++ routine is provided in Numerical Recipes in C++ page 49.
The large number of calculations required for elimination and back substitution combined with the limited fixed precision of the numbers stored in a computer mean that it can be difficult for direct methods to obtain a solution with an accuracy comparable with the precision of the data. These problems are described in Numerical Problems with Direct Methods.
In many problems many of the coefficients off the principle diagonal will be zero, this means that matrix will use a lot more memory than necessary, and although since mid-2000 when P.C.s began having at least 1GB of RAM this probably is no longer a problem, all these zero values will still be checked by the algorithm algorithm, impacting performance.
These problems are solved using Iterative Methods to solve the system of equations.
Iterative methods solve the system of linear equations, Ax = b, by generating a series of increasingly better approximations to the solution vector, x. Iterative methods are a better option for solving larger matrices for the following reasons,
The theory of iterative methods for solving the equations is straightforward. Vector x is the exact solution of the linear system Ax = b. However we don't know x, we only know a slightly wrong solution x + δx where δx is error in our guess. When multiplied by A our slightly wrong value of x give a slightly wrong value of the desired result, b namely
A ⋅ (x + δx) = b + δb
By implementing an algorithm to calculate the value of δx that minimises δb we can find the values for x. As listed in the pros of iterative methods above, this means that the matrix is not manipulated and a general routine (common ones listed below) is used to calculate the values of x.
A number of algorithms have been developed to calculate the new values for x that will minimise δb. Common algorithms are,