WordGPT
โ† Math: from algebra to machine learning

Linear algebra ยท Part 2 of 5

Matrices and their operations

Learn what a matrix is and how to add, scale, transpose, and multiply matrices, with careful attention to when each operation is defined.

Linear algebra15 min read

A single number can describe a temperature or a price, but many real situations need a whole grid of numbers at once: the inventory of a store (items by warehouse), the pixels of an image, the coefficients of several linear equations. A matrix is just a rectangular array of numbers, and matrix operations are the rules for combining such grids.

The surprise is that matrices cannot always be combined the way numbers can. Adding two matrices requires them to have the same shape, and multiplying them requires a matching condition between inner dimensions. Getting these rules right is the main skill of this lesson, and it is the foundation for everything that follows: solving linear systems, computing determinants, and representing linear maps.

What a matrix is

A matrix is a rectangular array of numbers with rows and columns; we say its size is (rows first, then columns). We write entries with double subscripts: is the entry in row , column .

Here is , with , , . A matrix with one row is a row vector; with one column, a column vector (the objects from the previous lesson). A square matrix has the same number of rows and columns. Two matrices are equal only if they have the same size and every pair of matching entries is equal.

The identity matrix is the matrix with 1s on the diagonal and 0s elsewhere; for example . It plays the role of the number 1 in matrix multiplication.

Addition and scalar multiplication

Two matrices can be added only if they have the same size; the sum is formed entry by entry. There is no way to add a matrix to a one.

Multiplying a matrix by a number (a scalar) means multiplying every entry by that number:

Both operations behave exactly like their vector counterparts: addition is commutative and associative, (the zero matrix of the same size), and scalars distribute over sums: .

Example 1. Combining two matrices Compute where and .

First scale entry by entry:

Then subtract entry by entry:

Matrix multiplication: the row-times-column rule

Matrix multiplication is the operation that encodes composing linear maps, and its rule looks odd at first: to get the entry in row , column of , take row of and column of , multiply them pairwise, and add up.

For this to make sense, the number of columns of must equal the number of rows of . If is and is , then is . A quick way to remember: write the sizes side by side, ; the inner numbers must match and they cancel, leaving the outer ones as the size of the product.

A concrete case, times :

Two crucial consequences: in general (multiplication is not commutative), and is possible even when neither factor is zero. Also, whenever the sizes allow the products.

Interactive 2x2 matrix transformation showing the unit square mapped by the matrix [[1,2],[3,4]], illustrating that the order of two matrix multiplications changes the result.det = -2
Drag the entries to see the matrix transform the plane. With A = [[1,2],[3,4]] and B = [[0,1],[1,0]] from the example, applying A then B lands somewhere different from B then A โ€” that is why AB โ‰  BA.

Example 2. A basic product Compute where and .

Entry : row 1 of times column 1 of :

Entry : row 1 of times column 2 of :

Entry : row 2 of times column 1 of :

Entry : row 2 of times column 2 of :

So

Notice , a different matrix: order matters.

Example 3. A non-square product Compute where () and ().

Inner sizes match (), so the product is defined and is .

Entry : row 1 of with column 1 of :

Entry : row 1 of with column 2 of :

Entry : row 2 of with column 1 of :

Entry : row 2 of with column 2 of :

So

The reverse product would be โ€” a completely different size, another reminder that and need not even be comparable.

Powers and the identity

Since square matrices can be multiplied by themselves, powers make sense: , , and so on. Only square matrices have powers, because requires the columns of to match the rows of .

The identity matrix behaves like 1: for any square . Also, by convention, and powers combine as expected: . But because multiplication is not commutative, in general โ€” the middle terms are , which do not merge unless and happen to commute.

Example 4. Squaring a matrix Compute for , and verify that .

Apply the row-times-column rule to .

Entry : row 1 of times column 1 of :

Entry : row 1 of times column 2 of :

Entry : row 2 of times column 1 of :

Entry : row 2 of times column 2 of :

So

Check by substituting back: , which matches entry for entry, so the claim holds.

Transpose

The transpose of a matrix flips it across its main diagonal: row of becomes column of . An matrix becomes .

Useful rules: , , , and โ€” note the reversal โ€” . A matrix equal to its own transpose is called symmetric; symmetric matrices must be square.

Example 5. Transpose of a product Verify for and .

First compute the product:

Its transpose is

Now compute the other side:

Both sides agree, confirming the reversal rule.

Matrices acting on vectors

