A reader asks:

I know that a square matrix M maps point x to point y. Do I have enough information to work out M?

In a word: no, unless you’re working in one dimension!

In general, to work out a square transformation matrix in n dimensions, you need to know n points - the matrix contains n2 unknowns, and each point gives you n equations. You need as many equations as you have unknowns, so n points will suffice 1.

The bigger question is: how do you work that out?

It’s actually not all that hard - let’s suppose you have:

Mx1=y1 Mx2=y2 Mx3=y3 Mxn=yn

Where all of the xis and yis are column vectors. It turns out, you can combine all of that into a single equation:

MX=Y,

where X is all of the xis lined up side by side - and similarly for Y.

To find the unknown M, all you need to do is post-multiply both sides by X1:

MXX1=YX1 … and the matrices at the end of the left-hand side work out to be I:

M=YX1

(This is why the xis have to be linearly independent: otherwise, X has no inverse.)

Now, I haven’t done proper grown-up matrix work for a long while, but I gather that no computer scientist worth his hash-salting algorithm would ever invert a matrix; there are almost certainly better algorithms for working this sort of thing out. However, there’s a certain neatness to this solution that I rather like. So there!

Footnotes:

1. as long as they’re linearly independent