MINHTPC's blog

By MINHTPC, 12 months ago, In English

Gauss-Jordan Elimination — Introduction

Given a system of $$$n$$$ linear algebraic equations (SLAE) with $$$m$$$ variables, we are asked to solve it (i.e., determine whether it has no solution, a unique solution, or infinitely many solutions). In the case of at least one solution, return any one of them.

In short, we are given the following system of equations:

$$$ \begin{cases} a_{11}x_1 + a_{12}x_2 + \cdots + a_{1m}x_m = b_1 \\ a_{21}x_1 + a_{22}x_2 + \cdots + a_{2m}x_m = b_2 \\ \vdots \\ a_{n1}x_1 + a_{n2}x_2 + \cdots + a_{nm}x_m = b_n \end{cases} $$$

where $$$a_{ij}$$$ ($$$1 \le i \le n,\ 1 \le j \le m$$$) and $$$b_i$$$ ($$$1 \le i \le n$$$) are known constants, and $$$x_i$$$ ($$$1 \le i \le m$$$) are the unknowns.

Alternatively, the system can be represented in matrix form as:

$$$Ax = b$$$

where $$$A$$$ is an $$$n \times m$$$ matrix of coefficients $$$a_{ij}$$$, and $$$b$$$ is an $$$n$$$-dimensional vector of constants.

This method can also be applied when the system has modular constraints:

$$$ \begin{cases} a_{11}x_1 + a_{12}x_2 + \cdots + a_{1m}x_m \equiv b_1 \ (\text{mod } p) \\ a_{21}x_1 + a_{22}x_2 + \cdots + a_{2m}x_m \equiv b_2 \ (\text{mod } p) \\ \vdots \\ a_{n1}x_1 + a_{n2}x_2 + \cdots + a_{nm}x_m \equiv b_n \ (\text{mod } p) \end{cases} $$$

The Algorithm

The Gauss-Jordan elimination method sequentially eliminates variables to reduce the system to a simpler form and then solves it. Specifically, we use the first equation to eliminate $$$x_1$$$ from the remaining $$$n-1$$$ equations, transforming them into a new system. This continues by eliminating $$$x_2$$$, and so on.

Two elementary row operations are used:

  • Multiply an equation by a non-zero constant $$$r$$$.
  • Add one equation to another (after possibly scaling it).

These operations preserve the solution set.

To perform Gauss elimination, for each variable $$$x_i$$$ ($$$1 \le i \le \min(n, m)$$$):

  1. Find an unused equation with $$$a_{ei} \neq 0$$$:
  • If found: divide all coefficients of that equation by $$$a_{ei}$$$, mark the equation as used, and eliminate $$$x_i$$$ from other equations.
  • If not found: $$$x_i$$$ is a free variable.
  1. For each remaining equation $$$r$$$, subtract $$$a_{ri}$$$ times the pivot row (equation $$$e$$$). This sets all other $$$a_{ri} = 0$$$ while maintaining $$$a_{ei} = 1$$$.

After elimination, solve from bottom to top:

  • If $$$n \lt m$$$, then $$$x_i$$$ with $$$i \gt n$$$ are free variables.
  • Assume all free variables are 0 (or arbitrary if finding general solution).
  • For each dependent variable, solve using the row where it was eliminated.

Finally, check for consistency:

  • If any row simplifies to $$$0 = c$$$ with $$$c \neq 0$$$, the system has no solution.
  • Otherwise, if at least one free variable exists, there are infinitely many solutions; else, there is a unique solution.

Example

We use an $$$n \times (m+1)$$$ augmented matrix to represent the system. Each row is an equation; the first $$$m$$$ numbers are coefficients, the last is the constant term.

Given:

$$$ \begin{cases} x + 5y + 3z - 4t = 19 \\ 3x + 16y + 7z - 9t = 42 \\ -2x - 8y - 9z + 3t = -61 \end{cases} $$$

Matrix:

$$$ \begin{pmatrix} 1 & 5 & 3 & -4 & 19 \\ 3 & 16 & 7 & -9 & 42 \\ -2 & -8 & -9 & 3 & -61 \end{pmatrix} $$$

Step 1: Eliminate $$$x$$$

  • Row2 -= 3 * Row1
  • Row3 += 2 * Row1
$$$ \begin{pmatrix} 1 & 5 & 3 & -4 & 19 \\ 0 & 1 & -2 & -3 & -15 \\ 0 & -2 & -3 & -5 & -23 \end{pmatrix} $$$

Step 2: Eliminate $$$y$$$

  • Row1 -= 5 * Row2
  • Row3 += 2 * Row2
$$$ \begin{pmatrix} 1 & 0 & 13 & -19 & 94 \\ 0 & 1 & -2 & -3 & -15 \\ 0 & 0 & 1 & -11 & 7 \end{pmatrix} $$$

Step 3: Eliminate $$$z$$$

  • Row1 -= 13 * Row3
  • Row2 += 2 * Row3
$$$ \begin{pmatrix} 1 & 0 & 0 & 124 & 3 \\ 0 & 1 & 0 & -19 & -1 \\ 0 & 0 & 1 & -11 & 7 \end{pmatrix} $$$

Let $$$t = 0$$$:

$$$ \begin{cases} x = 3 \\ y = -1 \\ z = 7 \\ t = 0 \end{cases} $$$

Since $$$t$$$ is a free variable, there are infinitely many solutions. Another valid one is:

$$$ \begin{cases} x = -121 \\ y = 18 \\ z = 18 \\ t = 1 \end{cases} $$$

Conclusion

In this part, we’ve introduced the Gauss-Jordan elimination method and applied it to a sample problem.

In the next section, we’ll explore competitive programming problems that use this technique, share implementation tips, and provide clean code samples.

  • Vote: I like it
  • +6
  • Vote: I do not like it

»
12 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Thanks to everyone who read my blog . That is a little knowledge if you have tips or diffrent ideas , you can share at here . We are good communnity so we share and together become more better.