This article was originally posted on the public id: TechFlow

The concept of elementary transformation of matrices may sound strange to many people, but in fact, we used it as early as in junior high school when solving multiple equations. But in the textbook, it’s called elimination. Let’s start with an example from the textbook:


Suppose we want to solve this equation, how do we do it?

First, we add (1) to (2), (4) to (3), and multiply (1) by 6 to (4) to obtain:


We can solve for PI (4) minus PI (2) times 5:


We put thePlug in, and you can solve.


Because after elimination, the number of systems is less than the number of variables, we can’t solve for all of them. One of theYou can take any value.

The above calculation method is familiar to us. If we use a matrix to represent all degrees, the matrix D can be written as:


So, the elimination process that we just did, is essentially an elementary transformation of this matrix. To summarize the process, the elementary transformation operations of matrices include the following three kinds:

  1. The line two
  2. With severalTimes all the entries in a row
  3. With severalMultiply all the entries in one row and add them to the other row

All three of the above operations are for units of behavior, so they are also called “row operations.” We can also perform the same three operations on columns, called column transformations. The row transformation combined with the column transformation is the elementary transformation of the matrix.

Again, we can do the same thingThis matrix uses the elementary transformation operation we just described, to produce the following result:


It corresponds to the system of equations:


The matrix is the result of elementary row transformation, and we can do the column transformation to make it even easier, we can just swap the third and third columns, and then we can eliminate the fifth column by elementary column transformation, and then it looks like this:


We can easily prove by data induction that all m*n matrices can be transformed into the following form by a series of elementary transformations:


R is the number of non-zero rows in the simplest matrix, which is also called the rank of the matrix. We write the rank of A matrix as:

And as we said earlier when we introduced determinants, there are many other properties of determinants. One of them is a matrix that goes through an elementary transformation, and its determinant stays the same. And we know that if there’s a row or a column in the determinant that’s all 0, then the determinant is 0.

So, we can get, for the NTH order matrixIn terms of its rank, then.

According to the previous definition of invertible matrix, the rank of an invertible matrix is equal to the order of the matrix, while the rank of an irreversible matrix is smaller than the order of the matrix. Therefore, invertible matrices are also called full rank matrices, and irreversible matrices (singular matrices) are also called reduced rank matrices.

When we reviewed determinants and inverses, we thought something was missing, but now that we have the idea of the rank of a matrix, we can put it all together.

The code to calculate

Similarly, numpy inherits tools for calculating the rank of matrices. We can easily calculate the rank of a matrix with one line of code, so that we don’t have to look at the determinant to determine whether a matrix is invertible. Because the rank of a matrix is much faster to compute than the determinant.

import numpy as np
np.linalg.matrix_rank(a)
Copy the code

With the concept of matrix rank, our subsequent content is much more convenient to introduce, it is also one of the very important concepts in the field of matrices.

Solutions to linear systems of equations

Now that we understand the concept of the rank of a matrix, let’s see how it applies to linear systems of equations.

When we introduced the determinant, we showed that the solution to the system of n elements and n identities can be expressed as a determinant. But in reality, the system of equations we encounter is not necessarily n-element n-equality, so let’s generalize to the general case. Suppose we have a system of n-element m equations:


We can write this as a matrix product:


Where A is an m by n matrix,

We use the coefficient matrix A and the augmented matrixAnd can easily see whether the system of linear equations has a solution. Let’s start with the conclusion:

  1. There is no solution when R(A) is less than R(B)
  2. When R(A) = R(B) = n, there is A unique solution
  3. When R(A) = R(B) < n, there are infinite solutions

The proof process is also very simple, mainly using the rank of the matrix and the definition of the simplest matrix.

Let’s assume R(A)= R and reduce the B matrix to its simplest form, assuming that the result is:


Obviously, when R of A is less than R of B, then the matrixIn the, then the equation 0 = 1 corresponding to row r + 1 is contradictory, so the equation has no solution.

If R(A) = R(B) = R = n, then the matrixIn theAnd,So we can just write down the solution to the system:


In this case, the system has a unique solution

If R(A) = R(B) = R < n, then in B, we write the corresponding solution:


We makeBring, get:

Due to the parameterYou can take any value, so there’s an infinite number of solutions. The form of the solution written above is the general solution of the system of linear equations.

Homogeneous linear equations

If we set all the constant terms of the above linear system to 0, it is called the homogeneous linear system as follows:


The greatest characteristic of homogeneous systems is whenWhen, there must be a solution, called the zero solution of the system. We also use the augmented matrix to determine that it is written in the same form as before:


And unlike inhomogeneous linear systems, we can conclude thatIn such a way that there is no case where there is no solution. At this time, what we need to determine is whether the system of equations has non-zero solutions. We can also judge by the rank of the matrix. The judgment condition is also very simple: if R(A) = n, there are no non-zero solutions; if R(A) < n, there are countless groups of non-zero solutions. So let’s write the case where R of A is equal to n, the matrixTo:


In other words:

Due to the, so the unique solution is. When R(A) < n, the system is similar to the inhomogeneous system except that it can be determined, we can directly substitute into the previous general formula, and obtain:

The formulas and calculations of solutions to linear equations are not important in themselves. Because in the real world of algorithms, it’s not used much. However, understanding linear equations is very helpful for understanding the vectors and linear space behind. The formula in the article looks horrible, but if you calm down and really try to understand it, you will find that it is not true.

I sincerely hope you have a good harvest, if you like this article, please pay attention to it