2D Matrix Transformations

Matrices are not just boxes of numbers; they are spatial machines. Every 2×2 matrix defines a linear transformation — a rule that stretches, rotates, reflects, or shears the entire coordinate plane. Adjust the transformation matrix below and watch how the grid, the unit square, and the basis vectors physically warp in real-time.

[x', y']ᵀ = M · [x, y]ᵀ
Matrix-Vector Multiplication:
x' = w₁₁·x + w₁₂·y   |   y' = w₂₁·x + w₂₂·y
The first column [w₁₁, w₂₁] is where î lands. The second column [w₁₂, w₂₂] is where ĵ lands.
MATRIX: [ [1, 0], [0, 1] ]
DETERMINANT: [ 1.00 ]
STATUS: [ IDENTITY ]
  w₁₁ (î → x) 1.00
  w₁₂ (ĵ → x) 0.00
  w₂₁ (î → y) 0.00
  w₂₂ (ĵ → y) 1.00
Initializing Python Runtime (Pyodide)...
Applied Matrix Math

Task: Apply a 2×2 transformation matrix M = [[2, 1], [0, 3]] to a target vector v = [2, 3] using NumPy. Print the resulting transformed vector.

Basic Hint

Import numpy. Create the matrix as a 2D array: np.array([[...], [...]]). Create the vector as a 1D array: np.array([...]). Use np.dot(matrix, vector) or the @ operator to multiply them.

Detailed Walkthrough

NumPy handles matrix multiplication for us. Here is the exact expansion:

import numpy as np

# The transformation matrix (2x2)
M = np.array([[2, 1],
              [0, 3]])

# The target vector (1D array, treated as column)
v = np.array([2, 3])

# Matrix-vector multiplication
# Row 1 of M dot v: (2*2) + (1*3) = 7
# Row 2 of M dot v: (0*2) + (3*3) = 9
result = np.dot(M, v)  # or M @ v

print(result)  # Output: [7 9]
// Awaiting execution...
From Scratch

Task: Manually calculate the new coordinates of vector v = [2, 3] after applying the matrix M = [[2, 1], [0, 3]], without using NumPy.

Basic Hint

The new x-coordinate is (w₁₁ * x) + (w₁₂ * y).

The new y-coordinate is (w₂₁ * x) + (w₂₂ * y).

You are multiplying the first matrix row by the vector column to get x', and the second row to get y'.

Detailed Walkthrough

Matrix-vector multiplication, element by element:

# Define the matrix entries
w11, w12 = 2, 1
w21, w22 = 0, 3

# Define the original vector
x, y = 2, 3

# Row 1 of M times the column vector v:
# new_x = (w11 * x) + (w12 * y) = (2*2) + (1*3) = 4 + 3 = 7
new_x = (w11 * x) + (w12 * y)

# Row 2 of M times the column vector v:
# new_y = (w21 * x) + (w22 * y) = (0*2) + (3*3) = 0 + 9 = 9
new_y = (w21 * x) + (w22 * y)

print(f"Transformed vector: [{new_x}, {new_y}]")
# Output: Transformed vector: [7, 9]
// Awaiting execution...