Matrix Operations
Read and combine matrices, trace row-by-column products, and model practical problems with an editable matrix explorer and worked solutions.
Reading a matrix
A matrix organizes numbers into rows and columns. Its arrangement carries meaning: a row might represent a shop, while a column represents a product.
Rows first, columns second
An m × n matrix has m rows and n columns. The entry aij is in row i, column j. Counting begins at 1.
Example · Locate matrix entries
Use this array to identify its size and locate entries by row, then column.
B is 2 × 3. Its entries include b11=6, b13=24, and b23=8.
| Type | Shape | Example |
|---|---|---|
| Row matrix | 1 × n | 214 |
| Column matrix | m × 1 | 456 |
| Square matrix | n × n | 1234 |
Try it · Locate the entry
State the dimensions of C and find c24 and c12.
Show solution
C has 2 rows and 4 columns, so it is 2 × 4. The entries are c24=3 and c12=9.
Common mistake
A 2 × 3 matrix and a 3 × 2 matrix each contain six entries, but they have different dimensions.
Let us begin with what the arrangement tells us. A matrix keeps information in fixed positions, so moving an entry can change its meaning even when the same numbers are present. As you read the examples, identify the row first and then the column. That habit will help us make sense of every operation that follows.
When matrices are equal
Two conditions for equality
Matrices A and B are equal exactly when they have the same dimensions and every pair of corresponding entries is equal.
Example · Solve entry by entry
The first entries give x=5. The lower-right entries give y+1=7, so y=6. The other corresponding entries already match.
Try it · A hidden contradiction
Can any value of x make these matrices equal?
Show solution
No. Even if x=7, the lower-right entries 4 and 5 disagree. All corresponding entries must match.
What equality tells us
Two matrices are equal if and only if they have the same dimensions and equal entries in every corresponding position.
It lets us recover unknown values from two descriptions of the same data, but satisfying only one position does not establish equality.
Before combining matrices, let us settle what it means for them to contain the same information. Matching the total number of entries is not enough: their positions must match too. In the next example, treat each corresponding pair as a separate condition, and check even the pairs that contain no unknown.
Addition & subtraction
Match the positions
You may add or subtract matrices only when their dimensions are identical. Add or subtract corresponding entries; the result keeps the same dimensions.
Example · Add corresponding entries
The upper-right entry is 2+3=5. The lower-left entry is 0+(−1)=−1.
Try it · Addition
Show solution
Try it · Subtraction
Show solution
For example, 3−(−4)=7 and 1−(−5)=6. Subtract every entry of the second matrix.
Common mistake
Matching only the number of rows is not enough. A 2 × 3 matrix plus a 2 × 2 matrix is undefined.
We can now read the entries and tell when two matrices are equal. The next question is how to combine the information they contain. For addition, keep corresponding positions together: an entry in one row and column must be combined with the entry in that same position.
Scalars & matrix equations
Scale every entry
A scalar is an ordinary number. To calculate cA, multiply every entry of A by c. The dimensions do not change.
Example · Multiply by 3
Useful properties
For compatible matrices and real scalars c,d:
- A+B=B+A and (A+B)+C=A+(B+C).
- A+O=A, where O is the zero matrix of the same dimensions.
- A+(−A)=O.
- c(A+B)=cA+cB and (c+d)A=cA+dA.
- c(dA)=(cd)A and 1A=A.
Example · Solve 3X+A=B
Subtract A, then multiply every entry by ⅓:
Check: 3X+A reproduces B. This is division by the scalar 3, not division by a matrix.
Try it · Combine operations
Show solution
Try it · Find X
If 2X+A=B, find X for the following matrices.
Show solution
Addition combined two arrays. Scalar multiplication changes the size of every entry in one array by the same factor. That gives us a way to solve matrix equations using familiar algebra, provided we distinguish multiplication by a number from multiplication by another matrix.
Can these matrices multiply?
Inner dimensions match; outer dimensions remain
If A is m × n and B is n × p, then AB is defined and has dimensions m × p. The number of columns of A must equal the number of rows of B.
(m × n)(n × p) → m × p
Example · Order matters
For A of size 3 × 2 and B of size 2 × 4, AB is 3 × 4. BA is undefined because its inner dimensions would be 4 and 3.
Quick check · Predict the shape
A is 2 × 3 and B is 3 × 4. What can you say about AB?
Try it · Check both orders
P is 1 × 3 and Q is 3 × 1. Are PQ and QP defined? What are their dimensions?
Show solution
Both are defined. PQ is 1 × 1; QP is 3 × 3. Even when both orders exist, the products need not have the same size.
Matrix multiplication asks a different question from addition. Instead of combining matching positions, we combine the contributions along a row with those down a column. Before doing any arithmetic, check whether those two lists have the same length.
Row-by-column multiplication
One row, one column, one entry
The entry in row i, column j of AB is the sum of products of corresponding entries from row i of A and column j of B:
(AB)ij = ai1b1j + ai2b2j + ⋯ + ainbnj.
Example · A rectangular product
The dimensions are (3 × 2)(2 × 2), so AB is 3 × 2.
First row, first column: (−1)(−3)+3(−4)=−9.
First row, second column: (−1)(2)+3(1)=1.
Common mistake
Matrix multiplication is not entry-by-entry multiplication. Every output entry uses a complete row and a complete column.
Try it · Multiply
Show solution
For example, the upper-right entry is 6(6)+(−4)(−2)=44.
Try it · A column times a row
Show solution
We know when a product is allowed; now let us see how one entry is built. Follow just one row and one column, pair their entries, and add the products. Finish that one entry before moving on. You are repeating the same small calculation in different positions, rather than trying to calculate the entire matrix at once.
See a product as a combination of columns
If the columns of \(A\) are \(c_1,c_2\), then \(A\begin{bmatrix}u\\v\end{bmatrix}=u c_1+v c_2\). This follows from the same row-by-column definition: each row contributes its first entry times \(u\), plus its second entry times \(v\). It connects matrix multiplication to systems of equations and to geometric transformations.
Build an output from two ingredients
A recipe matrix \(A=\begin{bmatrix}2&1\\1&3\end{bmatrix}\) lists flour and sugar requirements in its rows, and small and large batches in its columns. What does \(A\begin{bmatrix}3\\2\end{bmatrix}\) mean? Each entry is a number of cups.
Show worked solution
Three small batches and two large batches require \(8\) cups of flour and \(9\) cups of sugar. The output rows retain the ingredient labels. Conversely, recovering batch counts from supplies gives two simultaneous scalar equations. Use the matrix lab to check the product, then select each output entry to trace its row and column.
Explore matrix operations
Edit the matrices below. Separate entries with spaces or commas and rows with a new line. Use up to 4 × 4 matrices with entries from −1,000 to 1,000.
Calculate, then explain
We have learned the rules separately; this workspace lets us see how the choice of operation changes the result. Predict whether an operation is possible and what shape its answer should have before calculating. Then inspect an individual entry to connect the output with the rule.
Identity & multiplication rules
The identity matrix
The square identity matrix I has 1s on its main diagonal and 0s elsewhere.
Examples · Identity matrices
For any m × n matrix A, ImA=A and AIn=A. Notice that the left and right identity matrices can have different sizes.
Properties that hold
Whenever the dimensions allow the expressions:
- A(BC)=(AB)C — associativity.
- A(B+C)=AB+AC — left distributivity.
- (A+B)C=AC+BC — right distributivity.
- c(AB)=(cA)B=A(cB).
Parentheses can move in a product, but the order of the matrices stays the same.
A counterexample to AB=BA
Both products exist, but they are different. Matrix multiplication is not commutative in general.
Zero products need care
AB=O does not force A=O or B=O. These matrices are both nonzero, but their product is zero:
Why an identity matrix is useful
An identity matrix is a square matrix with ones on its main diagonal and zeros elsewhere.
It plays the role of one in matrix multiplication: multiplying a matrix by a compatible identity leaves the matrix unchanged. Its diagonal ones select the matching entries, while its other entries contribute zero. The identity’s size must match the side on which it multiplies.
The row-by-column rule is now familiar enough for us to ask which arithmetic habits still work. Look for a matrix that leaves a product unchanged, then compare products taken in opposite orders. Examples are useful here because one counterexample is enough to show that a familiar number rule does not hold for all matrices.
Honors: a nonzero matrix whose square vanishes
A matrix power \(A^n\), for a positive integer \(n\), means repeated matrix multiplication; \(A\) must be square. Ordinary scalar patterns can fail because a nonzero matrix can erase information.
Prove a formula for every positive power
Let \(N=\begin{bmatrix}0&2\\0&0\end{bmatrix}\) and \(A=I+N\). Prove \(A^n=I+nN\) for every positive integer \(n\). Then find a matrix \(B\) satisfying \(AB=BA=I\), without assuming a general inverse formula.
Show worked solution
Direct multiplication gives \(N^2=O\). The formula holds for \(n=1\). If \(A^n=I+nN\), then \(A^{n+1}=(I+nN)(I+N)=I+(n+1)N+nN^2=I+(n+1)N\). Induction proves it for all positive integers. Choose \(B=I-N\): both products equal \(I-N^2=I\). Thus \(B=\begin{bmatrix}1&-2\\0&1\end{bmatrix}\). We have verified an inverse by its defining two-sided identity rather than dividing by a matrix.
Predict what repeated multiplication preserves
Use the matrix N from the preceding challenge. Decide what N² = O tells you.
Model a real situation
Example · A school supplies stall
Rows of Q represent Monday and Tuesday. Columns represent notebooks and pens. The price column P uses the same product order.
Each notebook costs ₱30 and each pen costs ₱10. Multiplying quantity by price gives revenue:
Monday: 12(30)+20(10)=₱560. Tuesday: 15(30)+18(10)=₱630. The result has one row per day and one revenue column.
Try it · Add a second stall
A second stall sells notebooks and pens on those same days in the quantities below. Find the combined quantity matrix and the total revenue each day at the same prices.
Show solution
Each day brings in 20(30)+30(10)=₱900. Adding quantities before multiplying gives the same result as adding the stalls’ revenues.
Check the labels
Compatible dimensions are necessary, but a meaningful model also needs matching categories and units. Reversing the order of prices without reversing the quantity columns changes the calculation.
The calculation becomes more useful when every row and column has a meaning. Before multiplying in these applications, say aloud what one entry of the result should represent. That interpretation helps you choose the order of the matrices and check whether the answer is reasonable.
Order has a geometric meaning
A matrix can act on a coordinate column. For \(S=\begin{bmatrix}2&0\\0&1\end{bmatrix}\), multiplying \((x,y)\) gives \((2x,y)\), a horizontal stretch. For \(R=\begin{bmatrix}0&-1\\1&0\end{bmatrix}\), it gives \((-y,x)\), a quarter-turn counterclockwise. These descriptions are consequences of multiplying the columns, not new multiplication rules.
Stretch, then turn—or turn, then stretch?
Starting from \(v=\begin{bmatrix}1\\2\end{bmatrix}\), calculate \(RSv\) and \(SRv\). Explain which action happens first.
Show worked solution
The rightmost matrix acts first on a column vector. The unequal outputs prove these transformations do not commute. Associativity lets us compute \((RS)v=R(Sv)\); it does not allow us to reverse the order. For further geometric interpretations, see Transformations and the Riemann Sphere.
Practice & review
Predict the dimensions before calculating. Write your working before opening a solution.
Review 1 · Equality
Show solution
2x=8 and y−3=2, so x=4 and y=5.
Review 2 · Subtract carefully
Show solution
Review 3 · A linear combination
Show solution
Review 4 · A rectangular product
Show solution
The result is 3 × 3. Its middle entry is 2(5)+(−6)(2)=−2.
Review 5 · Identity sizes
If A is 2 × 3, choose the identity sizes that make IA=A and AI=A.
Show solution
I₂A=A on the left; AI₃=A on the right.
Review 6 · Explain the error
A learner says: “Since real-number multiplication commutes, (A+B)²=A²+2AB+B² for every pair of square matrices.” What is missing?
Show solution
Expansion gives A²+AB+BA+B². Replacing AB+BA by 2AB requires AB=BA, which does not hold in general.
Additional practice: mixed exercises
Warm-up: complex-number arithmetic
These optional prerequisite questions use \(i^2=-1\). Combine real and imaginary parts separately.
- Simplify \((-4+3i)+(9-17i)\).
- Simplify \((8-6i)-(-2+5i)\).
- Simplify \((3-9i)(-8+6i)\).
Show worked solution
- Combine like terms: \(-4+9=5\) and \(3i-17i=-14i\). The result is \(5-14i\).
- Distribute the subtraction: \(8-6i+2-5i=10-11i\).
- Expand: \(-24+18i+72i-54i^2\). Since \(i^2=-1\), this is \(-24+54+90i=30+90i\).
Addition and distribution
Check dimensions, then work entry by entry.
- State the dimensions of \(\begin{bmatrix}-4&9&2&8\\-2&0&2&3\end{bmatrix}\).
- Add \(\begin{bmatrix}-1&2\\0&1\end{bmatrix}+\begin{bmatrix}1&3\\-1&2\end{bmatrix}\).
- Add \(\begin{bmatrix}1\\-3\\2\end{bmatrix}+\begin{bmatrix}-1\\3\\-2\end{bmatrix}\).
- Can \(\begin{bmatrix}2&1&0\\4&0&-1\end{bmatrix}\) and \(\begin{bmatrix}0&1\\-1&3\end{bmatrix}\) be added?
- Evaluate \(3\left(\begin{bmatrix}-2&0\\4&1\end{bmatrix}+\begin{bmatrix}4&-2\\3&7\end{bmatrix}\right)\) in two ways.
Show worked solution
- There are \(2\) rows and \(4\) columns, so the dimensions are \(2\times4\).
- Add corresponding entries: \(\begin{bmatrix}0&5\\-1&3\end{bmatrix}\). For example, the upper-right entry is \(2+3=5\).
- Each pair consists of additive inverses, giving the zero column \(\begin{bmatrix}0\\0\\0\end{bmatrix}\).
- No. Their dimensions are \(2\times3\) and \(2\times2\), so corresponding entries cannot be paired throughout.
- Adding first gives \(3\begin{bmatrix}2&-2\\7&8\end{bmatrix}=\begin{bmatrix}6&-6\\21&24\end{bmatrix}\). Alternatively, distribute \(3\) to both matrices, obtaining \(\begin{bmatrix}-6&0\\12&3\end{bmatrix}+\begin{bmatrix}12&-6\\9&21\end{bmatrix}\), with the same result.
Matrix calculation practice
Check dimensions first; show entrywise arithmetic for sums and row–column products for multiplication.
- \(\begin{bmatrix}1&5\\4&2\end{bmatrix}+\begin{bmatrix}-2&1\\-4&0\end{bmatrix}\)
- \(\begin{bmatrix}6&4&3\\1&-3&2\\8&7&1\end{bmatrix}-\begin{bmatrix}4&5&-4\\-5&1&0\\6&4&7\end{bmatrix}\)
- \(\begin{bmatrix}6&-4\\-3&-3\end{bmatrix}\begin{bmatrix}0&6\\-4&-2\end{bmatrix}\)
Show worked solution
- Add corresponding entries: \(\begin{bmatrix}-1&6\\0&2\end{bmatrix}\).
- Subtract each entry in the second matrix: \(\begin{bmatrix}2&-1&7\\6&-4&2\\2&3&-6\end{bmatrix}\).
- The four row–column sums are \(6(0)+(-4)(-4)=16\), \(6(6)+(-4)(-2)=44\), \((-3)(0)+(-3)(-4)=12\), and \((-3)(6)+(-3)(-2)=-12\). Result: \(\begin{bmatrix}16&44\\12&-12\end{bmatrix}\).
Matrix review before vectors
Check both the dimensions and the order of multiplication.
- Let \(A=\begin{bmatrix}2&8\\7&6\end{bmatrix}\), \(B=\begin{bmatrix}1&6\\3&7\end{bmatrix}\), \(C=\begin{bmatrix}1&6\end{bmatrix}\), and \(D=\begin{bmatrix}2\\7\end{bmatrix}\). Which of \(AB,DC,BC,AD\) equals \(\begin{bmatrix}2&12\\7&42\end{bmatrix}\)?
- Compute \(\begin{bmatrix}4\\5\\6\end{bmatrix}\begin{bmatrix}1&2&3\end{bmatrix}\). Is \(\begin{bmatrix}6\\4\\-1\end{bmatrix}\begin{bmatrix}3&1&5\\6&2&0\end{bmatrix}\) defined?
- Which can multiply a \(2\times3\) matrix on the right: \(2\times2\), \(3\times12\), \(2\times12\), or \(2\times3\)?
- If \(A\) is \(2\times8\) and \(B\) is \(7\times2\), which of \(A+B,AB,BA,A-B\) exist?
- Must \(AB\ne BA\) always hold? State the correct general rule, and the rules for \(A+B\) and \(AI\).
- Two stores hold items \(A,B,C\) in quantities \(\begin{bmatrix}7&9&8\\10&5&9\end{bmatrix}\), with one row per store. Unit values are \(10,8,7\) dollars respectively. Find each inventory value and compare them.
Show worked solution
- \(DC=\begin{bmatrix}2\\7\end{bmatrix}\begin{bmatrix}1&6\end{bmatrix}=\begin{bmatrix}2&12\\7&42\end{bmatrix}\). It is a \(2\times1\) by \(1\times2\) product. \(BC\) is undefined and \(AD\) has size \(2\times1\).
- The first product is \(\begin{bmatrix}4&8&12\\5&10&15\\6&12&18\end{bmatrix}\). The second has dimensions \(3\times1\) and \(2\times3\); the inner dimensions do not match, so it is undefined.
- Only \(3\times12\): the second matrix must have \(3\) rows. The product has dimensions \(2\times12\).
- Only \(BA\) exists, since \((7\times2)(2\times8)\) has matching inner dimensions. Its size is \(7\times8\). Sums and differences require identical sizes; \(AB\) would require \(8=7\).
- Matrix multiplication is not commutative in general, but particular pairs can commute (for example, \(A=B=I\)). Thus \(AB\ne BA\) is not universally true. For matching sizes, \(A+B=B+A\), and with the correctly sized identity, \(AI=A\).
- Multiply by the price column: \(\begin{bmatrix}7&9&8\\10&5&9\end{bmatrix}\begin{bmatrix}10\\8\\7\end{bmatrix}=\begin{bmatrix}198\\203\end{bmatrix}\). Store 1 is worth \(198\) dollars and Store 2 is worth \(203\) dollars, so Store 2 is higher by \(5\) dollars.
Read dimensions and entries
Count rows before columns. Indices name row first, then column.
- For \(B=\begin{bmatrix}6&4&24\\1&-9&8\end{bmatrix}\), find \(b_{11},b_{13},b_{23}\).
- State the dimensions of \(\begin{bmatrix}1&4&6&1\\2&-2&1&4\\6&-8&1&-1\end{bmatrix}\).
- State the dimensions of \(\begin{bmatrix}2&1&4\end{bmatrix}\).
- State the dimensions of \(\begin{bmatrix}6&2&-2&8&1\\2&6&7&5&0\\1&1&-4&3&0\\7&0&9&4&-4\end{bmatrix}\).
- State the dimensions of \(\begin{bmatrix}5&0&6&1\\-2&-4&2&6\end{bmatrix}\).
Show worked solution
- Read the specified positions: \(b_{11}=6\), \(b_{13}=24\), \(b_{23}=8\).
- There are \(3\) rows and \(4\) columns: \(3\times4\).
- There are \(1\) rows and \(3\) columns: \(1\times3\).
- There are \(4\) rows and \(5\) columns: \(4\times5\).
- There are \(2\) rows and \(4\) columns: \(2\times4\).
More matrix calculations
Show the arithmetic in corresponding positions. For a product, multiply each row by each column.
- Calculate \(-4\begin{bmatrix}4&1\\-5&0\\1&-3\end{bmatrix}\).
- Calculate \(-2\begin{bmatrix}2&1\\0&-3\end{bmatrix}-6\begin{bmatrix}0&3\\-1&4\end{bmatrix}\).
- Calculate \(\begin{bmatrix}-5&2&-2\\4&-2&0\end{bmatrix}-\begin{bmatrix}6&-5&-6\\1&3&-3\end{bmatrix}\).
- Calculate \(\begin{bmatrix}1&1\\6&-4\\0&0\end{bmatrix}+5\begin{bmatrix}-4&6\\1&1\\-4&-1\end{bmatrix}\).
- Calculate \(\begin{bmatrix}-1&1\\2&-6\\1&0\end{bmatrix}\begin{bmatrix}1&5&0\\-3&2&-2\end{bmatrix}\).
Show worked solution
- Multiply every entry by \(-4\): \(\begin{bmatrix}-16&-4\\20&0\\-4&12\end{bmatrix}\).
- The scaled matrices are \(\begin{bmatrix}-4&-2\\0&6\end{bmatrix}\) and \(\begin{bmatrix}0&18\\-6&24\end{bmatrix}\). Subtract to obtain \(\begin{bmatrix}-4&-20\\6&-18\end{bmatrix}\).
- Subtract entrywise: \(\begin{bmatrix}-11&7&4\\3&-5&3\end{bmatrix}\).
- Scale the second matrix to \(\begin{bmatrix}-20&30\\5&5\\-20&-5\end{bmatrix}\), then add: \(\begin{bmatrix}-19&31\\11&1\\-20&-5\end{bmatrix}\).
- For example, entry \((2,1)\) is \(2(1)+(-6)(-3)=20\). Applying row–column products throughout gives \(\begin{bmatrix}-4&-3&-2\\20&-2&12\\1&5&0\end{bmatrix}\).
Reasoning, modeling and matrix challenges
You can now calculate matrix operations. The next step is to decide what a calculation means and what it can tell you. These problems use the same row-by-column rule; no inverse-matrix method is needed.
Application · Recover the prices
A school stall sells notebooks and pens at fixed prices. On Monday it sells \(2\) notebooks and \(3\) pens for \(90\) pesos; on Tuesday it sells \(4\) notebooks and \(2\) pens for \(140\) pesos. Write the matrix equation, recover both prices, and explain why matching the product labels matters.
Hint
Use a price column in the same order as the quantity columns. Eliminate one unknown using the two revenue equations.
Show worked solution
The rows give \(2n+3p=90\) and \(4n+2p=140\). Double the first equation and subtract the second: \(4p=40\), so \(p=10\). Substitution gives \(n=30\). A notebook costs \(30\) pesos and a pen \(10\) pesos. Both original revenues check. If the price column were reversed without reversing the quantity columns, the dimensions would still match, but quantities would be multiplied by the wrong prices.
Reasoning · When does cancellation fail?
Let \(A=\begin{bmatrix}1&0\\0&0\end{bmatrix}\). Find every \(2\times2\) matrix \(X\) satisfying \(AX=A\). Does \(AX=AI\) imply \(X=I\)? Explain the information that the product loses.
Hint
Write the four entries of X as variables and multiply. Which row survives?
Show worked solution
Equality with \(A\) requires \(a=1\) and \(b=0\), but puts no restrictions on \(c,d\). Thus every solution is \(X=\begin{bmatrix}1&0\\c&d\end{bmatrix}\) with \(c,d\in\mathbb R\). For example, \(X=A\ne I\) satisfies the equation. Left multiplication by \(A\) erases the second row. Cancelling a nonzero matrix is not justified merely because cancelling a nonzero real number is valid.
Advanced / Honors · Describe all commuting matrices
Let \(A=\begin{bmatrix}1&1\\0&1\end{bmatrix}\). Determine all real \(2\times2\) matrices \(B\) for which \(AB=BA\). Then decide whether all such matrices commute with one another.
Hint
Use four unknown entries in B. Compare all four entries of AB and BA, and then multiply two matrices of the form you obtain.
Show worked solution
Comparing entries gives \(c=0\) and \(d=a\), with no restriction on \(a,b\). Hence exactly the matrices \(B=\begin{bmatrix}a&b\\0&a\end{bmatrix}\) commute with \(A\). For \(C=\begin{bmatrix}u&v\\0&u\end{bmatrix}\), both \(BC\) and \(CB\) equal \(\begin{bmatrix}au&av+bu\\0&au\end{bmatrix}\), since real scalar multiplication commutes. This proves the second claim for this family, not for arbitrary matrices.
