Matrix Equation: How to Solve AX = B with Examples

#Algebra
TL;DR
A matrix equation writes a system of linear equations in the compact form AX=BAX = B, where AA holds the coefficients, XX the unknowns, and BB the constants. This article shows how to build the equation, solve it with X=A−1BX = A^{-1}B, decide when a unique solution exists (det⁡A≠0\det A \neq 0), and avoid the order and singular-matrix mistakes.
MV
Madhukar VLast updated on June 27, 202611 min read

The Equation That Solves a Hundred Equations at Once

A power-grid engineer can face a hundred linear equations that must all hold at once. Economists modelling a market and graphics programmers lighting a scene hit the same wall, and writing those equations one by one is hopeless. The matrix equation collapses the entire system into three letters, AX=BAX = B, and hands it to a single, reliable solving rule. One compact statement, and the whole tangle becomes solvable.

What a Matrix Equation Is

A matrix equation is an equation of the form AX=BAX = B, where AA is the coefficient matrix, XX is the column matrix of unknown variables, and BB is the column matrix of constants. It is the matrix form of a system of linear equations: every equation in the system becomes one row of AA paired with one entry of BB.

For example, the system

2x+3y=52x + 3y = 5

4x−y=14x - y = 1

becomes the matrix equation

[23 4−1][x y]=[5 1]\begin{bmatrix} 2 & 3 \ 4 & -1 \end{bmatrix}\begin{bmatrix} x \ y \end{bmatrix} = \begin{bmatrix} 5 \ 1 \end{bmatrix}

The first matrix is AA, the column of variables is XX, and the column of constants is BB. Solving the matrix equation means finding the XX that makes the product equal BB. This is the same problem as solving a system of equations — only written so a single operation can finish it.

How Do You Write a System as a Matrix Equation?

Three steps turn any linear system into AX=BAX = B.

  1. Line up the variables. Write each equation with the same variables in the same order, filling in a coefficient of 0 where a variable is missing.

  2. Build AA from the coefficients. Each row of AA is one equation's coefficients, in variable order.

  3. Build XX and BB. XX is the column of variables; BB is the column of the right-hand-side constants.

Take the system 3x−2y=73x - 2y = 7 and x+5y=−4x + 5y = -4. Lined up, the coefficients are (3,−2)(3, -2) and (1,5)(1, 5), so

A=[3−2 15],X=[x y],B=[7 −4]A = \begin{bmatrix} 3 & -2 \ 1 & 5 \end{bmatrix}, \quad X = \begin{bmatrix} x \ y \end{bmatrix}, \quad B = \begin{bmatrix} 7 \ -4 \end{bmatrix}

The missing-variable rule matters. If one equation reads 2x=62x = 6 in a two-variable system, its row is (2,0)(2, 0), not (2)(2) — the zero holds the place of yy.

How to Solve a Matrix Equation

The standard route is the inverse matrix method. Just as you solve 3x=123x = 12 by multiplying both sides by 13\tfrac{1}{3}, you solve AX=BAX = B by multiplying both sides on the left by A−1A^{-1}:

AX=BAX = B

A−1AX=A−1BA^{-1}AX = A^{-1}B

IX=A−1BIX = A^{-1}B

X=A−1BX = A^{-1}B

Here II is the identity matrix, which leaves XX unchanged, so the solution is

X=A−1B\boxed{X = A^{-1}B}

The whole method rests on AA having an inverse. The inverse of a matrix exists only when its determinant is non-zero. So before solving, check det⁡A\det A.

Variable glossary. AA is the coefficient matrix; XX is the column of unknowns; BB is the column of constants; A−1A^{-1} is the inverse of AA; II is the identity matrix; det⁡A\det A is the determinant of AA.

A note on which method to reach for. The inverse method is clean for a 2×22 \times 2 system you are solving once. For larger systems, finding A−1A^{-1} is heavy, and Cramer's rule or Gaussian elimination is usually faster and more numerically stable. The inverse method teaches the idea best; the others scale better.

When Does a Matrix Equation Have a Solution?

The determinant decides everything.

  • det⁡A≠0\det A \neq 0. The inverse exists, and the equation has exactly one solution, X=A−1BX = A^{-1}B.

  • det⁡A=0\det A = 0 (singular AA). The inverse does not exist, and the system has either no solution or infinitely many — never exactly one. Which case you are in depends on whether BB is consistent with the rows of AA.

This is why the determinant check is not optional bookkeeping. It is the test for whether the inverse method can even run.

Examples of Matrix Equation

Example 1

Write the system x+2y=4x + 2y = 4, 3x−y=53x - y = 5 as a matrix equation.

