TExcelTAD
Home › Linear Algebra & Matrix Theory › Algebraic View of Systems of Equations

Algebraic View of Systems of Equations

Pictures stop helping beyond three variables, so we need precise algebraic language: what a linear equation is, what counts as a solution, and how to store a whole system compactly as a matrix. This vocabulary is used in every later lesson.

Definitions

A linear equation in the variables x1,x2,…,xnx_1, x_2, \ldots, x_n has the form

a1x1+a2x2+⋯+anxn=ba_1x_1 + a_2x_2 + \cdots + a_nx_n = b

where the coefficients a1,…,ana_1, \ldots, a_n and the constant term bb are numbers. Variables appear only to the first power, multiplied by constants, and never multiplied with each other.

A system of linear equations is a finite list of such equations in the same variables. A solution is an assignment of numbers to x1,…,xnx_1, \ldots, x_n that makes every equation true at the same time. The solution set is the set of all solutions. Two systems are equivalent if they have the same solution set.

A system is consistent if it has at least one solution and inconsistent if it has none.

Matrices of a system

Writing x1,x2,…x_1, x_2, \ldots over and over is wasteful. All the information sits in the numbers, which we arrange in a rectangular table, a matrix:

x1+2x2−x3=22x1−x2+3x3=94x2+x3=6[12−12−13041]⏟coefficient matrix[12−122−1390416]⏟augmented matrix\begin{aligned} x_1 + 2x_2 - x_3 &= 2 \\ 2x_1 - x_2 + 3x_3 &= 9 \\ 4x_2 + x_3 &= 6 \end{aligned} \qquad \underbrace{\begin{bmatrix} 1 & 2 & -1 \\ 2 & -1 & 3 \\ 0 & 4 & 1 \end{bmatrix}}_{\text{coefficient matrix}} \qquad \underbrace{\left[\begin{array}{rrr|r} 1 & 2 & -1 & 2 \\ 2 & -1 & 3 & 9 \\ 0 & 4 & 1 & 6 \end{array}\right]}_{\text{augmented matrix}}

The coefficient matrix AA holds the coefficients, one row per equation and one column per variable (a missing variable gets a 0). The augmented matrix [A∣b][A \mid \mathbf{b}] adds the constants as a final column. With the vector x=(x1,x2,x3)\mathbf{x} = (x_1, x_2, x_3) the whole system is the single equation Ax=bA\mathbf{x} = \mathbf{b}.

python · try it yourself
from sympy import Matrix

A = Matrix([[1, 2, -1], [2, -1, 3], [0, 4, 1]])
b = Matrix([2, 9, 6])
aug = A.row_join(b)          # glue b on as an extra column
print("augmented shape:", aug.shape)
for row in aug.tolist():
    print(row)

x = Matrix([1, 1, 2])        # a candidate solution
print("A*x =", list(A * x), " b =", list(b), " solution?", A * x == b)
augmented shape: (3, 4)
[1, 2, -1, 2]
[2, -1, 3, 9]
[0, 4, 1, 6]
A*x = [1, 7, 6]  b = [2, 9, 6]  solution? False

The candidate (1,1,2)(1, 1, 2) satisfies only the third equation, so it is not a solution. Checking a proposed solution is easy: multiply and compare. Finding solutions needs elimination.

Describing infinitely many solutions

When a system has infinitely many solutions, we describe them with parameters. Take

x1−x2+2x3=3x_1 - x_2 + 2x_3 = 3

One equation, three unknowns. Choose x2=sx_2 = s and x3=tx_3 = t freely; then x1=3+s−2tx_1 = 3 + s - 2t. The solution set is

(x1,x2,x3)=(3+s−2t, s, t)for all numbers s,t(x_1, x_2, x_3) = (3 + s - 2t,\ s,\ t) \qquad \text{for all numbers } s, t

This is the general solution in parametric form; ss and tt are free parameters, and each choice of them gives one particular solution. Geometrically it is a plane in R3\mathbb{R}^3.

python · try it yourself
from sympy import symbols, linsolve

x1, x2, x3 = symbols("x1 x2 x3")
print(linsolve([x1 - x2 + 2*x3 - 3], [x1, x2, x3]))

# check a few particular solutions
for s, t in [(0, 0), (1, 0), (2, 5)]:
    p = (3 + s - 2*t, s, t)
    print(p, "->", p[0] - p[1] + 2*p[2])
{(x2 - 2*x3 + 3, x2, x3)}
(3, 0, 0) -> 3
(4, 1, 0) -> 3
(-5, 2, 5) -> 3

SymPy's linsolve writes the same answer with x2x_2 and x3x_3 themselves acting as parameters. SymPy prints x1 and 2*x3 in Python syntax.

Not linear, and why it matters

