VOOZH about

URL: https://www.geeksforgeeks.org/dsa/gaussian-elimination/

⇱ Gaussian Elimination to Solve Linear Equations - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Gaussian Elimination to Solve Linear Equations

Last Updated : 13 May, 2026

The Gaussian Elimination Method is a widely used technique for solving systems of linear equations, where multiple equations with unknown variables are solved simultaneously to find the values of the unknowns. This method has practical applications in real life, such as in traffic flow analysis, where it helps solve systems representing traffic movement at intersections, optimising the flow of traffic and reducing congestion.

In LU decomposition, Gaussian elimination is used to convert the matrix A into an upper triangular matrix (U).

Categories of Linear Equation Systems:

  • Consistent Independent System: Has exactly one solution.
  • Consistent Dependent System: Has infinite solutions.
  • Inconsistent System: Has no solution.

Gaussian Elimination Method

Gaussian elimination is a row reduction algorithm for solving linear systems. It involves a series of operations on the augmented matrix (which includes both coefficients and constants) to simplify it into a row echelon form or reduced row echelon form. This method can also help in determining the rank, determinant and inverse of matrices. Gaussian elimination is a method for solving systems of equations in matrix form.

Let's, for example, we have a system of linear equations:


a

Matrix form of this system of linear equations:

Goal:

Turn matrix into row-echelon form like, .

Once in this form, we can say that 𝑧 = 𝑓 and use back substitution to solve for y and x.

Elementary Row Operations

  1. Interchanging Rows: Swap two rows.
  2. Multiplying a Row by a Scalar: Multiply all elements of a row by a non-zero number.
  3. Adding a Scalar Multiple of One Row to Another: Add or subtract a multiple of one row to/from another.

These operations simplify solving systems of linear equations without changing the solution set.

πŸ‘ matrix-660
Elementary Row Operations

Follow these steps:

  1. Get a 1 in the first column, first row
  2. Use the 1 to get 0’s in the remainder of the first column
  3. Get a 1 in the second column, second row
  4. Use the 1 to get 0’s in the remainder of the second column
  5. Get a 1 in the third column, third row.

The resulting matrix is in row echelon form. A matrix is in reduced row-echelon form if all leading coefficients are 1 and the columns containing these leading coefficients have zeros elsewhere. This final form is unique, regardless of the sequence of row operations used. An example below illustrates this concept.

Example

To solve the system of equations:

  1. x+y=3
  2. 3x-2y=4

Step 1: Write the Coefficient Matrix

The coefficients of the unknowns (x and y) are written as a matrix:

Step 2: Write the Augmented Matrix

Include the constants from the right-hand sides of the equations as an additional column:

Step 3: Perform Row Operations

The goal is to simplify the augmented matrix to solve for x and y.

Subtract from (to eliminate the x-term in the second row):

Calculation:

Simplify the second row:
Divide ​ by βˆ’5 to solve for y:

Result:

Step 4: Back-Substitute

Use the second row (y=1) to substitute into the first row (x + y = 3): x + 1 = 3β€…β€ŠβŸΉβ€…β€Šx= 2

Solution

The solution to the system is: (x, y )=(2, 1)

Other algorithm in Gaussian elimination to solve Linear Equations

  1. Partial Pivoting: Select the pivot element with the largest absolute value from the column. Swap rows to move this element into the pivot position. This improves numerical stability by reducing rounding errors.
  2. Elimination: For each row below the pivot, subtract a multiple of the pivot row to eliminate the entries below the pivot.

Implementation of Gaussian Elimination to solve Linear Equations

1. Back Substitution

We use back-substitution to find the values of the unknowns after obtaining the row echelon form. The steps are:

  1. Start with the last row of the row echelon form.
  2. Solve for the last variable by dividing the constant term by its coefficient.
  3. Substitute the known value of the last variable into the previous rows.
  4. Solve for the next variable by isolating it and using the known values of the other variables.
  5. Repeat the process for all rows, moving upwards to the first row.
  6. Once all variables are solved, the system is complete and the solution is found.

Below is the implementation of the above algorithm.  


Output
Solution for the system:
3.000000
1.000000
2.000000


Illustration:

2. Partial Pivoting

The steps involved in Partial Pivoting Gaussian Elimination are:

  1. Start with the given augmented matrix.
  2. Find the row with the largest absolute value in the first column and swap that row with the first row.
  3. Divide the first row by the pivot element to make it equal to 1.
  4. Use the first row to eliminate the first column in all other rows by subtracting the appropriate multiple of the first row from each row.
  5. Repeat steps 2-4 for the remaining columns, using the row with the largest absolute value as the pivot row for each column.
  6. Back-substitute to obtain the values of the unknowns.

Output
Solution for the system:
3
1
2

Applications of Gaussian Elimination Method

  • Computing Determinants: It simplifies finding the determinant of a square matrix by reducing it to row echelon form. The determinant is calculated by multiplying the diagonal elements and adjusting for row swaps and scalar multiplications.
  • Finding the Inverse of a Matrix: Gauss–Jordan elimination, a variant of Gaussian elimination, is used to find the inverse of a matrix. By augmenting the matrix with the identity matrix and applying row operations, the matrix is transformed into the inverse if it exists.
  • Computing Ranks and Bases: It can be applied to any matrix to determine its rank and the basis for its column space. The row echelon form reveals information about the number of linearly independent rows and the columns that form a basis for the matrix's column space.

Practice Problems

1. Solve the following system of equations using Gaussian elimination method.

x + y + z = 6
3x + y + 6z = 10
2x +4 y – z = 1

2. Solve the following linear system using the Gaussian elimination method.

x – y = -6
6x – 2y = 0

3. Using Gaussian elimination method, solve:

x – 9y + 3z = 1
x + y + z = 4
2x – y + z = 2

Comment
Article Tags: