| home | contents | send comment | send link | add bookmark |

Gaussian elimination 4x4 Solver

by Stephen R. Schmitt

A·x = y
·
x1
x2
x3
x4
=
solution
x1
x2
x3
x4
=

Contents

  1. About
  2. The source code
  3. Discussion

1. About

This Java Script calculator solves a system of four linear equations in four variables using Gaussian elimination. To operate the calculator, enter the coefficients and the constants y. Press the Compute button to obtain the solution. On invalid entries, a popup window will display an error message. The Test button loads a test case to show how the calculator operates.

Return to Contents


2. The source code

The Java Script source code for this program can be viewed by using the View|Source command of your web browser.

You may use or modify this source code in any way you find useful, provided that you agree that the author has no warranty, obligations or liability. You must determine the suitability of this source code for your use.

Return to Contents


3. Discussion

A system of linear equations has the form:

a11x1 + a12x2 + . . . a1NxN = y1
a21x1 + a22x2 + . . . a2NxN = y1
 .                          .
 .                          .
aN1x1 + aN2x2 + . . . aNNxN = yN
which is represented in matrix-vector form as:
Ax = y
Gaussian elimination solves this linear system of equations by converting the original equations, using elementary row operations, to a simpler form that allows a simple substitution process. The basic algorithm can be broken into stages:
  1. Create an augmented matrix, [A:y] by combining the coefficient matrix A with the right hand side vector y to create an n by n + 1 matrix.
  2. Use elementary row operations to eliminate the elements below the main diagonal.
    1. Start at the first diagonal element - a11.
    2. If necessary, swap the current row with a lower row to maximize the diagonal element
    3. Add current row, multiplied by a constant, to each lower row so that the elements below the diagonal element become zero.
    4. Repeat steps 2 and 3 for the next diagonal element.
  3. Starting from the last row, work backward to solve for variables by using substitution. The symbol (') indicates that the element's value is not the same as in the original matrix.
    1. On the last row, xN = y'N/a'NN.
    2. Repeat xi = (y'i - ∑a'ijxj)/a'NN for i = (N - 1) ... 1.

An alternative procedure, Gauss-Jordan elimination, uses elementary row operations to both zero the elements below the diagonal and above. Back substitution is not necessary and the values of the unknowns are the values of the elements in the last column of the augmented matrix. However, Gauss-Jordan elimination is less efficient in usage of computer resources than Gaussian elimination.

Return to Contents



Copyright © 2006, Stephen R. Schmitt