Skip to the lesson
FixTheRobot Explore Robotics / Linear Algebra / M2 Matrices and Linear Transformations / M2-T1

Linear Algebra · Theory · M2

M2-T1 — Introduction to Matrices

A matrix is a rectangle of numbers with two jobs: it stores data, and it transforms vectors. Robotics software uses both constantly.

  • Lesson 1 of 7
  • Module 2: Matrices and Linear Transformations
  • Matrices
  • About 9 minutes to read

Open any robotics codebase and you will find matrices everywhere: point clouds, camera intrinsics, covariances, rotations, Jacobians. This lesson gives you the vocabulary (shape, entry, row, column, transpose) and the two ways to read a matrix that the rest of the course builds on.

Learning objectives

After this lesson, you should be able to:

  • Name the shape of a matrix, address its entries by row and column, and say what rows and columns mean for a data table.
  • Form the transpose, and recognise identity, diagonal, symmetric and skew-symmetric matrices.
  • Explain the two roles of a matrix: a table of numbers and a rule that maps vectors to vectors.
  • Split any square matrix into a symmetric and a skew-symmetric part.

Introduction and motivation

A LiDAR scan with a thousand returns is a thousand pairs of numbers. A camera's calibration is nine numbers arranged in three rows. A robot's position uncertainty is four numbers describing an ellipse. A rotation, a Jacobian, a covariance: all matrices. Learning to read them fluently is the single most useful habit in robot mathematics, because it lets you see that very different problems share one structure.

This lesson is deliberately about meaning, not calculation. The calculations (products, inverses, decompositions) start in the next lessons; here you learn what the rectangle is.

The intuition

Think of a spreadsheet. Each row is one record, say one LiDAR point, and each column is one variable, say its x coordinate or its y coordinate. A matrix is exactly that spreadsheet, with the rule that every cell holds a number and the grid is rectangular. Stack 1,000 points in 3D and you get a 1,000 × 3 matrix.

A point cloud as a matrix and its transposeA matrix with three rows and two columns holds three robot-frame points, one point per row with x in the first column and y in the second. Its transpose has two rows and three columns: the x values form the first row and the y values the second.123144x y p₁p₂p₃ P: 3 × 2 (3 points, 2 coordinates) entry p₂₁ = 3: row 2, column 1 transpose 134214p₁ p₂ p₃ Pᵀ: 2 × 3rows and columns swapped In code: P.shape = (3, 2)Pᵀ.shape = (2, 3) Row = one measurement.Column = one variable.
A point cloud as a 3 × 2 matrix: rows are points, columns are coordinates. The transpose swaps rows and columns, turning 3 × 2 into 2 × 3.

The second reading is more powerful. Fix a 2 × 2 matrix and feed it any arrow: out comes another arrow. A matrix is a machine that transforms vectors. The same four numbers that were a table a moment ago now stretch, turn or flip the plane. Which reading is right depends on how you use it, and good engineers switch between them without noticing.

Interactive figure. A two by two matrix acts on the plane. The F-shaped outline and the unit square are transformed; two arrows show where the basis vectors land, which are the columns of the matrix. The readout gives the matrix, its determinant and whether it can be undone. This figure needs JavaScript to be interactive.

Drag the two handles. The four numbers of the matrix are the coordinates of the two arrows. The F shape shows what the whole plane does to a shape.

Geometric and physical interpretation

Geometric view. A 2 × 2 matrix deforms the whole plane at once: the grid lines stay straight and evenly spaced, but they can be rotated, stretched, sheared or flipped. Tracking where two arrows land (the next lesson shows these are the columns) is enough to know what happens to every shape. Physical view. A matrix is a linear device: double the input and the output doubles, add two inputs and the outputs add. A rotation of the robot, a change of sensor units and a small change in joint angles all behave this way (the last one only approximately, which is the subject of Module 8).

The mathematics

A
a matrix with m rows and n columns, called an m × n matrix (rows first).
aij
the entry in row i and column j of A. In code with zero-based indexing it is A[i-1][j-1].
Aᵀ
the transpose of A: the n × m matrix with (Aᵀ)ij = aji.
I
the identity matrix: ones on the diagonal and zeros elsewhere.

Shape and entries

A = [ a11  a12  ...  a1n ]
    [ a21  a22  ...  a2n ]       an m × n matrix: m rows, n columns
    [ ...             ]
    [ am1  am2  ...  amn ]

What it means. Every matrix is a rectangular grid. The first index counts down the rows and the second counts across the columns, so the shape is always written rows × columns.

