Visualizing Matrices



In physics, we often express physical quantities, such as velocity, in terms of vectors. In three dimensions, the velocity vector can be visualized as an arrow with the length of the arrow proportional to the speed of the object and the direction of the arrow parallel to the direction of motion of the object. Vectors are fairly easy to picture. However, there are also physical quantities that are expressed as matrices. Not much attention is paid to matrices in introductory physics classes and consequently many physics majors have a hard time visualizing matrices. Let's explore the properties of some matrices and learn how to visualize the properties of a matrix.

We can think of a matrix as an operator that transforms one vector into another via matrix multiplication. In the example below, a vector A is transformed into a vector B by the matrix M.



The matrix multiplication is actually mathematical short-hand for several additions and multiplications.



These formulae tell us how to multiply the matrix, but they don't give us any direct insight as to the meaning of the matrix. Let's start our investigation of matrices by considering a special class of matrix: the rotation matrix. The following matrix



has a very simple interpretation: it takes the vector A and rotates it by an angle &theta around the z-axis. In the special case that &theta is 0, this matrix becomes the identity matrix I which leaves the vector A unchanged.
An important property of the rotation matrix is that it has a determinant of 1. The determinant of a matrix is calculated using the formula



which has the important property that it is an invariant of the matrix. Invariant quantities are very useful for visualization because they are independent of the coordinate system used to represent the quantity. Vectors have a very important invariant quantity: the magnitude of the vector which represents the size of the vector. You can think of the determinant as the "size" of the matrix. Rotation matrices all have a determinant of 1. Thus, when we multiply a vector by a rotation matrix, the resultant vector is the same size as the original vector.

If the rotation angle &theta is small, then the rotation matrix can be further simplified using the approximations sin &theta = &theta and cos &theta = 1. In this case, the rotation matrix becomes



which is equal to the identity matrix with the addition of a few small terms. In fact, this matrix is an example of an infinitesimal deformation matrix D of the form D = I + &epsilon M, where I is the identity matrix, and &epsilon is a very small number. In practice, we'll use an even simpler definition of the deformation matrix: D = I + M and we'll make sure that every element of the matrix M is small. This means that we can study M without having to worry about the small parameter &epsilon which doesn't alter the properties of M.
The deformation matrix D doesn't change the vector A very much, but it does "deform" the vector in a manner that is quite predictable. We will use the POV raytracing program to study how the deformation matrix D alters the shape of a simple object (a cube) and from this we will learn about the properties of the original matrix M.

Let's start with a very simple matrix. We will use POV to represent the original cube coordinates as a glass cube. We'll then use the deformation matrix D to deform the points in the cube. Finally, we'll plot the deformed cube as a blue metallic cube.



This matrix takes the cube and, as we move forward in the x-direction, the cube is increasingly displaced in the y-direction. This matrix is known as a shear matrix because it produces a shearing effect: a distortion in one direction that varies along an orthogonal direction. In this case, we can see that the right end of the cube is displaced upward, revealing the original glass cube along the x-z plane.

If we increase the size of the matrix M then we increase the deformation proportionately. For example, if we multiply the above matrix by a factor of 2, then the displacement becomes twice as large.



Also, if we multiply the matrix by -1, then the displacement is downward, rather than upward.



We can also transpose the matrix. This has the effect of interchanging the x and y coordinates. Thus, we now see a displacement in x that depends upon y. In this case, we see that the metal cube is displaced to the right as we move upward, revealing the original glass cube along the y-z plane.



We can also displace the matrix in the x-direction as a function of z, rather than y.



We can also shrink the cube along any given direction. In this case, we are shrinking it by 20 percent along the y-axis. The width and depth of the metal cube are identical to the glass cube, but the height is significantly shorter.



Up until now we've only considered matrices with one non-zero element. What if we have two non-zero elements? Let's start by investigating two special cases: the symmetric matrix and the antisymmetric matrix. A symmetric matrix is equal to its transpose: the matrix remains unchanged if we interchange the rows with columns and vice versa. The symmetric matrix produces a diamond-shaped figure



with the axis of elongation along the x-y diagonal. If we take the negative of this matrix, then the cube is elongated along the other diagonal.



However, we also have the possibility of an antisymmetric matrix. An antisymmetric matrix is equal to the negative of its transpose. By definition, all the diagonal elements of an antisymmetric matrix are equal to zero.



The antisymmetric matrix is just an ordinary rotation: in this case, we've rotated the cube through a small angle about the z-axis. This shouldn't be too surprising since we already looked at rotation matrices and found that a small rotation can be written as the sum of the identity matrix plus an antisymmetric matrix.

If the diagonal elements are zero, then symmetric matrices correspond to shear, and antisymmetric matrices correspond to rotations. We can, of course, combine both shearing and rotations in a single matrix. The matrix below has the effect of both shearing the cube along the x-y diagonal, and then rotating the cube around the y-axis.



The vast majority of the matrices we have studied have the property that they leave the volume of the cube unchanged. You might think that only matrices with determinant equal to 1 will preserve the volume of the cube, but this is not the case. Shearing the cube will not change its volume, but it will change the sizes of the vectors defining the cube. The matrices M that leave the volume unchanged all have a trace equal to zero. The trace of the matrix is defined as the sum of all the diagonal element in the matrix. The trace is another invariant property of the matrix. If the trace of Mis positive, then the deformation matrix D will increase the volume of the cube. If the trace of M is negative, then the deformation matrix D will decrease the volume of the cube.