[12 3−1][x y]=[4 5]\begin{bmatrix} 1 & 2 \ 3 & -1 \end{bmatrix}\begin{bmatrix} x \ y \end{bmatrix} = \begin{bmatrix} 4 \ 5 \end{bmatrix}

Final answer: A=[12 3−1]A = \begin{bmatrix} 1 & 2 \ 3 & -1 \end{bmatrix}, X=[x y]X = \begin{bmatrix} x \ y \end{bmatrix}, B=[4 5]B = \begin{bmatrix} 4 \ 5 \end{bmatrix}.

Example 2

Solve [21 13][x y]=[5 10]\begin{bmatrix} 2 & 1 \ 1 & 3 \end{bmatrix}\begin{bmatrix} x \ y \end{bmatrix} = \begin{bmatrix} 5 \ 10 \end{bmatrix}.

First, det⁡A=(2)(3)−(1)(1)=5≠0\det A = (2)(3) - (1)(1) = 5 \neq 0, so the inverse exists. For a 2×22 \times 2 matrix, the inverse is 1det⁡A[d−b −ca]\tfrac{1}{\det A}\begin{bmatrix} d & -b \ -c & a \end{bmatrix}:

A−1=15[3−1 −12]A^{-1} = \frac{1}{5}\begin{bmatrix} 3 & -1 \ -1 & 2 \end{bmatrix}

Now X=A−1BX = A^{-1}B:

X=15[3−1 −12][5 10]=15[15−10 −5+20]=15[5 15]=[1 3]X = \frac{1}{5}\begin{bmatrix} 3 & -1 \ -1 & 2 \end{bmatrix}\begin{bmatrix} 5 \ 10 \end{bmatrix} = \frac{1}{5}\begin{bmatrix} 15 - 10 \ -5 + 20 \end{bmatrix} = \frac{1}{5}\begin{bmatrix} 5 \ 15 \end{bmatrix} = \begin{bmatrix} 1 \ 3 \end{bmatrix}

Final answer: x=1x = 1, y=3y = 3.

Example 3 (watch how this goes wrong)

Solve AX=BAX = B where A=[12 24]A = \begin{bmatrix} 1 & 2 \ 2 & 4 \end{bmatrix} and B=[3 7]B = \begin{bmatrix} 3 \ 7 \end{bmatrix}.

Wrong attempt. A student computes A−1A^{-1} using the 2×22 \times 2 formula and pushes straight to X=A−1BX = A^{-1}B, expecting a clean answer.

The break. Check the determinant first: det⁡A=(1)(4)−(2)(2)=4−4=0\det A = (1)(4) - (2)(2) = 4 - 4 = 0. The matrix is singular, so A−1A^{-1} does not exist — the 1det⁡A\tfrac{1}{\det A} factor would divide by zero. The inverse method cannot run here.

Correct. Read the two equations: x+2y=3x + 2y = 3 and 2x+4y=72x + 4y = 7. The second is twice the first on the left (2x+4y2x + 4y), but 2×3=6≠72 \times 3 = 6 \neq 7 on the right. The lines are parallel and never meet. Final answer: no solution (the system is inconsistent).

Example 4

A right-hand side that flips the verdict: solve [12 24][x y]=[3 6]\begin{bmatrix} 1 & 2 \ 2 & 4 \end{bmatrix}\begin{bmatrix} x \ y \end{bmatrix} = \begin{bmatrix} 3 \ 6 \end{bmatrix}.

Same singular AA as Example 3, but now B=[3 6]B = \begin{bmatrix} 3 \ 6 \end{bmatrix}. The equations are x+2y=3x + 2y = 3 and 2x+4y=62x + 4y = 6 — the second is exactly twice the first, so they are the same line.

Final answer: infinitely many solutions, all points on x+2y=3x + 2y = 3. (Compare with Example 3: same AA, different BB, opposite outcome.)

Example 5

Solve the 3×33 \times 3 system x+y+z=6x + y + z = 6, 2y+5z=−42y + 5z = -4, 2x+5y−z=272x + 5y - z = 27 using the matrix equation, given det⁡A=−21\det A = -21.

A=[111 025 25−1],B=[6 −4 27]A = \begin{bmatrix} 1 & 1 & 1 \ 0 & 2 & 5 \ 2 & 5 & -1 \end{bmatrix}, \quad B = \begin{bmatrix} 6 \ -4 \ 27 \end{bmatrix}

Since det⁡A=−21≠0\det A = -21 \neq 0, a unique solution exists. Solving X=A−1BX = A^{-1}B (or by elimination) gives

