Simultaneous Equation Solver


This page contains a routine that numerically solves a system of N equations in N unknowns, where N may be up to 12 and the variables are real.


Author: E. A. Voorhees, Los Alamos National Laboratory (LANL)

Dongarra, J. J.;   J.R. Bunch;   C.B. Moler;   and G.W. Stewart.
          "LINPACK User's Guide"
          SIAM, Philadelphia

The utility posted on this page is based on the program "SGEFS.F", written by E. A. Voorhees (LANL).
"SGEFS.F" is part of the SLATEC library of programs, and its original code (written in FORTRAN) can be viewed there.
Before being posted on this page, "SGEFS.F" was translated to Javascript and edited. Although all care was taken to ensure that it was translated accurately, some errors may have crept into the translation. These errors are mine; the original FORTRAN routines have been thoroughly tested and work properly. Please contact the webmaster to report any errors.

Consider a system of three equations in three unknowns, which takes the following form:

a11 x1 + a12 x2 + a13 x3 = b1
a21 x1 + a22 x2 + a23 x3 = b2
a31 x1 + a32 x2 + a33 x3 = b3

where the a and b values are known constants. Knowing these constants, the task is then to solve for the values of x that satisfy this system.

This system can be rearranged into matrix form:

[A](x) = (b)

where [A] is a square matrix and (x) and (b) are column vectors:

        a11   a12   a13
[A]   =   a21   a22   a23
        a31   a32   a33

(x)   =   x2

(b)   =   b2

(i) The first entry should be the dimension of the system, N (remember, N should not be greater than 12).
(ii) The next NxN entries should be the coefficients of the A Matrix.
The coefficients should be entered in the following order:
a11, a12, a13, . . .
a21, a22, a23, . . .
(iii) The next N entries should be the coefficients of the b vector: b1, b2, b3, . . . etc.

Do not enter commas, periods, brackets, etc. Also note that numbers in scientific notation are NOT recognized.

For example, say we want to solve the following system:

1 x1 + 2 x2 + 3 x3 = 7
2 x1 - 1 x2 + 1 x3 = 8
3 x1 + 4 x2 - 1 x3 = 9

Data input to the box should be as follows:

  1     2     3  
  2     -1     1  
  3     4     -1  
  7     8     9  

Once all the data has been entered, click the Solve button, and the values of x that solve the system will be computed.

IMPORTANT: Make sure that Error Code is greater than 0; if it is not, the solution is meaningless.
If Error Code > 0, it represents a rough estimate of the number of digits of accuracy in the solution, (x).
If Error Code < 0, there are errors:
            Error Code = -1: Fatal Error. [A] is computationally singular. No solution was computed.
            Error Code = -2: Warning. Solution has no significance. The solution may be inaccurate, or [A] may be poorly scaled.

In addition, several other properties of   [A]   follow, for example,
rcond, which is an estimate of 1/cond(A),
the determinant of the [A] Matrix,
the LU Decomposition Matrices [P], [L], and [U] such that [P][L][U] = [A],
and the inverse of the [A] Matrix (if non-singular).


Return to Math Functions Page Home