No history yet

Vectors and Matrices

Vectors: More Than Just Numbers

In math, some things just have a size, or magnitude. A temperature of 25 degrees, a speed of 60 miles per hour, a price of $5. These are called scalars. But what if you need to describe not just a size, but also a direction? That's where vectors come in.

A vector is like an arrow. It has a length (its magnitude) and it points somewhere (its direction). Think of giving directions: "walk three blocks east." That's a vector. "Walk three blocks" is just a scalar—it tells you how far, but not where.

In linear algebra, we write vectors as ordered lists of numbers, called components. For a 2D vector, we might have something like this:

v=(32)\vec{v} = \begin{pmatrix} 3 \\ 2 \end{pmatrix}

This vector represents a point that is 3 units along the x-axis and 2 units along the y-axis from the origin. Vectors can have any number of dimensions, not just two or three.

Just like with regular numbers, you can perform operations on vectors. When we add or subtract vectors, we simply do it component by component. If we have another vector u\vec{u}:

u=(14)\vec{u} = \begin{pmatrix} 1 \\ 4 \end{pmatrix}

Then their sum is:

v+u=(3+12+4)=(46)\vec{v} + \vec{u} = \begin{pmatrix} 3+1 \\ 2+4 \end{pmatrix} = \begin{pmatrix} 4 \\ 6 \end{pmatrix}

Geometrically, adding vectors looks like placing them head-to-tail. The new vector, called the resultant, goes from the start of the first vector to the end of the second.

We can also multiply a vector by a scalar. This is called scalar multiplication, and it stretches or shrinks the vector's magnitude without changing its direction. Multiplying by a negative scalar reverses the vector's direction.

2v=2(32)=(64)2\vec{v} = 2 \begin{pmatrix} 3 \\ 2 \end{pmatrix} = \begin{pmatrix} 6 \\ 4 \end{pmatrix}

This new vector 2v2\vec{v} points in the same direction as v\vec{v} but is twice as long.

The Dot Product

Besides adding and scaling, there's another important vector operation: the dot product. Instead of giving you another vector, the dot product of two vectors gives you a single number—a scalar. To find it, you multiply the corresponding components of the two vectors and then add up the results.

vu=(3)(1)+(2)(4)=3+8=11\vec{v} \cdot \vec{u} = (3)(1) + (2)(4) = 3 + 8 = 11

So what does this number mean? The dot product tells us something about the angle between the two vectors. It's defined by the formula:

ab=abcos(θ)\vec{a} \cdot \vec{b} = \|\vec{a}\| \|\vec{b}\| \cos(\theta)

Here, a\|\vec{a}\| is the magnitude (length) of vector a\vec{a}, and θ\theta is the angle between the two vectors. If the dot product is zero, it means the vectors are perpendicular (at a 90-degree angle), because cos(90)=0\cos(90^\circ) = 0. This is an incredibly useful property for checking if vectors are orthogonal.

Meet the Matrix

Now, let's move on to matrices. A matrix is just a rectangular grid of numbers arranged in rows and columns. Think of it as a way to organize data or a collection of vectors. The size, or dimension, of a matrix is given by its number of rows and columns. A matrix with mm rows and nn columns is called an m×nm \times n matrix.

Lesson image

There are a few special types of matrices that are good to know.

  • Zero Matrix: A matrix where every entry is 0.
  • Identity Matrix: A square matrix (same number of rows and columns) with 1s on the main diagonal (from top-left to bottom-right) and 0s everywhere else. It's the matrix equivalent of the number 1.
  • Diagonal Matrix: A square matrix where all entries off the main diagonal are 0.
Zero MatrixIdentity MatrixDiagonal Matrix
(0000)\begin{pmatrix} 0 & 0 \\ 0 & 0 \end{pmatrix}(1001)\begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix}(7002)\begin{pmatrix} 7 & 0 \\ 0 & -2 \end{pmatrix}

Making Matrices Work

Like vectors, we can perform operations on matrices. Adding, subtracting, and scalar multiplication are all done element by element, just as you'd expect. For two matrices to be added or subtracted, they must have the exact same dimensions.

A=(1234),B=(5678)A+B=(1+52+63+74+8)=(681012)A = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}, B = \begin{pmatrix} 5 & 6 \\ 7 & 8 \end{pmatrix} \\ A + B = \begin{pmatrix} 1+5 & 2+6 \\ 3+7 & 4+8 \end{pmatrix} = \begin{pmatrix} 6 & 8 \\ 10 & 12 \end{pmatrix}

Matrix multiplication is where things get more interesting. You don't just multiply corresponding elements. Instead, to find the entry in the ii-th row and jj-th column of the product matrix, you take the dot product of the ii-th row of the first matrix and the jj-th column of the second matrix.

Lesson image

Because of this row-by-column rule, you can only multiply two matrices if the number of columns in the first matrix equals the number of rows in the second. If you multiply an m×nm \times n matrix by an n×pn \times p matrix, the result will be an m×pm \times p matrix.

This leads to a very important property: matrix multiplication is generally not commutative. In other words, ABAB is not the same as BABA. Sometimes BABA might not even be a valid operation! However, other properties like associativity (A(BC)=(AB)CA(BC) = (AB)C) and distributivity (A(B+C)=AB+ACA(B+C) = AB+AC) do hold true.

Now, let's test your understanding of these foundational concepts.

Quiz Questions 1/6

What is the primary distinction between a scalar and a vector?

Quiz Questions 2/6

Given the vectors v=[42]\vec{v} = \begin{bmatrix} 4 \\ -2 \end{bmatrix} and u=[15]\vec{u} = \begin{bmatrix} -1 \\ 5 \end{bmatrix}, what is their sum, v+u\vec{v} + \vec{u}?

Vectors and matrices are the building blocks of linear algebra. Understanding how to manipulate them is the first step toward using them to solve complex problems in fields ranging from computer graphics to data science.