No history yet

Vectors and Matrices

What are Vectors?

Think about giving someone directions. You might say, "Walk two blocks east and then one block north." That instruction has two key pieces of information: distance (magnitude) and direction. A vector is just that—a quantity that has both magnitude and direction.

In linear algebra, we represent vectors as an ordered list of numbers, often written vertically in a column. Each number corresponds to a coordinate in space. For a 2D plane, a vector has two numbers. For 3D space, it has three.

v=[21]\vec{v} = \begin{bmatrix} 2 \\ 1 \end{bmatrix}

This vector v\vec{v} represents a movement of 2 units along the horizontal x-axis and 1 unit along the vertical y-axis. It's an arrow pointing from the origin (0,0) to the point (2,1).

Vector Operations

Vectors wouldn't be very useful if we couldn't do math with them. The two most basic operations are addition and scalar multiplication.

Vector Addition Adding two vectors is like following one set of directions after another. If you have vector a\vec{a} (go 2 blocks east, 1 block north) and vector b\vec{b} (go 1 block east, 3 blocks north), adding them together gives you a new vector that represents the total displacement. You just add the corresponding components.

a+b=[21]+[13]=[2+11+3]=[34]\vec{a} + \vec{b} = \begin{bmatrix} 2 \\ 1 \end{bmatrix} + \begin{bmatrix} 1 \\ 3 \end{bmatrix} = \begin{bmatrix} 2+1 \\ 1+3 \end{bmatrix} = \begin{bmatrix} 3 \\ 4 \end{bmatrix}

Scalar Multiplication A scalar is just a regular number, like 5, -2, or π\pi. Multiplying a vector by a scalar scales its magnitude. If you multiply a vector by 2, it becomes twice as long in the same direction. If you multiply it by -1, it flips to point in the opposite direction.

Lesson image

To perform scalar multiplication, you multiply each component of the vector by the scalar.

3×[21]=[3×23×1]=[63]3 \times \begin{bmatrix} 2 \\ 1 \end{bmatrix} = \begin{bmatrix} 3 \times 2 \\ 3 \times 1 \end{bmatrix} = \begin{bmatrix} 6 \\ 3 \end{bmatrix}

Organizing Data with Matrices

If a vector is a list of numbers, a matrix is a grid of numbers, arranged in rows and columns. Matrices are incredibly useful for storing data and representing relationships between different pieces of information. For example, a matrix could store the pixel values of a grayscale image or the weights of connections in a neural network.

A matrix is described by its dimensions: rows by columns. A 3×23 \times 2 matrix has 3 rows and 2 columns.

Lesson image
A=[582174]A = \begin{bmatrix} 5 & 8 \\ 2 & 1 \\ 7 & 4 \end{bmatrix}

Here, A is a 3×23 \times 2 matrix. The element in the first row and second column is 8.

Basic Matrix Operations

Just like vectors, matrices have their own set of rules for arithmetic.

Matrix Addition You can add two matrices only if they have the same dimensions. The process is simple: you add the corresponding elements in each position. If you add two 2×22 \times 2 matrices, the result will be another 2×22 \times 2 matrix.

[1234]+[5678]=[1+52+63+74+8]=[681012]\begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix} + \begin{bmatrix} 5 & 6 \\ 7 & 8 \end{bmatrix} = \begin{bmatrix} 1+5 & 2+6 \\ 3+7 & 4+8 \end{bmatrix} = \begin{bmatrix} 6 & 8 \\ 10 & 12 \end{bmatrix}

Matrix Multiplication Matrix multiplication is a bit more involved than addition. To multiply two matrices, the number of columns in the first matrix must equal the number of rows in the second. For example, you can multiply a 3×23 \times 2 matrix by a 2×42 \times 4 matrix, and the result will be a 3×43 \times 4 matrix.

To find the element in row ii and column jj of the resulting matrix, you take the dot product of row ii from the first matrix and column jj from the second matrix. This means you multiply their corresponding entries and then sum the products.

One important thing to remember: The order of multiplication matters for matrices! In general, A×BA \times B is not the same as B×AB \times A.

[1234][5678]=[(15+27)(16+28)(35+47)(36+48)]=[19224350]\begin{align*} \begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix} \begin{bmatrix} 5 & 6 \\ 7 & 8 \end{bmatrix} &= \begin{bmatrix} (1 \cdot 5 + 2 \cdot 7) & (1 \cdot 6 + 2 \cdot 8) \\ (3 \cdot 5 + 4 \cdot 7) & (3 \cdot 6 + 4 \cdot 8) \end{bmatrix} \\ &= \begin{bmatrix} 19 & 22 \\ 43 & 50 \end{bmatrix} \end{align*}

Matrix Transposition The transpose of a matrix, denoted with a superscript TT, is what you get when you swap the rows and columns. The first row becomes the first column, the second row becomes the second column, and so on.

A=[582174]AT=[527814]A = \begin{bmatrix} 5 & 8 \\ 2 & 1 \\ 7 & 4 \end{bmatrix} \quad A^T = \begin{bmatrix} 5 & 2 & 7 \\ 8 & 1 & 4 \end{bmatrix}

Notice how the 3×23 \times 2 matrix becomes a 2×32 \times 3 matrix after transposition. This operation is useful in many areas, including solving systems of linear equations.

Quiz Questions 1/6

What are the two key components that define a vector?

Quiz Questions 2/6

Given two vectors, a=[35]\vec{a} = \begin{bmatrix} 3 \\ 5 \end{bmatrix} and b=[12]\vec{b} = \begin{bmatrix} -1 \\ 2 \end{bmatrix}, what is their sum a+b\vec{a} + \vec{b}?

Vectors and matrices are the building blocks of linear algebra. Understanding how to represent and manipulate them is the first step toward tackling more complex problems in fields from computer graphics to machine learning.