Gauss Jordan Elimination Calculator

Gauss-Jordan Elimination Calculator

Solve systems of linear equations using the Reduced Row Echelon Form (RREF) method.

2 Equations (2×3 Matrix) 3 Equations (3×4 Matrix) 4 Equations (4×5 Matrix)

Resulting RREF Matrix

Solutions

Understanding Gauss-Jordan Elimination

The Gauss-Jordan elimination method is an algorithm used in linear algebra to solve systems of linear equations, find the inverse of a matrix, and determine the rank of a matrix. Unlike Gaussian elimination, which stops at row echelon form, Gauss-Jordan continues until the matrix is in Reduced Row Echelon Form (RREF).

How the Calculation Works

The process follows these core elementary row operations:

  • Swapping: Interchanging two rows to place a non-zero element in the pivot position.
  • Scaling: Multiplying a row by a non-zero scalar to make the leading coefficient (pivot) equal to 1.
  • Pivoting: Adding or subtracting multiples of the pivot row from other rows to create zeros above and below the leading 1.

Example Scenario

Consider the following 2×2 system:

2x + 1y = 5
1x + 3y = 10

1. Represent as an augmented matrix: [[2, 1, 5], [1, 3, 10]].
2. Divide the first row by 2 to get a leading 1: [[1, 0.5, 2.5], [1, 3, 10]].
3. Subtract the first row from the second row to get a zero below the 1: [[1, 0.5, 2.5], [0, 2.5, 7.5]].
4. Divide the second row by 2.5: [[1, 0.5, 2.5], [0, 1, 3]].
5. Subtract 0.5 times the second row from the first: [[1, 0, 1], [0, 1, 3]].
Solution: x = 1, y = 3.

Frequently Asked Questions

What is the difference between Gaussian and Gauss-Jordan?

Gaussian elimination produces an upper triangular matrix (Row Echelon Form) requiring back-substitution. Gauss-Jordan produces a diagonal identity matrix (Reduced Row Echelon Form) where the answers appear directly in the final column.

What if the system has no solution?

A system is inconsistent (no solution) if a row in the RREF matrix has zeros in the coefficient positions but a non-zero value in the constant position (e.g., 0 = 5).

function generateMatrixInputs() { var size = parseInt(document.getElementById('matrixSize').value); var container = document.getElementById('matrixInputWrapper'); var html = ''; for (var i = 0; i < size; i++) { html += ''; for (var j = 0; j <= size; j++) { var placeholder = (j < size) ? 'x' + (j + 1) : 'Const'; var bgColor = (j === size) ? '#f0f8ff' : '#fff'; html += ''; if (j === size – 1) { html += ''; } } html += ''; } html += '
=
'; container.innerHTML = html; } function calculateGaussJordan() { var n = parseInt(document.getElementById('matrixSize').value); var matrix = []; // Build Matrix from inputs for (var i = 0; i < n; i++) { matrix[i] = []; for (var j = 0; j <= n; j++) { var val = parseFloat(document.getElementById('m_' + i + '_' + j).value); if (isNaN(val)) val = 0; matrix[i][j] = val; } } // Gauss-Jordan Logic for (var p = 0; p < n; p++) { // Find pivot var max = p; for (var i = p + 1; i Math.abs(matrix[max][p])) { max = i; } } // Swap rows var temp = matrix[p]; matrix[p] = matrix[max]; matrix[max] = temp; // Check for singularity if (Math.abs(matrix[p][p]) < 1e-10) { continue; } // Pivot normalization var pivotVal = matrix[p][p]; for (var j = p; j <= n; j++) { matrix[p][j] /= pivotVal; } // Elimination for (var i = 0; i < n; i++) { if (i !== p) { var factor = matrix[i][p]; for (var j = p; j <= n; j++) { matrix[i][j] -= factor * matrix[p][j]; } } } } displayResults(matrix, n); } function displayResults(matrix, n) { var resultArea = document.getElementById('resultArea'); var rrefOutput = document.getElementById('rrefOutput'); var solutionOutput = document.getElementById('solutionOutput'); resultArea.style.display = 'block'; var rrefHtml = ''; var solutions = []; var isConsistent = true; for (var i = 0; i < n; i++) { rrefHtml += ''; var rowZero = true; for (var j = 0; j <= n; j++) { var val = matrix[i][j]; // Round to 4 decimal places for display var displayVal = Math.abs(val) < 1e-10 ? 0 : parseFloat(val.toFixed(4)); rrefHtml += ''; if (j 1e-10) rowZero = false; } // Check for inconsistency (0 = non-zero) if (rowZero && Math.abs(matrix[i][n]) > 1e-10) { isConsistent = false; } rrefHtml += ''; solutions.push('x' + (i + 1) + ' = ' + (Math.abs(matrix[i][n]) < 1e-10 ? 0 : matrix[i][n].toFixed(4))); } rrefHtml += '
' + displayVal + '
'; rrefOutput.innerHTML = rrefHtml; if (!isConsistent) { solutionOutput.innerHTML = 'No Solution (System is Inconsistent)'; } else { var allZeros = true; for(var i=0; i<n; i++) { var diag = Math.abs(matrix[i][i]); if (diag < 1e-10) { allZeros = false; break; } } if (!allZeros) { solutionOutput.innerHTML = 'Infinite Solutions or Dependent System'; } else { solutionOutput.innerHTML = solutions.join("); } } resultArea.scrollIntoView({ behavior: 'smooth' }); } // Initialize generateMatrixInputs();

Leave a Comment