Matrix Tricks

Tags

Common patterns

Exploiting the heck out of distributive

Distributive property will save you a lot of headache. It works on any linear operation, which means that matrices are fair game. Transposes are distributive as well, and dot products are definitely distributive, both left and right hand side.

Therefore, something like this is possible:

zT(v)z=zTvzz^T(\sum v)z = \sum z^Tvz

And something like this is really helpful:

(v)Tz=vTz(\sum v)^Tz = \sum v^Tz

Comparisons of vectors, matrices

Change of coordinates

This is actually pretty obvious but also a little tricky. If we wanted to map from the canonical basis e1,,ene_1,…, e_n to another basis t1,,tnt_1, …, t_n, then we can make a matrix TT whose columns is the basis. Then, TxTx would be expressing the other basis in terms of the canonical basis. Therefore, T1xT^{-1}x is expressing the canonical basis in terms of the other basis. It’s flipped from intuition, so be careful!

Therefore, if you have a canonical function AA and another basis that your x~,y~\tilde x, \tilde y are in, then you can define

y~=(T1AT)x~\tilde y = (T^{-1}AT)\tilde x

You can imagine going through a “portal” to the canonical place, applying the function, and the going through an inverse portal to the other basis.

Matrix to summations, and vice versa

Completing the square

Recall that the complete the square in scalar form is

12az2+bz+c=12a(z+ba)2+cb22a\frac{1}{2}az^2 + bz + c = \frac{1}{2}a(z + \frac{b}{a})^2 + c - \frac{b^2}{2a}

We can also rewrite this as matrix multiplication too!

12zTAz+bTz+c=12(z+A1b)TA(z+A1b)+c12bTA1b\frac{1}{2} z^T Az + b^Tz + c = \frac{1}{2}(z + A^{-1}b)^TA(z + A^{-1}b)+ c - \frac{1}{2}b^TA^{-1}b