x=5,y=3,z=−2x = 5, \quad y = 3, \quad z = -2

Check in equation 1: 5+3+(−2)=65 + 3 + (-2) = 6 ✓. Final answer: (x,y,z)=(5,3,−2)(x, y, z) = (5, 3, -2).

Example 6

Find the unknown matrix XX in [10 02]X=[4 6]\begin{bmatrix} 1 & 0 \ 0 & 2 \end{bmatrix}X = \begin{bmatrix} 4 \ 6 \end{bmatrix}.

Here AA is diagonal, so A−1=[10 012]A^{-1} = \begin{bmatrix} 1 & 0 \ 0 & \tfrac{1}{2} \end{bmatrix}:

X=[10 012][4 6]=[4 3]X = \begin{bmatrix} 1 & 0 \ 0 & \frac{1}{2} \end{bmatrix}\begin{bmatrix} 4 \ 6 \end{bmatrix} = \begin{bmatrix} 4 \ 3 \end{bmatrix}

Final answer: X=[4 3]X = \begin{bmatrix} 4 \ 3 \end{bmatrix}, i.e. x=4x = 4, y=3y = 3.

Why Matrix Equations Matter — "one rule for any system"

Long before computers, people had systems of equations to solve in surveying, astronomy, and trade, and they solved them by repetitive substitution. The breakthrough was realising that the structure of every linear system is the same — coefficients times unknowns equals constants — so a single notation and a single method could handle all of them. That is what AX=BAX = B delivers.

  • Engineering. Circuit analysis, structural load balancing, and control systems all reduce to large AX=BAX = B systems solved by computer.

  • Computer graphics and physics simulation. Lighting, fluid flow, and rigid-body dynamics are systems of linear equations solved thousands of times per second.

  • Economics and data science. Linear regression — fitting a line or surface to data — is solved as a matrix equation, and so are equilibrium and optimisation models.

A detail worth carrying: the reason software almost never literally computes A−1A^{-1} for large systems is that inverting is both expensive and error-prone. The matrix equation tells the computer what to solve; methods like LU decomposition tell it how to do so cheaply. The equation is the idea; the algorithm is the engineering.

Common Errors When Working With Matrix Equations

Mistake 1: Solving without checking the determinant

Where it slips in: Jumping straight to X=A−1BX = A^{-1}B.

Don't do this: Computing the inverse before confirming AA is invertible. If det⁡A=0\det A = 0, the inverse formula divides by zero and the method silently breaks.

The correct way: Compute det⁡A\det A first. If it is non-zero, proceed; if it is zero, the system has no solution or infinitely many, and you analyse the equations directly. The first instinct is to treat every system as if it has a clean unique answer, and the determinant is the one check that catches the systems that do not.

Mistake 2: Multiplying on the wrong side

Where it slips in: Applying A−1A^{-1} to solve AX=BAX = B.

Don't do this: Writing X=BA−1X = BA^{-1}. Matrix multiplication is not commutative, so the side matters.

The correct way: Multiply A−1A^{-1} on the left of both sides, since AA sits to the left of XX. That gives X=A−1BX = A^{-1}B. The habit that fixes this is writing the inverse on the same side as the matrix you are cancelling, every time.

Mistake 3: Dropping a zero coefficient when building A

Where it slips in: A system where one equation is missing a variable.

Don't do this: Writing a short row that skips the missing variable, which misaligns the columns of AA.

The correct way: Put a 0 in the slot for any missing variable so every row has the same length and the columns stay aligned. A misaligned AA produces a confident, wrong answer.

Bottom Line

  • A matrix equation writes a linear system compactly as AX=BAX = B, with AA the coefficients, XX the unknowns, and BB the constants.

  • When AA is invertible, the solution is X=A−1BX = A^{-1}B.

  • A unique solution exists exactly when det⁡A≠0\det A \neq 0; a singular AA means no solution or infinitely many.

  • The most common mistake is solving without first checking the determinant.

  • For large systems, elimination or Cramer's rule beats computing the inverse directly.

Practice Questions on Matrix Equation

Work through these, then check your answers below.

  1. Rewrite the system 4x−y=34x - y = 3, 2x+3y=112x + 3y = 11 as a matrix equation AX=BAX = B.

  2. Solve the system from Question 1 by the inverse method.

  3. Without fully solving, decide whether [13 26]X=[2 5]\begin{bmatrix} 1 & 3 \ 2 & 6 \end{bmatrix}X = \begin{bmatrix} 2 \ 5 \end{bmatrix} has a solution.

  4. Solve [11 1−1][x y]=[6 2]\begin{bmatrix} 1 & 1 \ 1 & -1 \end{bmatrix}\begin{bmatrix} x \ y \end{bmatrix} = \begin{bmatrix} 6 \ 2 \end{bmatrix}.