The transpose

(Aᵀ)ij = aji           (Aᵀ)ᵀ = A           (A + B)ᵀ = Aᵀ + Bᵀ

What it means. Transposing mirrors the matrix across its diagonal: row i becomes column i. Doing it twice returns the original. A list of points stored as rows becomes a list of points stored as columns.

Special matrices

  • Identity I: leaves every vector unchanged. It is the “do nothing” transformation.
  • Diagonal: nonzero only on the diagonal. It stretches each axis independently (a unit conversion, a scaling).
  • Symmetric: Aᵀ = A. Covariance matrices are symmetric, which is why Module 6 can say so much about them.
  • Skew-symmetric: Aᵀ = −A. These encode rotations at the infinitesimal level and appear again in Module 7 and Module 10.
A = S + K,     S = (A + Aᵀ) / 2,     K = (A − Aᵀ) / 2

What it means. S contains whatever in A is mirror-symmetric across the diagonal, and K contains the rest. Nothing is lost: adding them back reproduces A. This split reappears when a velocity-like quantity is separated into stretching and rotating.

A matrix has a shape (rows × columns) and entries aij. It is both a table and a transformation: read it the way the problem needs.

Step-by-step derivation: every square matrix is symmetric plus skew-symmetric

Take any square matrix A. We show that S = (A + Aᵀ)/2 is symmetric, that K = (A − Aᵀ)/2 is skew-symmetric, and that S + K = A.

  1. S is symmetric. Using (A + B)ᵀ = Aᵀ + Bᵀ, (Aᵀ)ᵀ = A and that a factor ½ passes through the transpose: Sᵀ = (Aᵀ + (Aᵀ)ᵀ)/2 = (Aᵀ + A)/2 = S.
  2. K is skew-symmetric. Kᵀ = (Aᵀ − (Aᵀ)ᵀ)/2 = (Aᵀ − A)/2 = −(A − Aᵀ)/2 = −K.
  3. They add up to A. S + K = (A + Aᵀ + A − Aᵀ)/2 = 2A/2 = A.
  4. The diagonal of K is zero. A skew-symmetric matrix has kii = −kii, which forces kii = 0. So a skew-symmetric 3 × 3 matrix has only three free numbers: exactly enough to hold a 3D vector (this is why the cross-product matrix of Module 7 has that shape).

The decomposition is unique: if A = S′ + K′ with S′ symmetric and K′ skew, then transposing gives Aᵀ = S′ − K′, and adding and subtracting the two equations returns the same S and K.

A worked example: a small point cloud and a symmetric/skew split

Shape and indexing. Three points in the robot frame are stored as the rows of P = [[1, 2], [3, 1], [4, 4]] (metres). Then P is 3 × 2, Pᵀ is 2 × 3, and the entry p₂₁ = 3 is the x coordinate of the second point.

Symmetric and skew parts. Let A = [[2, 1], [3, 4]].

  1. Aᵀ = [[2, 3], [1, 4]].
  2. S = (A + Aᵀ)/2 = [[4, 4], [4, 8]]/2 = [[2, 2], [2, 4]], a symmetric matrix.
  3. K = (A − Aᵀ)/2 = [[0, −2], [2, 0]]/2 = [[0, −1], [1, 0]], with zero diagonal, as predicted.
  4. Check. S + K = [[2, 1], [3, 4]] = A.

Memory. One million LiDAR points in 3D stored as 32-bit floats take 10⁶ × 3 × 4 bytes = 12 MB, which is why point-cloud code cares about the shape and the data type of its matrices.

Robotics application

Point clouds. A scan is an N × 3 matrix (one point per row). Almost every operation in the next modules, from fitting a plane to transforming into another frame, is a statement about this matrix.

Camera and sensor calibration. A pinhole camera's intrinsic matrix is a 3 × 3 matrix mapping directions to pixels. Its entries have physical meaning (focal lengths, image centre), and reading them as a table is how you debug a calibration.

Covariance. A robot's position uncertainty is a symmetric matrix; the symmetric/skew split above explains why a covariance that becomes slightly asymmetric through rounding is easy to repair: take S = (A + Aᵀ)/2. Filters do this routinely, and you will use it in Module 9. See also the SLAM track on probability and uncertainty.

Rotation and Jacobians. A rotation of the robot is a matrix, and a manipulator's Jacobian is a matrix whose columns say how each joint moves the hand. Both arrive in later modules; both are just matrices in the sense of this lesson.

