Tutorials › Linear Algebra › Dimension Checks for Matrix-Vector Products

Vectors and Linear Combinations · Tutorial 125 of 1000

Dimension Checks for Matrix-Vector Products

Use the matrix’s number of columns to check compatibility, then its number of rows to identify the product’s dimension.

Beginner 8 min read

What You'll Learn

  • Read the dimensions of a matrix and a column vector.
  • Decide whether a matrix-vector product is defined.
  • State the dimensions of a defined product without calculating its entries.
  • Explain why the column count controls compatibility and the row count controls the output.
  • Catch common errors that reverse the roles of rows and columns.

Why Dimensions Come Before Entries

Before calculating a matrix-vector product, check whether its dimensions allow the product to be formed. This quick check prevents a common mistake: using the number of rows to decide which vectors can be inputs. For a matrix acting on a column vector, it is the number of columns that must match the vector’s number of entries. If the product is defined, the number of rows determines how many entries the result has.

Throughout, matrices and vectors have real entries. Let \(m,n,p\in\mathbb{N}\), where \(\mathbb{N}=\{1,2,3,\dots\}\). A matrix \(\mathbf{A}\in\mathbb{R}^{m\times n}\) has \(m\) rows and \(n\) columns. A vector \(\mathbf{x}\in\mathbb{R}^{p}\) is a column with \(p\) entries. The dimensions of \(\mathbf{A}\) and \(\mathbf{x}\) are therefore \(m\times n\) and \(p\times 1\), respectively.

Definition: For \(\mathbf{A}\in\mathbb{R}^{m\times n}\) and a column vector \(\mathbf{x}\in\mathbb{R}^{p}\), the matrix-vector product \(\mathbf{A}\mathbf{x}\) is defined when the number of columns of \(\mathbf{A}\) equals the number of entries of \(\mathbf{x}\). When it is defined, its dimensions are \(m\times 1\), so it is a vector in \(\mathbb{R}^{m}\).

The two numbers play different roles. The matrix’s column count tells us how many coordinates the input vector must have. The matrix’s row count tells us how many output coordinates there are. This distinction can be remembered as “columns in, rows out,” but the results below show precisely why that rule holds.

The Compatibility Test

The row description of a matrix-vector product computes one output entry for each row of the matrix. Each such entry is a dot product of that row’s \(n\) entries with the vector’s \(p\) entries. A dot product is defined only when both lists have the same number of entries. The column description expresses the product as a linear combination of the matrix’s columns, using one coefficient for each column. These descriptions give the same compatibility requirement.

Proposition (Compatibility criterion): Let \(\mathbf{A}\in\mathbb{R}^{m\times n}\) and \(\mathbf{x}\in\mathbb{R}^{p}\). The product \(\mathbf{A}\mathbf{x}\) is defined if and only if \(n=p\).

Proof. Assume first that \(\mathbf{A}\mathbf{x}\) is defined. By the row formula, an output coordinate is formed by pairing the \(n\) entries of a row of \(\mathbf{A}\) with the entries of \(\mathbf{x}\). This pairing is a dot product, which requires the two lists to have equal length. The row has \(n\) entries and \(\mathbf{x}\) has \(p\) entries, so \(n=p\). Conversely, suppose \(n=p\). Each row of \(\mathbf{A}\) and the vector \(\mathbf{x}\) then have the same number of entries, so each row dot product is defined. There is one such dot product for each of the \(m\) rows, and together they define \(\mathbf{A}\mathbf{x}\). Thus the product is defined exactly when \(n=p\). \(\square\)

This is an if-and-only-if test: equal dimensions guarantee that the product is defined, and a defined product requires equal dimensions. It is not enough that the matrix and vector both have some dimension in common, or that the matrix has the same number of rows as the vector has entries. The match to check is specifically between the matrix’s number of columns and the vector’s number of entries.

Finding the Product’s Dimensions

Once compatibility has been checked, the output size follows from the row formula. There is one output coordinate per row. Equivalently, the column formula combines the columns of \(\mathbf{A}\), and each of those columns has \(m\) entries. Either description gives a result with \(m\) entries.

Proposition (Output dimension): If \(\mathbf{A}\in\mathbb{R}^{m\times n}\), \(\mathbf{x}\in\mathbb{R}^{p}\), and \(\mathbf{A}\mathbf{x}\) is defined, then \(n=p\) and \(\mathbf{A}\mathbf{x}\in\mathbb{R}^{m}\). As a column, the product has dimensions \(m\times 1\).

