Guides7 min
How to Solve the Matrix Equation AX = B
When the b in Ax = b is a matrix rather than a vector, the equation becomes AX = B. There is nothing to fear. Each column of B is its own linear system, and one wide augmented matrix eliminates them all at once. This guide shows the solution on a 2×2 example, then covers the XA = B form and the case with no solution.
AX = B is several linear systems
If A is n×n and B is n×p, then X is n×p as well. The j-th column of AX is A·(j-th column of X), so there are p linear systems A·xⱼ = bⱼ. The coefficient matrix A is the same for all of them, so there is no reason to solve them separately. Form [A | B] and eliminate once.
If A is invertible, X = A⁻¹B is the unique solution. But you do not need to compute the inverse first. When elimination finishes, X appears directly on the right.
Example: 2×2 A, 2×3 B
- 01Attach all of B to the right of A to form [A | B].2110513210
- 02Move a nonzero entry of column 1 up to row 1 to use as the pivot.
R₁ ↔ R₂1321021105 - 03Make every other entry of column 1 zero.
R₂ ← R₂ − 2R₁132100−5−3−25 - 04Divide row 2 by the pivot so the pivot becomes 1.
R₂ ← (−1/5)R₂13210013525−1 - 05Make every other entry of column 2 zero.
R₁ ← R₁ − 3R₂1015−153013525−1
The left side has become the identity matrix, so the right side is X.
Check
Solving with the inverse gives the same thing. det(A) = 5, A⁻¹ = 35−15−1525, and multiplying A⁻¹B gives the X above. Looking at the third column (5, 0) alone, this is the same as saying the solution of 2x + y = 5, x + 3y = 0 is (3, −1).
Solve the XA = B form by transposing
When X is on the left, the equation does not split into columns. Transposing both sides gives (XA)ᵀ = AᵀXᵀ = Bᵀ, which has the form AᵀY = Bᵀ; find Y = Xᵀ and transpose back.
Solving CᵀY = Dᵀ gives Y = 31−2−1, so
Check: XC = 3411 = D. In the calculator, enter Aᵀ and Bᵀ, take the resulting Xᵀ, and transpose it.
When A is singular
If det(A) = 0, you cannot use X = A⁻¹B. You can still eliminate, and there are two possible outcomes.
- SX = B₁: the two rows of B₁ are in the same 2-to-1 ratio as S, so elimination produces a 0 = 0 row. There are infinitely many solutions. (rank [S | B₁] = rank S = 1)
- SX = B₂: the second row is not in that ratio, so a row 0 = (nonzero number) appears. There is no solution. (rank [S | B₂] = 2 > rank S)
The test is exactly the same as for the number of solutions of a linear system: compare the ranks.
Common mistakes
- Solving XA = B as X = A⁻¹B. Order matters in matrix multiplication, so X = BA⁻¹. If in doubt, transposing to AᵀXᵀ = Bᵀ is the safe route.
- Eliminating separately for each column of B. Not wrong, but it repeats the same elimination p times. Do it once with [A | B].
- Mismatched sizes. If A is n×n, then B is n×p and X is n×p. If B has a different number of rows from A, the equation does not even make sense.
FAQ
What if B is the identity matrix?
The solution of AX = I is X = A⁻¹. Finding the inverse by Gauss-Jordan elimination on [A | I] is exactly this special case.
What if A is not square?
For an m×n matrix A, AX = B has no inverse to use, so it usually has either no solution or infinitely many. Solve it column by column with the linear system calculator, or if there is no solution, find the least-squares solution from AᵀAX = AᵀB.
Where do I enter B in the calculator?
In the AX = B calculator there is an input for B next to A, and you can change the number of columns of B. The number of rows is set automatically to match A.
Related guides