# Systems of Linear Equations

 Home Matrix Home Systems of Linear Equations Upper / Lower Triagular Matrices Gaussian Elimination Equilibrate Matrix Choleski Decomposition Crout Decomposition Doolittle Decomposition Tridiagonal Systems Iterative Methods Singular Value Decomposition

## Gaussian Elimination

Gaussian elimination is basically the systematic technique for solving a system of linear equations as taught in the first algebra courses in elementary school or high school. The technique consists of picking one of the equations and solving for a given variable in terms of the remaining variables, then substituting that expression for the given variable in the remaining equations and simplifing. Repeat the process until only one variable remains, solve the last equation for that variable, and then working backwards, solve for the remaining variables.

The two real versions and one complex version of Gaussian elimination are presented here. All versions use partial pivoting to select the next variable to eliminate in terms of the remaining variables. In general, the system should be equilibrated before calling either of the routines. The solution then needs to be transformed back to the unequilibrated basis. If more than one system of linear equations needs to be solved using the same matrix of coefficients, then one should use Doolittle's method with partial pivoting, which corresponds to the LU decomposition using Gaussian elimination.

### Function List

• int Gaussian_Elimination( double* A, int n, double* B )

This routine solves the linear system of equations A x = B for x. The matrix A is an n×n matrix, the vector (column matrix) B is an n-dimensional vector. The matrix A is modified during the calculations and the solution x is returned in the vector B. The function returns 0 if the calculation was successful and -1 if the matrix is singular.

• int Gaussian_Elimination_Aux( double* AB, int nrows, int ncols )

This routine solves the linear system of equations A x = B for x, where A is an nrows×nrows matrix, B is an nrows×(ncols - nrows) matrix, and the solution x is an an nrows×(ncols - nrows) matrix. The argument AB is an nrows×ncols matrix [A:B], the first nrows columns of which are the nrows columns of A and the remaining (ncols - nrows) columns are the columns of B. The matrix A is modified during the calculations and the solution x is returned in the last (ncols - nrows) columns of AB. The function returns 0 if the calculation was successful and -1 if the matrix is singular.

• int cGaussian_Elimination( double complex *A, int n, double complex *B )

This routine solves the linear system of equations A x = B for x. The complex matrix A is an n×n matrix, the complex vector (column matrix) B is an n-dimensional vector. The matrix A is modified during the calculations and the complex solution x is returned in the vector B. The function returns 0 if the calculation was successful and -1 if the matrix is singular.

#### C Test Code, Test Results, and Build Shell Script

• The file, testgauss_elimination.c, contains a test program of Gaussian_Elimination( ). This program requires the file gauss_elimination.c listed above.

• The file, Gauss_Elimination.txt, contains the results of the test program testgauss_elimination.c.

• The file, testgauss_elimination.sh, contains the shell script used to compile, link, and execute the test program testgauss_elimination.c.

• The file, testcgauss_elimination.c, contains a test program of cGaussian_Elimination( ). This program requires the file gauss_elimination.c listed above.

• The file, CGauss_Elimination.txt, contains the results of the test program testcgauss_elimination.c.

• The file, testcgauss_elimination.sh, contains the shell script used to compile, link, and execute the test program testcgauss_elimination.c.