If you would like to explore more matrices, here is the POV source code that produces the images in this document. Just change the matrix elements (the Mij values) and render the image. Keep the individual values small (usually no larger than 0.2) or the distortions will be too large.
In order to render this, you will need the free font Bitstream Vera Sans Mono Bold which is a fixed-width font: useful for computer programmers and 3D rendering.

//**************************************************************/
//
//* This POV-Ray file generates a picture of a cube that is
//* transformed using the given matrix.
//* Written by Derin A. Sherman for POV-Ray 3.6
//*
//**************************************************************/


global_settings { assumed_gamma 1.8 }

#include "colors.inc"
#include "shapes.inc"
#include "woods.inc"
#include "glass.inc"
#include "textures.inc"

#declare cs=0.3; // camera scale factor
#declare fs=0.3; // font scale factor
#declare cylrad=0.025; // cylinder radius for coordinate axes

// the matrix (defined using Mij, where (i,j) are one of (x,y,z)

#declare Mxx = 0.0;
#declare Mxy = 0.2;
#declare Mxz = -0.2;
#declare Myx = 0.2;
#declare Myy = 0.0;
#declare Myz = 0.0;
#declare Mzx = 0.2;
#declare Mzy = 0.0;
#declare Mzz = 0.0;

// change from right-handed coordinates to left-handed coordinates (used by POV)

#declare Mxz = -Mxz;
#declare Myz = -Myz;
#declare Mzx = -Mzx;
#declare Mzy = -Mzy;

// add identity matrix to our transform

#declare Mxx = Mxx + 1.0;
#declare Myy = Myy + 1.0;
#declare Mzz = Mzz + 1.0;

// define the transform

#declare MyTransform = transform {
matrix < Mxx, Mxy, Mxz, Myx, Myy, Myz, Mzx, Mzy, Mzz, 0, 0, 0>
}

camera { // direction <-0.4, -0.8, -4>
location <4*cs, 5.0*cs, -10.0*cs>
right 1.3333333333*x up y
look_at <0.5, 0.5, 0.5>
}

light_source {
<-10.0, 4.0, 10.0>
color rgb<0.5, 0.5, 0.5>
}

light_source {
<10.0, 4.0, 10.0>
color rgb<0.5, 0.5, 0.5>
}


// a plane beneath the cube

plane {y, -1.5
texture{
T_Wood8
pigment { turbulence 0.1}
finish{
ambient 0.3
reflection 0.2
}
scale 2.0
rotate <5.0, 85.0, 10.0>
translate <-12.0, 0.0, 2.0>
}
}

// sky

sphere{<0,0,0>,1 hollow
texture {
pigment {
gradient <0,1,0>
color_map{[0.0 color White]
[0.6 color rgb<0.1,0.45,0.85> ]
[1.0 color rgb<0.1,0.45,0.85> ]
}
}
finish {
ambient 1 diffuse 0
}
}
scale 10000
}

// Draw the coordinate system

intersection {
text { ttf "VeraMoBd.ttf", "X", 1, 0}
plane {z, 1 translate <0, 0, -0.75>}
translate <1.4/fs,0,0> // fine-tune horizontal alignment
scale fs
rotate <0, 0, 0>
pigment{color rgb <0.5 0.0 0.75>}
finish {
ambient 0.25
diffuse 1.0
phong 0.1
phong_size 0.1
}
}

intersection {
text { ttf "VeraMoBd.ttf", "Y", 1, 0}
plane {z, 1 translate <0, 0, -0.75>}
translate <0,1.3/fs,0> // fine-tune horizontal alignment
scale fs
rotate <0, 0, 0>

pigment{color rgb <0.5 0.0 0.75>}
finish {
ambient 0.25
diffuse 1.0
phong 0.1
phong_size 0.1
}
}

intersection {
text { ttf "VeraMoBd.ttf", "Z", 1, 0}
plane {z, 1 translate <0, 0, -0.75>}
translate <0,0.1/fs,-1.2/fs> // fine-tune horizontal alignment
scale fs
rotate <0, 0, 0>

pigment{color rgb <0.5 0.0 0.75>}
finish {
ambient 0.25
diffuse 1.0
phong 0.1
phong_size 0.1
}
}

union {
sphere{<0,0,0> cylrad} // origin
cylinder{<0,0,0>, <1+cylrad*4,0,0>, cylrad} // x-axis
cone{<1+cylrad*4,0,0>, cylrad*4, <1+cylrad*12, 0, 0>, 0}
cylinder{<0,0,0>, <0,1+cylrad*4,0>, cylrad} // y-axis
cone{<0,1+cylrad*4,0>, cylrad*4, <0, 1+cylrad*12, 0> 0}
cylinder{<0,0,0>, <0,0,-(1+cylrad*4)> cylrad} // z-axis
cone{<0,0,-(1+cylrad*4)>, cylrad*4, <0, 0, -(1+cylrad*12)> 0}

pigment{color rgb <0.25 0.75 1.0>}
finish {
ambient 0.25
diffuse 1.0
phong 0.1
phong_size 0.1
}
}

// the original cube

#declare origcube =
box{<0, 0, 0>, <1, 1, -1> }


// Draw the original cube

object{origcube scale 0.999
texture {
T_Glass3
scale 90
finish {
reflection 0.6
}
}
}

// Now draw the transformed cube

object{origcube transform{MyTransform}
texture {
pigment {rgb <0.3, 0.8, 1.0>}
finish {
ambient 0.2
diffuse 0.7
brilliance 6.0
metallic
reflection 0.6
phong 0.8
phong_size 240
}
}
}