Answer to Question 1: [4−1 23][x y]=[3 11]\begin{bmatrix} 4 & -1 \ 2 & 3 \end{bmatrix}\begin{bmatrix} x \ y \end{bmatrix} = \begin{bmatrix} 3 \ 11 \end{bmatrix}.

Answer to Question 2: det⁡A=(4)(3)−(−1)(2)=14≠0\det A = (4)(3) - (-1)(2) = 14 \neq 0, so A−1=114[31 −24]A^{-1} = \tfrac{1}{14}\begin{bmatrix} 3 & 1 \ -2 & 4 \end{bmatrix}. Then X=114[31 −24][3 11]=114[20 38]=[107 197]X = \tfrac{1}{14}\begin{bmatrix} 3 & 1 \ -2 & 4 \end{bmatrix}\begin{bmatrix} 3 \ 11 \end{bmatrix} = \tfrac{1}{14}\begin{bmatrix} 20 \ 38 \end{bmatrix} = \begin{bmatrix} \frac{10}{7} \ \frac{19}{7} \end{bmatrix}. So x=107x = \tfrac{10}{7}, y=197y = \tfrac{19}{7}.

Answer to Question 3: det⁡A=(1)(6)−(3)(2)=0\det A = (1)(6) - (3)(2) = 0, so AA is singular. Checking consistency: the first equation is x+3y=2x + 3y = 2 and the second is 2x+6y=52x + 6y = 5. Doubling the first gives 2x+6y=4≠52x + 6y = 4 \neq 5, so the system is inconsistent and has no solution.

Answer to Question 4: det⁡A=(1)(−1)−(1)(1)=−2≠0\det A = (1)(-1) - (1)(1) = -2 \neq 0, so A−1=1−2[−1−1 −11]=12[11 1−1]A^{-1} = \tfrac{1}{-2}\begin{bmatrix} -1 & -1 \ -1 & 1 \end{bmatrix} = \tfrac{1}{2}\begin{bmatrix} 1 & 1 \ 1 & -1 \end{bmatrix}. Then X=12[11 1−1][6 2]=12[8 4]=[4 2]X = \tfrac{1}{2}\begin{bmatrix} 1 & 1 \ 1 & -1 \end{bmatrix}\begin{bmatrix} 6 \ 2 \end{bmatrix} = \tfrac{1}{2}\begin{bmatrix} 8 \ 4 \end{bmatrix} = \begin{bmatrix} 4 \ 2 \end{bmatrix}. So x=4x = 4, y=2y = 2.

A Practical Next Step

If the determinant step trips you, return to the "When Does a Matrix Equation Have a Solution?" section. At Bhanzu, our trainers teach students to compute the determinant before reaching for the inverse, so a singular system is caught at the start rather than after a page of wrong work.

Want a live Bhanzu trainer to walk through more matrix equation problems? Book a free demo class.

Was this article helpful?

Your feedback helps us write better content

Frequently Asked Questions

What is the matrix equation formula?
A matrix equation has the form AX=BAX = B, and when AA is invertible its solution is X=A−1BX = A^{-1}B.
When can you solve AX = B by the inverse method?
Only when AA is square and det⁡A≠0\det A \neq 0. If the determinant is zero, AA has no inverse and the system has either no solution or infinitely many.
Is X = A⁻¹B the same as X = BA⁻¹?
No. Matrix multiplication is not commutative. To solve AX=BAX = B you multiply on the left, giving X=A−1BX = A^{-1}B.
Can a matrix equation have no solution?
Yes. If AA is singular and BB is inconsistent with the rows of AA — like Example 3 — the system has no solution at all.
What other methods solve a matrix equation?
Besides the inverse method, you can use Cramer's rule, Gaussian elimination, or LU decomposition. For large systems, elimination-based methods are faster and more stable than inverting.
✍️ Written By
Madhukar V
Madhukar V
Math Columnist & Analyst
I see mathematics as more than just numbers and formulas—it is a way of thinking, questioning, and understanding the world around us. I work at the intersection of mathematics, EdTech, technology, and AI-powered learning, I enjoy exploring how mathematical ideas can be made simple, meaningful, and relatable. Through my articles, I aim to present mathematics with curiosity and a practical perspective, helping readers see the beauty and relevance behind every concept in a Bhanzu way.
LinkedIn
Related Articles
Book a FREE Demo ClassBook Now →