Proof. Since the product is defined, the compatibility criterion gives \(n=p\). Write the rows of \(\mathbf{A}\) as lists \(\mathbf{r}_1,\dots,\mathbf{r}_m\), each with \(n\) entries. The row formula gives the product’s \(i\)th entry as the dot product of \(\mathbf{r}_i\) and \(\mathbf{x}\), for each \(i\) from \(1\) to \(m\). There are exactly \(m\) such entries, so the product is a column in \(\mathbb{R}^{m}\), with dimensions \(m\times 1\). In the column formula, \(\mathbf{A}\) has \(n\) columns, each in \(\mathbb{R}^{m}\), and \(\mathbf{x}\) supplies one scalar coefficient for each column; their linear combination is also in \(\mathbb{R}^{m}\). \(\square\)

The dimension rule can be recorded compactly, provided the matching condition is kept visible:

$$ \mathbf{A}\in\mathbb{R}^{m\times n},\qquad \mathbf{x}\in\mathbb{R}^{n} \quad\Longrightarrow\quad \mathbf{A}\mathbf{x}\in\mathbb{R}^{m}. $$

The symbol \(\Longrightarrow\) here represents a conditional statement, not permission to multiply matrices with any sizes. If the input dimension is not \(n\), the product is undefined; it does not have a different output dimension. Always decide whether the product exists before stating its size.

Worked Dimension Checks

Worked Example: A Defined Product

Suppose \(\mathbf{A}\in\mathbb{R}^{3\times 2}\) and \(\mathbf{x}\in\mathbb{R}^{2}\). Is \(\mathbf{A}\mathbf{x}\) defined, and what are its dimensions?

Step 1: Read the matrix dimensions. The matrix has \(3\) rows and \(2\) columns. Thus its column count is \(n=2\).

Step 2: Read the vector dimension. The vector has \(p=2\) entries. Compare the required numbers: \(n=2\) and \(p=2\), so \(n=p\).

Step 3: State the result size. The compatibility criterion says the product is defined. The matrix has \(m=3\) rows, so the product has \(3\) entries: \(\mathbf{A}\mathbf{x}\in\mathbb{R}^{3}\), with dimensions \(3\times1\).

Check: Each of the \(3\) matrix rows has \(2\) entries, matching the \(2\) entries of \(\mathbf{x}\). There are \(3\) row dot products, so the stated output has exactly \(3\) coordinates.

Worked Example: A Product That Is Not Defined

Suppose \(\mathbf{B}\in\mathbb{R}^{2\times 4}\) and \(\mathbf{y}\in\mathbb{R}^{3}\). Decide whether \(\mathbf{B}\mathbf{y}\) is defined. If it is not, do not assign it output dimensions.

Step 1: Read the inner dimensions. The matrix has \(4\) columns, while the vector has \(3\) entries. The compatibility check is \(4=3\).

Step 2: Compare. Since \(4\ne3\), the condition fails. Thus \(\mathbf{B}\mathbf{y}\) is undefined.

Check: Each row of \(\mathbf{B}\) contains \(4\) entries, but \(\mathbf{y}\) contains only \(3\). The row dot products cannot be formed. Although \(\mathbf{B}\) has \(2\) rows, that does not make the product defined, and \(\mathbf{B}\mathbf{y}\) has no output dimension.

Worked Example: More Rows Than Columns

Let \(\mathbf{C}\in\mathbb{R}^{4\times 3}\) and \(\mathbf{z}=(z_1,z_2,z_3)^{\top}\in\mathbb{R}^{3}\). Determine the dimensions of \(\mathbf{C}\mathbf{z}\) in both the row and column descriptions, without calculating its entries.

Step 1: Check compatibility. The matrix has \(3\) columns and \(\mathbf{z}\) has \(3\) entries, so \(n=p=3\). The product is defined.

Step 2: Count the output by rows. The matrix has \(4\) rows. The row formula therefore gives \(4\) output coordinates, so \(\mathbf{C}\mathbf{z}\in\mathbb{R}^{4}\).

Step 3: Count the output by columns. Write the columns of \(\mathbf{C}\) as \(\mathbf{c}_1,\mathbf{c}_2,\mathbf{c}_3\). Each column has \(4\) entries, and the column formula is \(\mathbf{C}\mathbf{z}=z_1\mathbf{c}_1+z_2\mathbf{c}_2+z_3\mathbf{c}_3\). This combination has \(4\) entries.

Check: Both descriptions give a column in \(\mathbb{R}^{4}\), with dimensions \(4\times1\). The input has \(3\) entries because there are \(3\) columns; the output has \(4\) entries because there are \(4\) rows.

Worked Example: A Parameterized Number of Columns

Suppose \(\mathbf{D}\) has \(5\) rows and \(k\) columns, and \(\mathbf{u}\in\mathbb{R}^{4}\). For which value of \(k\) is \(\mathbf{D}\mathbf{u}\) defined, and what are the product’s dimensions then?

