MatrixStep

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

A =2113B =105210
  1. 01
    Attach all of B to the right of A to form [A | B].
    2110513210
  2. 02
    Move a nonzero entry of column 1 up to row 1 to use as the pivot.
    R₁ ↔ R₂
    1321021105
  3. 03
    Make every other entry of column 1 zero.
    R₂ ← R₂ − 2R₁
    132100−5−3−25
  4. 04
    Divide row 2 by the pivot so the pivot becomes 1.
    R₂ ← (−1/5)R₂
    13210013525−1
  5. 05
    Make 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.

X =15−1533525−1

Check

2113·15−1533525−1=105210

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.

XC = D, C =1201D =3411

Solving CᵀY = Dᵀ gives Y = 31−2−1, so

X = Yᵀ =3−21−1

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.

S =1224B₁ =1326B₂ =1327

The test is exactly the same as for the number of solutions of a linear system: compare the ranks.

Common mistakes

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