Equation Linear? Reason
3x1−0.5x2=π3x_1 - 0.5x_2 = \pi yes constants may be any numbers
x1x2=1x_1x_2 = 1 no product of variables
x1+x2=4\sqrt{x_1} + x_2 = 4 no function of a variable
sin⁡(2)⋅x1=x2\sin(2) \cdot x_1 = x_2 yes sin⁡(2)\sin(2) is just a constant

Linear systems are special because their solution sets are always "flat" (points, lines, planes and their higher-dimensional cousins) and because a finite, mechanical algorithm decides everything about them. Nonlinear systems have no such guarantee.

In software

  • In ML, fitting a linear model writes one equation per data point: thousands of equations, a handful of unknowns (the weights). Such a system is usually inconsistent, which leads to least squares.
  • Circuit simulators like SPICE and structural-engineering (finite element) codes assemble a coefficient matrix and a right-hand side and hand them to a solver.

Exercises

Exercise 1: Write the augmented matrix

Write the augmented matrix of 3x−z=43x - z = 4, x+y+z=0x + y + z = 0, 2y=52y = 5 (variables in the order x,y,zx, y, z).

Answer

[30−1411100205]\left[\begin{array}{rrr|r} 3 & 0 & -1 & 4 \\ 1 & 1 & 1 & 0 \\ 0 & 2 & 0 & 5 \end{array}\right].

Solution

Each row lists the coefficients of x,y,zx, y, z, with 0 for a missing variable, and then the constant: 3x+0y−1z=43x + 0y - 1z = 4, 1x+1y+1z=01x + 1y + 1z = 0, 0x+2y+0z=50x + 2y + 0z = 5.

Exercise 2: Back to equations

Which system has augmented matrix [104−101−23]\left[\begin{array}{rrr|r} 1 & 0 & 4 & -1 \\ 0 & 1 & -2 & 3 \end{array}\right]? Give its general solution.

Answer

x1+4x3=−1x_1 + 4x_3 = -1, x2−2x3=3x_2 - 2x_3 = 3; general solution (−1−4t,3+2t,t)(-1 - 4t, 3 + 2t, t).

Solution
x1+4x3=−1→x1=−1−4x3x2−2x3=3→x2=3+2x3x3=t free→(x1,x2,x3)=(−1−4t,3+2t,t)\begin{aligned} &x_1 + 4x_3 = -1 &&\to x_1 = -1 - 4x_3 \\ &x_2 - 2x_3 = 3 &&\to x_2 = 3 + 2x_3 \\ &x_3 = t \text{ free} &&\to (x_1, x_2, x_3) = (-1 - 4t, 3 + 2t, t) \end{aligned}

Exercise 3: Solution checker (code)

Write is_solution(A, b, x) with SymPy and test whether (2,−1,1)(2, -1, 1) solves the system in the lesson (A=[12−12−13041]A = \begin{bmatrix} 1 & 2 & -1 \\ 2 & -1 & 3 \\ 0 & 4 & 1 \end{bmatrix}, b=(2,9,6)\mathbf{b} = (2, 9, 6)).

Answer

No: A⋅x=(−1,8,−3)≠(2,9,6)A \cdot \mathbf{x} = (-1, 8, -3) \ne (2, 9, 6).

Solution
python · try it yourself
from sympy import Matrix

def is_solution(A, b, x):
    return Matrix(A) * Matrix(x) == Matrix(b)

A = [[1, 2, -1], [2, -1, 3], [0, 4, 1]]
print(list(Matrix(A) * Matrix([2, -1, 1])), is_solution(A, [2, 9, 6], [2, -1, 1]))
[-1, 8, -3] False

Exercise 4: Solve the lesson's system (code)

Find the actual solution of the 3×33 \times 3 system in the lesson with SymPy and check it.

Answer

x=(2,1,2)\mathbf{x} = (2, 1, 2).

Solution
python · try it yourself
from sympy import Matrix

A = Matrix([[1, 2, -1], [2, -1, 3], [0, 4, 1]])
b = Matrix([2, 9, 6])
x = A.solve(b)
print(list(x), A * x == b)
[2, 1, 2] True

Test yourself

How many columns does the augmented matrix of a system with 4 equations in 3 unknowns have?

  1. 3
  2. 4
  3. 5
  4. 7

A system is called inconsistent when…

  1. it has more equations than unknowns
  2. it has no solution
  3. it has infinitely many solutions
  4. its coefficients are fractions

Which equation is linear in x1x_1 and x2x_2?

  1. x12+x2=1x_1^2 + x_2 = 1
  2. x1x2=3x_1x_2 = 3
  3. e2⋅x1−x2=0e^2 \cdot x_1 - x_2 = 0
  4. 1x1+x2=2\frac{1}{x_1} + x_2 = 2