Step 1: Express the matrix dimensions. Here \(\mathbf{D}\in\mathbb{R}^{5\times k}\). Its column count is \(k\), and its row count is \(5\).

Step 2: Apply the compatibility condition. The vector has \(4\) entries, so the product is defined exactly when \(k=4\).

Step 3: State the output dimensions under that condition. When \(k=4\), \(\mathbf{D}\) has dimensions \(5\times4\), and \(\mathbf{u}\) has dimensions \(4\times1\). The product has dimensions \(5\times1\), so \(\mathbf{D}\mathbf{u}\in\mathbb{R}^{5}\).

Check: With \(k=4\), each row has \(4\) entries to pair with the vector’s \(4\) entries, and there are \(5\) rows. If \(k\ne4\), the column count and vector length do not match, so no product is defined.

Common Mistake: Reversing Rows and Columns

A frequent error is to use the matrix’s row count to decide the required input length. For example, let \(\mathbf{E}\in\mathbb{R}^{2\times3}\) and let \(\mathbf{v}\in\mathbb{R}^{2}\). A wrong calculation might say, “\(\mathbf{E}\) has \(2\) rows, and \(\mathbf{v}\) has \(2\) entries, so \(\mathbf{E}\mathbf{v}\) is defined and the answer has \(3\) entries.” This reasoning uses the row count for compatibility and the column count for output, reversing both roles.

The correction is to compare the column count with the vector length: \(\mathbf{E}\) has \(3\) columns, but \(\mathbf{v}\) has \(2\) entries, so \(3\ne2\) and \(\mathbf{E}\mathbf{v}\) is undefined. To make a product with \(\mathbf{E}\), the input must have \(3\) entries. With such an input, the output has \(2\) entries, because \(\mathbf{E}\) has \(2\) rows.

Another pitfall is to say that an undefined product has the “wrong output size.” That phrase can suggest there is a product to size. If the dimensions fail the compatibility test, there is no matrix-vector product at all. State “undefined” rather than giving it a dimension.

A Reliable Routine

For each matrix-vector product, use the following order. Keeping the checks separate makes it harder to confuse the input and output dimensions.

1
Write the shapes.
For \(\mathbf{A}\in\mathbb{R}^{m\times n}\) and \(\mathbf{x}\in\mathbb{R}^{p}\), record \(m\times n\) and \(p\times1\).
2
Compare the inner dimensions.
Check whether \(n=p\). If not, stop: \(\mathbf{A}\mathbf{x}\) is undefined.
3
Read the output dimension.
If \(n=p\), the product is defined and has dimensions \(m\times1\), or belongs to \(\mathbb{R}^{m}\).

This routine checks dimensions only; it does not calculate the product’s entries. That separation is useful whenever a problem asks only whether a product is possible or what shape its result must have. It also establishes a necessary preliminary check before any later calculation involving a matrix-vector product.

Check Your Understanding

For each question, state the dimension comparison you use. Do not calculate product entries.

  1. If \(\mathbf{F}\in\mathbb{R}^{3\times5}\) and \(\mathbf{q}\in\mathbb{R}^{5}\), is \(\mathbf{F}\mathbf{q}\) defined? If so, state the product’s dimensions and the space containing it.
  2. If \(\mathbf{G}\in\mathbb{R}^{4\times2}\) and \(\mathbf{r}\in\mathbb{R}^{3}\), is \(\mathbf{G}\mathbf{r}\) defined? Explain why or why not.
  3. A matrix has \(6\) rows and \(k\) columns. For which \(k\) can it multiply a vector in \(\mathbb{R}^{2}\), and what is the output space?
  4. Explain why a matrix with \(2\) rows and \(5\) columns cannot multiply a vector in \(\mathbb{R}^{2}\), even though the matrix has \(2\) rows.
  5. State the compatibility condition and the output dimension for \(\mathbf{A}\in\mathbb{R}^{m\times n}\) multiplying \(\mathbf{x}\in\mathbb{R}^{p}\).

Test yourself: Linear Algebra final exam practice

Ready to check what you know? Work a full-length practice final, then open the complete worked solutions.

Want all 1,114 practice problems?

This tutorial covers one topic. Calc Pass covers the full Calculus AB & BC curriculum (the core of Calculus I and II): full review, every practice question, and step-by-step solutions to each one.

QR code to download the Calc Pass app

Get the Calc Pass App

Scan to download and practice on the go, with instant scoring.

Calc Pass Volume 1: 1,114 Practice Questions book cover

Vol. 1: 1,114 Questions

The complete practice question bank, organized by AB & BC topic.

View on Amazon
Calc Pass Volume 2: Solutions Manual book cover

Vol. 2: Solutions Manual

Fully worked solutions to every question in Volume 1.

View on Amazon