Linear algebra · solving systems
Matrix Division: Solving Ax = b and xA = b
Matrix division is not division in the arithmetic sense. No operation produces “one over a matrix” that you can multiply by. What matrix languages call division is a compact way to solve a linear system: given a matrix A and a right-hand side b, find x so that Ax = b, or find a row x so that xA = b. The two forms are called left division and right division, and each has its own operator.
Two operators, two equations
Written in MATLAB-style notation, A\b is left division and means “the x that satisfies Ax = b”. The backslash points at A because A sits on the left of the unknown. Right division b/A means “the row vector x that satisfies xA = b”, with A on the right of the unknown. The two are related by a transpose: b/A equals (Aᵀ\bᵀ)ᵀ.
Scalars are the special case you already know. For a 1 × 1 matrix A = a, A\b is b/a, and the slash and backslash agree. Once A has more than one entry the order of the factors matters, because matrix multiplication does not commute. That is the whole reason there are two operators.
Mathematically, when A is square and invertible, A\b equals A⁻¹b. Numerically, no competent implementation forms the inverse. It factors A (see LU factorization) and then runs two triangular solves, which is both faster and more accurate than computing A⁻¹ and multiplying.
A worked example
Take A = [2 1; 0 3] and b = [4 5]. Left division asks for a column x with Ax = bᵀ, where the column is written as (x₁, x₂):
2x₁ + x₂ = 4, 3x₂ = 5.
The second equation gives x₂ = 5/3. Substituting back, 2x₁ = 4 − 5/3 = 7/3, so x₁ = 7/6. The answer is x = (7/6, 5/3). Check the first equation: 2 · 7/6 + 5/3 = 7/3 + 5/3 = 4. Correct.
Right division with the same A and the row b = [4 5] asks for x = [x₁ x₂] with xA = b. Multiplying out gives 2x₁ = 4 and x₁ + 3x₂ = 5. So x₁ = 2, and then 3x₂ = 3 gives x₂ = 1. The answer is the row [2 1]. Check: [2 1] times A is [2·2 + 1·0, 2·1 + 1·3] = [4 5]. The two results differ, which is the point: A\b and b/A answer different questions.
A = [2 1; 0 3]
x = A \ [4; 5] % column (7/6, 5/3)
y = [4 5] / A % row (2, 1)
What the operator does when A is not a nice square
For a square system the solver picks a method from the structure of A. A triangular matrix goes straight to substitution. A symmetric positive definite matrix can use a Cholesky factorization. Anything else typically gets LU with partial pivoting. Checking structure first is cheap compared with the cubic cost of the factorization itself.
If A is rectangular, the system is either overdetermined (more equations than unknowns) or underdetermined. Then division no longer gives an exact solution; it returns a least-squares answer instead. That case has its own page, left division and least squares.
If A is square but singular, there is no unique solution. Good implementations warn, and the warning deserves attention. A matrix can also be so close to singular that the computed x is mostly rounding error, with no warning at all. The condition number of A estimates how much relative error in b can be amplified in x; a value near 10¹⁶ in double precision means essentially no correct digits are left.
Habits that avoid trouble
Never write inv(A)*b when A\b is available. When solving against many right-hand sides, pass them as columns of one matrix B so that the factorization is done once: A\B solves every column together. And when a vector has to be divided entry by entry, you want a different operator altogether, the dotted one covered under element-by-element multiplication.
Terms such as singular matrix and condition number are defined in the glossary. More factorizations and solvers sit together in the linear algebra section.