Ma · Mathematics

How to Solve Non-Square Matrix Equations

Published By the 9to5Science editorial team

At a glance

  1. 1. Check dimensions

    Write the sizes of every matrix and determine the size required for the unknown.

  2. 2. Test consistency

    For AX = B, check whether every column of B lies in the column space of A.

  3. 3. Solve by columns

    Treat each column equation Ax = b as an ordinary linear system and combine the solutions.

  4. 4. Choose a solution type

    Report exact solutions when they exist; otherwise use least squares if an approximate fit is intended.

A rectangular matrix generally has no ordinary inverse, so you cannot solve a matrix equation by multiplying by A−1A^{-1}. Instead, identify the dimensions and interpret the equation as one or more systems of linear equations. This approach applies whether you are solving AX=BAX=B, XA=BXA=B, or a more complicated equation involving an unknown matrix.

The most common case is AX=BAX=B, where AA and BB are known and XX is unknown. The equation may have no exact solution, a unique solution, or infinitely many solutions.

Start with dimensions

Suppose AA is an m×nm\times n matrix and BB is an m×pm\times p matrix. For the product AXAX to be defined and equal to BB, XX must be an n×pn\times p matrix:

Am×nXn×p=Bm×p.A_{m\times n}X_{n\times p}=B_{m\times p}.

Write the unknown as columns, X=[x1  x2  ⋯  xp]X=[x_1\;x_2\;\cdots\;x_p], and write B=[b1  b2  ⋯  bp]B=[b_1\;b_2\;\cdots\;b_p]. Then AX=BAX=B means

Axj=bj(j=1,…,p).Ax_j=b_j \qquad (j=1,\ldots,p).

So you can solve the equation by solving pp ordinary systems with the same coefficient matrix AA, one for each column of BB.

Decide whether exact solutions exist

A system Ax=bAx=b has a solution exactly when bb is in the column space of AA. Therefore, AX=BAX=B has an exact solution exactly when every column of BB is in the column space of AA.

You can test this by row-reducing the augmented matrix [A∣B][A\mid B]. If row reduction produces a row whose coefficient entries are all zero but whose entry in BB is nonzero, the equation is inconsistent. Otherwise, the solutions can be found by expressing pivot variables in terms of any free variables.

The number of solutions depends on the rank of AA and consistency:

  • If AA has full column rank (rank⁡(A)=n\operatorname{rank}(A)=n), each consistent column system has a unique solution.
  • If rank⁡(A)<n\operatorname{rank}(A)<n, a consistent system has free variables and therefore infinitely many solutions (over R\mathbb{R}).
  • If any column system is inconsistent, there is no exact matrix XX satisfying the equation.

Worked example: a rectangular equation with infinitely many solutions

Let

A=[101011],B=[1234].A=\begin{bmatrix}1&0&1\\0&1&1\end{bmatrix}, \qquad B=\begin{bmatrix}1&2\\3&4\end{bmatrix}.

Since AA is 2×32\times3 and BB is 2×22\times2, the unknown XX must be 3×23\times2. Write its columns as x1x_1 and x2x_2. Solving Ax1=b1Ax_1=b_1 gives

x11+x31=1,x21+x31=3.x_{11}+x_{31}=1,\qquad x_{21}+x_{31}=3.

Set the free variable x31=t1x_{31}=t_1. Then x11=1−t1x_{11}=1-t_1 and x21=3−t1x_{21}=3-t_1. The second column gives, in the same way, x12=2−t2x_{12}=2-t_2, x22=4−t2x_{22}=4-t_2, and x32=t2x_{32}=t_2. Thus every solution is

X=[1−t12−t23−t14−t2t1t2],t1,t2∈R.X=\begin{bmatrix}1-t_1&2-t_2\\3-t_1&4-t_2\\t_1&t_2\end{bmatrix}, \qquad t_1,t_2\in\mathbb{R}.

For example, taking t1=t2=0t_1=t_2=0 gives one solution. Substituting it verifies the equation:

AX=[101011][123400]=[1234]=B.AX= \begin{bmatrix}1&0&1\\0&1&1\end{bmatrix} \begin{bmatrix}1&2\\3&4\\0&0\end{bmatrix} =\begin{bmatrix}1&2\\3&4\end{bmatrix}=B.

The two free parameters arise because AA has three columns but rank two. Each column system has one free variable.

If the equation is XA=BXA=B

The same principle works, but the row space replaces the column space. If AA is m×nm\times n, then XX must have mm columns for XAXA to be defined. Each row of XAXA is a linear combination of the rows of AA. Consequently, XA=BXA=B has a solution exactly when every row of BB lies in the row space of AA.

You can also transpose the equation: XA=BXA=B is equivalent to ATXT=BTA^T X^T=B^T. Then solve it as a left-multiplication problem, one column at a time.

If there is no exact solution: least squares

In applications, AX=BAX=B may be inconsistent because data contain measurement error or because the system is overdetermined. A common alternative is to choose XX that minimizes the total squared residual, ∥AX−B∥F2\lVert AX-B\rVert_F^2, where the Frobenius norm sums the squares of all entries.

The Moore–Penrose pseudoinverse gives a standard least-squares choice: X=A+BX=A^+B. When AA has full column rank, this simplifies to X=(ATA)−1ATBX=(A^T A)^{-1}A^T B. In numerical work, QR factorization or singular value decomposition is generally preferred to explicitly forming that inverse. Least squares gives an approximate fit; it does not turn an inconsistent equation into an exact one.

Common mistakes

  • Trying to invert a rectangular matrix. Ordinary matrix inverses are defined only for square matrices, and even a square matrix must be nonsingular. Use elimination or a pseudoinverse for the relevant problem instead.
  • Ignoring dimensions. Check the inner dimensions of every product before solving, and state the size of the unknown.
  • Assuming consistency. A rectangular system can have no solution. Check the augmented system or the column-space condition first.
  • Giving just one solution when there are free variables. A particular solution does not describe all solutions. Include the free parameters, or state clearly that you are giving one example.
  • Confusing exact and least-squares solutions. A least-squares answer minimizes error; it satisfies AX=BAX=B exactly only if the residual is zero.

For equations with the unknown matrix appearing more than once, such as AXB=CAXB=C, you can often convert the problem into a scalar linear system in the entries of XX. The dimensions and placement of the unknown determine which system to solve.

References

  1. Linear Algebra and Its Applications, David C. Lay, Steven R. Lay, and Judi J. McDonald
  2. Introduction to Linear Algebra, Gilbert Strang

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.