Lesson 5 of 9 · Linear algebra foundation

A matrix is a recipe for moving vectors.

Your win: multiply a 2D vector by the rotation matrix and recognize the same coordinate rules from complex multiplication.

14 minutesNeeds: Lesson 4 expansionOutcome: apply \(R_\theta\)
Mission link: RoPE implementations use real-valued tensors. The matrix view expresses the same complex rotation using ordinary real arithmetic.

Rows produce output coordinates

Multiplying a \(2\times2\) matrix by a two-component column vector forms one dot product per row:

\[ \begin{bmatrix}a&b\\c&d\end{bmatrix} \begin{bmatrix}x\\y\end{bmatrix} = \begin{bmatrix}ax+by\\cx+dy\end{bmatrix}. \]

The rotation recipe

\[ \underbrace{\begin{bmatrix} \cos\theta&-\sin\theta\\ \sin\theta& \cos\theta \end{bmatrix}}_{R_\theta} \begin{bmatrix}x\\y\end{bmatrix} = \begin{bmatrix} x\cos\theta-y\sin\theta\\ x\sin\theta+y\cos\theta \end{bmatrix}. \]

The output is exactly the pair obtained from \((x+iy)e^{i\theta}\). Complex multiplication and matrix multiplication are two notations for the same motion.

A quarter turn

At \(\theta=\pi/2\), \(\cos\theta=0\) and \(\sin\theta=1\):

\[ R_{\pi/2} =\begin{bmatrix}0&-1\\1&0\end{bmatrix}, \qquad R_{\pi/2}\begin{bmatrix}x\\y\end{bmatrix} =\begin{bmatrix}-y\\x\end{bmatrix}. \]

A 90° counterclockwise turn maps \((x,y)\) to \((-y,x)\).

Numbers substituted: \(R_{\pi/2}(3,2)\)

\[ \begin{aligned} R_{\pi/2}\begin{bmatrix}3\\2\end{bmatrix} &= \begin{bmatrix}0&-1\\1&0\end{bmatrix} \begin{bmatrix}3\\2\end{bmatrix}\\ &= \begin{bmatrix}0(3)+(-1)(2)\\1(3)+0(2)\end{bmatrix} = \begin{bmatrix}-2\\3\end{bmatrix}. \end{aligned} \]

Numbers substituted: \(R_{\pi/6}(2,0)\)

\[ \begin{aligned} R_{\pi/6}\begin{bmatrix}2\\0\end{bmatrix} &= \begin{bmatrix}\sqrt3/2&-1/2\\1/2&\sqrt3/2\end{bmatrix} \begin{bmatrix}2\\0\end{bmatrix}\\ &=\begin{bmatrix}\sqrt3\\1\end{bmatrix}. \end{aligned} \]

This matches the complex-number calculation in Lesson 4.

Numbers substituted: \(R_{\pi}(-1,4)\)

\[ \begin{bmatrix}-1&0\\0&-1\end{bmatrix} \begin{bmatrix}-1\\4\end{bmatrix} = \begin{bmatrix}1\\-4\end{bmatrix}. \]

A half turn negates both coordinates.

Columns show where the basis goes

First basis vector

\(R_\theta\begin{bmatrix}1\\0\end{bmatrix}=\begin{bmatrix}\cos\theta\\\sin\theta\end{bmatrix}\)

The first column is the rotated x-axis.

Second basis vector

\(R_\theta\begin{bmatrix}0\\1\end{bmatrix}=\begin{bmatrix}-\sin\theta\\\cos\theta\end{bmatrix}\)

The second column is the rotated y-axis.

Retrieval check

Which output is \(R_{\pi/2}(x,y)\)?

Practice before moving on

  1. Compute \(R_{\pi/2}\begin{bmatrix}4\\-1\end{bmatrix}\).
  2. Compute \(R_{\pi}\begin{bmatrix}2\\5\end{bmatrix}\).
  3. Compute \(R_{0}\begin{bmatrix}-3\\7\end{bmatrix}\).
  4. Use \(R_{\pi/4}\) to rotate \((\sqrt2,0)\).
  5. Verify by lengths that \((3,2)\) and its quarter-turn output \((-2,3)\) have equal magnitude.
  6. Explain what the two columns of \(R_{\pi/2}\) say geometrically.
Check solutions
  1. \(\begin{bmatrix}1\\4\end{bmatrix}\).
  2. \(\begin{bmatrix}-2\\-5\end{bmatrix}\).
  3. \(\begin{bmatrix}-3\\7\end{bmatrix}\).
  4. \(\begin{bmatrix}1\\1\end{bmatrix}\).
  5. Both squared magnitudes are \(13\).
  6. The x-axis basis goes to \((0,1)\), and the y-axis basis goes to \((-1,0)\).
Pairwise form: a full RoPE matrix is block diagonal: one \(2\times2\) rotation block per adjacent pair, with zeros between different pairs.

Primary source: MIT OCW: Linear Transformations and Their Matrices. Watch for the idea that a matrix is determined by where it sends the basis vectors.

Ask the teaching agent to give you a rotation at \(0\), \(\pi/2\), or \(\pi\) to calculate by hand.