Lab 7:  Matrix Notation in Mathematica

Vectors in mathematica are written as follows:

	{element 1, element 2, ... , element n}

You don't have to distinguish between row and column vectors in Mathematica, since Mathematica uses the context in order to determine which kind of vector you are using.

Matrices in mathematica are written as follows:

	{{row 1},{row 2}, ... , {row n}}
	
For example, a 2x2 matrix is (enter the following):

{{a, b}, {c, d}}

You can also write this using the matrix key in the BasicInput Pallette (File -> Palettes -> BasicInput):

(({{a, b}, {c, d}}))

The matrix and vector multiplication that we've been talking about in class is technically known as the "dot product" and is represented by a "." (a period).

{{a, b}, {c, d}} . {e, f}

{e, f} . {{a, b}, {c, d}}

[Notice that Mathematica knew to interpret {e,f} as a  column vector in the first case and as a row vector in the second case.]

Matrix multiplication and addition

Write a 2x2 matrix of your choice and multiply it by 3 (a scalar).  Scalar multiplication can be accomplished using a space or *.

Add together two 2x2 matrices of your choice.  Matrix addition can be accomplished using a +.

Multiply together a 2x2 matrix by a vector of your choice.  Matrix multiplication (the dot product) can be accomplished with a "."

Replace the "." with an "*" or a space to see that only "." corresponds to the standard matrix multiplication.

Functions of Matrices in Mathematica

Using the three examples:

m1 = {{a, b}, {c, d}}

m2 = {{1, 2}, {3, 2}}

m3 = {{1, -3, 3}, {3, -5, 3}, {6, -6, 4}}

Find the determinant using Det[m]

?Det

Find the inverse of the matrix using Inverse[m]

?Inverse

Show that the matrix times its inverse is equal to the identity matrix
(don't forget to use the dot product notation, ".").  For example, by entering:

Factor[m1 . Inverse[m1]]

Find the eigenvalues of the matrix using Eigenvalues[m]

?Eigenvalues

For example, by entering:

Factor[Eigenvalues[m1]]

Find the eigenvectors of the matrix using Eigenvectors[m]

?Eigenvectors

For example, by entering:

Factor[Eigenvectors[m1]]

You can find both the eigenvalues and the eigenvectors of 
a matrix using Eigensystem[m].

?Eigensystem

For example, by entering:

Factor[Eigensystem[m1]]

For each eigenvector of matrix m3, show that the matrix times the eigenvector equals
the eigenvector times its associated eigenvalue.  (Don't forget to use the dot product.)

That is, fill in the vector below with the eigenvector and check the answer:

m3 . { , , }

Another useful matrix operation is MatrixPower[matrix,t],
this takes the matrix to the t power.

For example,

MatrixPower[m2, 3]

gives the same answer as (enter both and compare):

m2 . m2 . m2

Either way, these commands tell you how much
change will occur in a vector over three time steps.

Lab Assignment

For matrix 3, hand in the diagonal matrix, D, and the transformation matrix, A, that
you would use to write the transition matrix, m3 as A.D.Inverse[A]).

Rest of lab

Not all matrices can be diagonalized (i.e., can be written as A.D.Inverse[A]).
Only nxn matrices that have n independent eigenvectors can be diagonalized.
[Independent means that you can't get one of the eigenvectors by simply
adding together multiples of the other eigenvectors.  Independence implies
that the determinant of A will not be zero.]

Here is an example of a matrix that cannot be diagonilized:

m4 = {{-3, 1, -1}, {-7, 5, -1}, {-6, 6, -2}}

Note that one of the eigenvectors of this matrix is {0,0,0}:

Factor[Eigensystem[m4]]

m4 is thus known as a "defective" matrix.  The only type of square matrix
that is defective is one that has a repeated eigenvalue. 
For example, the eigenvalue of -2 is repeated twice for matrix m4.

Just because an eigenvalue is repeated, however, does not make the matrix defective.
For example, matrix 3 also has an eigenvalue of -2 that is repeated twice, but it is possible
to find three independent eigenvectors for m3.

With any remaining time in the lab, find the eigenvectors of m3 and m4 associated with 
the eigenvalue of -2 by hand.  For m3, you will find that two of the three equations
are necessarily true given that the first equation is true.  Thus, you will be able to choose
arbitrary values for v1 and for v2, and you can choose these to point in two different directions
(e.g., v1 = 1, v2 = 0 and v1 = 0, v2 = 1).  In contrast, for m4, you will find that only one 
equation is necessarily true given the other two.  Therefore, once you choose a value for v1,
v2 and v3 will have to take on particular values, and you won't be able to choose a second
combination that points in a different direction.