Engineering implications and limitations

Practical rules

  • Shape errors are the most common matrix bug. Print and assert shapes at the boundaries of every function. “3 × N or N × 3?” has no universal answer: decide once, document it, and write assert P.shape[1] == 3.
  • Rows × columns, always. A 1 × 3 row vector and a 3 × 1 column vector are different shapes, and libraries treat a plain 1D array differently again. Be explicit about which you mean.
  • Indexing starts at 0 in code and at 1 in mathematics. a12 on paper is A[0][1] in Python.
  • Check symmetry with a tolerance. A covariance that should be symmetric is almost never exactly so after floating-point arithmetic. Use max|A − Aᵀ| < tol and symmetrise when needed.
  • Storage order matters for speed. Row-major and column-major layouts differ; iterating along the wrong axis can be many times slower on large point clouds.

Limits

The picture of a matrix as a transformation of the plane is exact for any matrix whose input and output spaces are both flat vector spaces. Nonlinear effects (a camera's lens distortion, a robot arm far from its reference pose) are not matrices; they are approximated by matrices locally, which is the idea behind the Jacobian.

Common misconceptions

“A matrix is just an array of numbers.”

It is an array that also defines a transformation, and the transformation is what most of linear algebra is about. The same array can be data in one function and an operator in the next.

“A matrix and its transpose do the same thing.”

They are different transformations in general. Only for symmetric matrices is Aᵀ = A. For a rotation, the transpose is the opposite rotation (Module 7).

“Shape does not matter if the numbers are right.”

Shape decides which operations are even defined. A 3 × 2 matrix cannot multiply a 3-vector on the right, and mixing up N × 3 with 3 × N silently produces nonsense in code that broadcasts.

“Only square matrices are important.”

Data matrices (N × 3 point clouds) and Jacobians of redundant robots are rectangular. Much of this course is about what rectangular matrices can and cannot do.

Engineering takeaways

  1. A matrix is a rectangular grid: m rows, n columns, entries aij, with the shape always written rows × columns.
  2. Rows are usually records (points) and columns variables (coordinates); the transpose swaps them.
  3. A matrix also transforms vectors: it is a linear machine, which the next lessons make precise.
  4. Identity, diagonal, symmetric and skew-symmetric matrices have special roles: do nothing, scale axes, covariance, and infinitesimal rotation.
  5. Every square matrix is a symmetric part plus a skew-symmetric part, and the split is unique.

References and further reading

Primary papers and authoritative documentation.

Knowledge check

Three conceptual questions. Write an answer, then reveal the explanation. Your answers stay in your browser.

Question 1

A depth camera returns a 480 × 640 image of distances. A colleague stores the points of a LiDAR scan as a 3 × N matrix, you store them as N × 3. What can go wrong when you exchange code, and how would you prevent it?

Explanation

Any function that expects one layout silently misinterprets the other when the shapes happen to broadcast, or raises a shape error when they do not; with square or small N the mistake can even produce plausible-looking wrong numbers. Prevent it by fixing a convention, writing it in the function documentation, and asserting the shape (for example P.shape[1] == 3) at the start of every function. The transpose converts between the two layouts.

Question 2

Why must a covariance matrix be symmetric, and how would you repair one that has become slightly asymmetric through rounding? Which part of the matrix are you throwing away?

Explanation

The covariance of x with y equals the covariance of y with x, so entry (i, j) equals entry (j, i): the matrix equals its transpose. A rounding-damaged matrix is repaired by replacing it with its symmetric part, S = (A + Aᵀ)/2. What is discarded is the skew-symmetric part K = (A − Aᵀ)/2, which for a true covariance is zero and in a damaged one is only rounding noise.

Question 3

Why does a skew-symmetric 3 × 3 matrix have exactly three free numbers? What familiar object in 3D also has three numbers?

Explanation

Skew-symmetry means aji = −aij and forces the diagonal to zero, so only the three entries above the diagonal are free; the three below are their negatives. A 3D vector also has three components, and in Module 7 you will see that every 3D vector corresponds to one skew-symmetric matrix that acts like “cross product with that vector”.

What’s next

You know what a matrix is. Next you will learn to combine matrices: addition, scaling and, above all, the matrix product, whose order-dependent rules explain many bugs in robot code.

Next lesson

M2-T2 — Matrix Operations and Multiplication

Add, scale, transpose and multiply matrices, check that shapes agree, and explain why the order of a product matters.

Nothing below is required to finish this lesson.