Runoob Tutorial ArchiveEnglish

Rank of a system of linear equations and matrices

Rank of a system of linear equations and matrices

From the chicken and rabbit problem to AI model training, linear equations are everywhere. The "rank" of a matrix tells us how much truly effective information there is in the system of equations.

Any system of linear equations can be written as Ax = b

A is the coefficient matrix (m equations, n unknowns), x is the vector of unknowns, and b is the constant vector.

For example, the chicken and rabbit problem: ( \begin{cases} x+y=10 \\ 2x+4y=28 \end{cases} ) written in matrix form:

[ \begin{bmatrix} 1 & 1 \\ 2 & 4 \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} = \begin{bmatrix} 10 \\ 28 \end{bmatrix} ]

Rank: The number of independent pieces of information

Rank = the number of truly "independent" rows (or columns) in a matrix.

If one equation can be obtained by multiplying another equation by a coefficient, it is redundant—it does not add new information.

The rank determines the solution status of a system of equations:

**

Full rank

Unique solution

No redundancy between equations

**

Deficient rank

Infinite solutions

Redundant equations

**

Contradiction

No solution

Equations contradict each other


Real-life example

**Chicken and Rabbit in a Cage: Full rank, unique solution

10 heads + 28 legs → 6 chickens, 4 rabbits. Two equations provide two independent pieces of information, just enough to solve for two unknowns.

**Redundant information: Deficient rank, infinite solutions

Equation one: x + y = 5. Equation two: 2x + 2y = 10 (which is 2 times equation one).

The two equations are actually just one piece of information—there are infinitely many pairs of (x, y) that satisfy the condition.


Mathematical definition

Rank determination

Condition Nature of the solution
rank(A) = rank([A|b]) = n Unique solution
rank(A) = rank([A|b]) < n Infinitely many solutions
rank(A) < rank([A|b]) No solution

Where [A|b] is the augmented matrix with b appended to the right of A.


Python hands-on practice

Example

import

numpy

as

np

Chicken and rabbit in the cage: full rank

A

=

np.

array

(

[

[

1

,

1

]

,

[

2

,

4

]

]

)

b

=

np.

array

(

[

10

,

28

]

)

x

=

np.

linalg

.

solve

(

A

,

b

)

print

(

"Solution:"

,

x

,

"→ chicken=6, rabbit=4"

)

print

(

"Rank:"

,

np.

linalg

.

matrix_rank

(

A

)

)

 

2 (full rank)

Redundant equations

A_red

=

np.

array

(

[

[

1

,

2

]

,

[

2

,

4

]

]

)

 

Row 2 = 2 * Row 1

print

(

"Rank of the redundant matrix:"

,

np.

linalg

.

matrix_rank

(

A_red

)

)

 

1

Rank of a random matrix

big

=

np.

random

.

randn

(

100

,

50

)

print

(

"Rank of a 100x50 random matrix:"

,

np.

linalg

.

matrix_rank

(

big

)

)

 

50

Original prompt (Chinese, left untranslated)



解: [6. 4.] → 鸡=6, 兔=4

秩: 2(满秩)

冗余矩阵的秩: 1

100×50 随机矩阵的秩: 50


Application scenarios in AI

LoRA fine-tuning = low-rank assumption

The core assumption of LoRA (Low-Rank Adaptation): the fine-tuning update amount \Delta W of the pre-trained weights is low-rank. Therefore, the full update amount \Delta W = AB can be approximated by the product of two small matrices A (d×r) and B (r×d), where r << d.

For example, for a 12288-dimensional weight matrix of GPT-3, r of 8 or 16 is sufficient—the rank is reduced from 12288 to 8, reducing the number of parameters by thousands of times. This is how parameter-efficient fine-tuning is done by utilizing the concept of "rank."

Feature Collinearity Detection

The rank of the data matrix is much smaller than the number of columns $\rightarrow$ there is high collinearity (multicollinearity) between features $\rightarrow$ $X^TX$ in linear regression is non-invertible or nearly singular $\rightarrow$ regularization (Ridge/Lasso) or dimensionality reduction (PCA) is required. In practical ML projects, this manifests as a large condition number of the feature matrix.

Matrix Completion in Recommender Systems

The user-item rating matrix usually has only a few ratings (sparse), but it is assumed to be generated by a low-rank structure (similar users have similar tastes). Matrix Completion utilizes the constraint of rank to infer missing ratings through known ratings. This is the core idea of the winning algorithm in the Netflix recommendation competition.