Jim's
Tutorials

Fall 2014
course
navigation

Sep 26

class discussion summary

We talked about matrices.
Here is some of what we did in an ipython notebook:
$ ipython notebook --pylab=inline # launch the notebook > m = array([[1,1,1], [1,0,-1], [0,1,0]]) # create a matrix > n = inv(m) # multiplicative inverse > dot(m, n) # matrix ("inner") multiply > transpose(m) # exchange rows and columns
For orthonormal basis matrices (rows are vectors whose dot product is 0 if different, 1 if same row), the inverse and transpose are the same. (Magic!)
A matrix * vector multiplication (row by column inner "dot" product) is what we did last time, component by component, finding the vector's representation in the new basis. In numpy, this kind of mulitiplication is the dot() function, which covers vector*vector (the dot product that gives a scalar), matrix*vector ("inner" product) and matrix*matrix (sometimes called the matrix product). All these are the same formula, with a sum over the inner index.
vector . vector : (1,n) * (n,1) gives (1,1) scalar output matrix . vector : (n,m) * (m,1) gives (n,1) vector output matrix . matrix : (n,m) * (m,p) gives (n,p) matrix output
where the inner product is a sum over the "inside" dimensions.

homework for Fri Oct 3

1. Invent some small (2, 3, or 4 dimensions) matrices and vectors. Do some of these products, both by hand and in numpy, and get the same answer.
2. Write down a 3x3 orthonormal matrix. (rows are three vectors, all perpendicular, all length 1). Check that the transpose is the multiplicative inverse. Use it to change a random 3-component vector to that basis. Confirm (as we did last time) that those new components multiplied by the basis vectors give the original vector. Make sure you can explain and understand how this matrix multiplication is a "transformation" from one coordinate system (i.e. the ihat, jhat, khat basis) to a new coordinate system (i.e. the vectors in the matrix).
3. Here is a particularly famous matrix. It's used extensively in JPEG compression - more than coming. I'll describe where it comes from later - for now, let's just look at it, as if it had dropped from the sky into your laps. (These numbers aren't exact, they've been rounded off, but let's ignore that for now too.)
array([[ 0.354, 0.354, 0.354, 0.354, 0.354, 0.354, 0.354, 0.354], [ 0.49 , 0.416, 0.278, 0.098, -0.098, -0.278, -0.416, -0.49 ], [ 0.462, 0.191, -0.191, -0.462, -0.462, -0.191, 0.191, 0.462], [ 0.416, -0.098, -0.49 , -0.278, 0.278, 0.49 , 0.098, -0.416], [ 0.354, -0.354, -0.354, 0.354, 0.354, -0.354, -0.354, 0.354], [ 0.278, -0.49 , 0.098, 0.416, -0.416, -0.098, 0.49 , -0.278], [ 0.191, -0.462, 0.462, -0.191, -0.191, 0.462, -0.462, 0.191], [ 0.098, -0.278, 0.416, -0.49 , 0.49 , -0.416, 0.278, -0.098]])
Paste that into an ipython session so you can play around with it, and give it a name (i.e. "m = ...").
Show that this is orthonormal, i.e. that the rows are perpendicular to each other, and that each has length 1.
Plot the rows. Notice anything interesting?
Choose some random (or interesting, for your definition of interesting) vectors of length 8. Multiply them by this matrix m, thereby "transforming" (i.e. rotating) them into m's coordinate system. Bingo! You're doing Fourier Transforms.
(This matrix is used heavily in JPEG compression - it's a Discrete Cosine Transform. Check wikipedia for more.)
http://cs.marlboro.edu/ courses/ fall2014/jims_tutorials/ fourier/ Sep_26
last modified Friday September 26 2014 5:29 pm EDT