One of the most important uses of a matrix is multiplying it by a vector. If is and is a column vector with entries, then is a column vector with entries, computed by the same row-times-column rule: entry of the result is row of dotted with .

This is exactly how a linear map acts on a vector, and it connects to the previous lesson: each row of takes a dot product with . It also explains why matrix multiplication is defined the way it is โ€” composing two such maps corresponds to multiplying their matrices, with the row-times-column rule falling out automatically.

Interactive grid showing the linear map [[2,-1],[0,3]] sending basis vectors e1 to (2,0) and e2 to (-1,3), with a draggable input vector and its image Av.det = 6
The matrix A = [[2,-1],[0,3]] from the lesson acting on vectors: drag the input vector and watch each output coordinate come from a row of A dotted with it. Notice e1 maps to (2, 0) and e2 maps to (-1, 3), the columns of A.

Example 6. Matrix times vector Compute for and .

First entry: row 1 dotted with :

Second entry: row 2 dotted with :

So

A matrix turned a 3-dimensional vector into a 2-dimensional one.

What a matrix does to the plane

A matrix is not literally a parallelogram. It is a grid of numbers that describes a transformation of the plane: a rule that moves every point to a new point .

The whole rule is decided by where two arrows go: and , the two sides of the unit square. Multiplying shows what happens to them.

So the first column of is where lands, and the second column is where lands.

A transformation like this keeps the origin where it is, keeps straight lines straight and keeps parallel lines parallel. The unit square has corners , , and . It therefore lands on a four-sided shape with corners , , and . Its opposite sides are parallel and equal, so the shape is always a parallelogram, the image of the unit square.

The area of that parallelogram is , the absolute value of the determinant. The original square has area , so tells you how much the matrix scales every area in the plane. A negative determinant means the plane is also flipped over, like a reflection in a mirror. A determinant of flattens the parallelogram onto a line segment or a point.

Interactive picture of a 2x2 matrix with four sliders. The unit square becomes a parallelogram whose sides are the columns of the matrix, drawn as a red and a green arrow. For the starting matrix with rows (3, 1) and (1, 2) the area is 5.det = 5
The red arrow is the first column of the matrix, where (1, 0) lands, and the green arrow is the second column, where (0, 1) lands. The shaded parallelogram is what the unit square becomes, and its area is the absolute value of det.

Example 7. Where the unit square goes Let . Find where the corners , and of the unit square land.

The first column is where lands and the second column is where lands.

The corner is the sum of the two, so it lands at the sum of the columns.

The unit square becomes the parallelogram with corners , , and .

Example 8. The area of the parallelogram What is the area of the parallelogram that makes of the unit square?

The area is the absolute value of the determinant.

The determinant is positive, so the plane is not flipped, and the parallelogram has area . Every region of the plane is made times larger by .

Example 9. A matrix that flips the plane What does do to the unit square, and what is its determinant?

The columns are and , so lands on and lands on . The two sides swap places and the unit square lands on itself, with its corners exchanged. That is a reflection in the line .

The area stays , because . The minus sign records that the plane was flipped over.

Common mistakes

  • Adding matrices of different sizes entry-wise or declaring the extra entries zero โ€” addition is only defined when both matrices have exactly the same size.
  • Multiplying in the wrong order or assuming โ€” matrix multiplication is not commutative, and the sizes may not even allow the reversed product.
  • Reversing the size rule as 'rows must match' โ€” it is the columns of the left matrix that must equal the rows of the right matrix.
  • Computing as โ€” the correct rule reverses the order: .
  • Expanding as โ€” the correct expansion is , and and generally do not combine.
  • Using the rows of as the places where and land; it is the columns, so lands on the first column.
  • Saying the matrix is a parallelogram; the parallelogram is what the unit square becomes, and the matrix is the rule that does it.

Practice

  1. Compute the sum where and .
  2. Compute where and .
  3. Compute the matrix product (in that order) where and .
  4. Compute (matrix product of with itself) for .
  5. Let and . Compute the column vector , then transpose it and give the resulting row vector.
Answers
  1. , adding each pair of matching entries.
  2. , since and .
  3. , using the row-times-column rule.
  4. , computed with the row-times-column rule applied to .
  5. , so , a row vector.

Next, in Determinants and inverses, you will learn when a square matrix can be 'undone' and how to compute the number that decides it.

Part of the free WordGPT Learn section. WordGPT is an AI writing workspace for documents, resumes, websites and study.

    Matrices and their operations โ€” Math: from algebra to machine learning | WordGPT