---
title: "Gauss-Jordan pseudo-code"
subject: "Numerical Method"
chapter: 3
key: "semester_4/numerical_method:gauss-jordan-pseudocode"
source: https://www.bctengineer.com/q/semester_4/numerical_method/gauss-jordan-pseudocode
site: BCT Engineering
---

# Gauss-Jordan pseudo-code

Numerical Method · Chapter 3: Solution of system of linear algebraic equations

- Asked in: 2075 Baisakh, 8 marks; 2072 Asoj, 8 marks; 2069 Bhadra, 8 marks; 2070 Bhadra, 8 marks (asked 4 times)
- Video: [Gauss Jordan Methods || Programming in C and Numerical Analysis || Lect-2](https://www.youtube.com/watch?v=B77dyE2u2o8) — sonia sachdeva
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_4/numerical_method/gauss-jordan-pseudocode
- Whole chapter: https://www.bctengineer.com/md/semester_4/numerical_method/chapter-3

## Question

Write a pseudo-code (algorithm) to solve a system of linear equations Ax = b of 'N' unknowns using the Gauss Jordan method.

## Short answer

Gauss-Jordan method reduces augmented matrix [A|b] to [I|x] by row operations. Algorithm: for k=1 to n, find pivot row with max |a[p][k]|, swap if needed, normalize pivot row, then eliminate column k from all other rows. Solution x[i] = a[i][n+1].

## Answer

Gauss-Jordan method reduces the augmented matrix [A | b] to [I | x] using row operations, so the solution is read directly without back substitution. Partial pivoting is included for safety.

#### Pseudo-code
```text
Algorithm: Gauss-Jordan method
Input : n, matrix a[1..n][1..n+1]  (augmented [A | b])
Output: solution x[1..n]

1.  Read n and the augmented matrix a
2.  For k = 1 to n do
3.      // partial pivoting
        Find row p (k <= p <= n) with largest |a[p][k]|
        If a[p][k] = 0 then
            print "No unique solution"; stop
        If p != k then swap row p and row k
4.      // normalise pivot row
        piv = a[k][k]
        For j = k to n+1 do
            a[k][j] = a[k][j] / piv
        End for
5.      // eliminate column k from all other rows
        For i = 1 to n do
            If i != k then
                m = a[i][k]
                For j = k to n+1 do
                    a[i][j] = a[i][j] - m * a[k][j]
                End for
            End if
        End for
6.  End for
7.  For i = 1 to n do
        x[i] = a[i][n+1]
    End for
8.  Print x[1..n]
9.  Stop
```

#### Notes
- The final coefficient matrix is the identity, so x[i] is the last column.
- Operations count is about n³/2 multiplications, more than Gauss elimination (n³/3).
- The same procedure applied to [A | I] gives the inverse of A.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. Gauss-Jordan reduces [A|b] to:
   A. [I | x]
   B. Upper triangular form
   C. [A | I]
   D. Zero matrix
   Answer: A. Solution is read directly. (Key point: Goal)

2. Column k is eliminated from:
   A. Only rows below
   B. All other rows
   C. Only rows above
   D. Only row k
   Answer: B. This differs from Gauss elimination. (Key point: Elimination)

3. Partial pivoting picks:
   A. Smallest entry
   B. First zero
   C. Row with largest |a[p][k]| and swaps
   D. Last row
   Answer: C. Improves stability. (Key point: Pivoting)

4. Compared with Gauss elimination, operations are:
   A. Fewer
   B. Same
   C. n^2
   D. About n^3/2 vs n^3/3, more
   Answer: D. Gauss-Jordan costs more. (Key point: Cost)

## Related in Numerical Method

- [Gauss elimination/Jordan with pivoting](https://www.bctengineer.com/question.md?key=semester_4%2Fnumerical_method%3Agauss-jordan-partial-pivoting) — Numerical Method, chapter 3, asked 2×
- [Gauss elimination, partial pivoting, 4 unknowns](https://www.bctengineer.com/question.md?key=semester_4%2Fnumerical_method%3Agauss-elimination-four-pivoting) — Numerical Method, chapter 3, asked 4×
- [Gauss-Seidel: four unknowns](https://www.bctengineer.com/question.md?key=semester_4%2Fnumerical_method%3Agauss-seidel-four-unknowns) — Numerical Method, chapter 3
- [Bisection method pseudo-code](https://www.bctengineer.com/question.md?key=semester_4%2Fnumerical_method%3Abisection-pseudocode) — Numerical Method, chapter 2, asked 3×
- [Gauss-Jordan inverse of matrix](https://www.bctengineer.com/question.md?key=semester_4%2Fnumerical_method%3Agauss-jordan-inverse-3x3) — Numerical Method, chapter 3
- [False position pseudo-code](https://www.bctengineer.com/question.md?key=semester_4%2Fnumerical_method%3Afalse-position-pseudocode) — Numerical Method, chapter 2, asked 2×

## Related in other subjects

- [Algorithm/pseudo-code for software PID](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3Apid-software-algorithm) — Embedded System, chapter 7, asked 3×
- [Algorithm versus pseudo-code](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Aalgorithm-vs-pseudocode) — Computer Programming, chapter 2
- [Is y[n] = ax[n] + b linear](https://www.bctengineer.com/question.md?key=semester_4%2Fsignals_and_systems%3Alinearity-affine-dt) — Signals and Systems, chapter 6, asked 4×
- [CG algorithm; Gauss-Seidel numerical](https://www.bctengineer.com/question.md?key=semester_8%2Fcomputational_techniques_in_civil_engineering%3Acg-algorithm-gauss-seidel-numerical) — Computational Techniques in Civil Engineering, chapter 2
