Matrix Algebra

Vectors are represented as lists. Matrices are lists of lists.

vec = {12, 5, -7}

mat = {{1,2},{4,5},{3,3}}

Use the function MatrixForm to display matrices.

MatrixForm[mat]

A = {{-1,3,5},{3,5,4},{2,1,5},{-4,0,6}}

MatrixForm[A]

A is a 4 x3 matrix. So it makes sense to multiply A and vec. Use the period for matrix multiplication and for multiplication of matrices and vectors.

A.vec

The matrix mat is 3 x 2. So it does not makes sense to multiply mat and A.

mat.A

On the other hand, it does make sense to multiply A and mat.

A.mat // MatrixForm

We'll define a new 3x3 A matrix

A = {{1,1,1},{1,1,2},{1,-1,3}}

A // MatrixForm

Here is the command for generating the 3x3 Identity Matrix

IdentityMatrix[3] //MatrixForm

Here is the inverse of A

Inverse[A] // MatrixForm

To check it's the inverse.

A.Inverse[A] //MatrixForm

Inverse[A].A // MatrixForm

Here is the matrix for the first example we did in class on population growth

A = {{.4271, .8498, .1273},{.9924,0,0},{0,.9826,0}}; MatrixForm[A]

If we start off with 30 people in each class, then the state vector at time 0 is

X0 = {30,30,30}

After 1 time unit (of 15 years), the population state vector is now

A.X0

After two years we have

A.(A.X0)

Which is the same as the 2nd power of A times X. We use the MatrixPower command to find powers of a matrix. Compare this to the Excel Spread Sheet.

MatrixPower[A,2].X0

Consider the following 3 x 3 system of linear equations:

 x + 2y +   z  =  4
2x -  y  + 3z = 1
2x + y  - z  = 2

We'll write this as a matrix-vector equation as follows

A = {{1,2,1},{2,-1,3},{2,1,-1}}; MatrixForm[A]

b = {4,1,2}

X = {x,y,z}

Then AX is the left hand side of the system

A.X // MatrixForm

So the vector equation is AX = b. If A and b were numbers and X was a regular variable, the solution (since A does nto equal 0) would be x = (A^(-1))b. By analogy we have

Inverse[A].b

Thus x = 1/2, y = 3/2 and z = 1/2. Check to see that this is in fact the solution of the system of equations.

Clear[x,y,z]

Eigenvalues and Eigenvectors

A = {{1,1},{1,1}}; A // MatrixForm

Eigenvalues[A]

Eigenvectors[A]

Check the Eigenvalue-Eigenvector Equation

A.{1,1}

A.{1,-1}

Coyotes and Roadrunners

A = {{.86,.08},{-.12,1.14}}; A // MatrixForm

Eigenvalues[A]

A.{200,100}

A.{100,300}

Rabbits and Wolves

A = {{.4271,.8498,.1273},{.9924,0,0},{0,.9826,0}}; MatrixForm[A]

Eigenvalues[A]

Eigenvectors[A]

The eigenvector corresponding to the dominant eigenvalue 1.20934 is

v = {.687131,.56387,.458151}

We'll normalize this vector by dividing it by the sum of its elements. This will give an eigenvector whose components sum to 1.

Total[v]

v/Total[v]

Notice that these are the long-term stabilization ratios for the human population growth model.

Here is the Leslie matrix for Example 3.1 on page 114 (The Florida sandhill crane)

crane ={ {0,0,.01,.04,.17,.27,.27,.27,.27,.27,.27,.27,.27,.27,.27,.27,.27,.27,.27,.27},{.63,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,.93,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,.98,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,.98,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,.97,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,.96,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,.95,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,.94,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,.91,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,.89,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,.89,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,.89,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,.87,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,.81,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,.76, 0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,.68, 0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,.51,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,.50,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,.50,0}}; crane//MatrixForm

Eigenvalues[crane]

vec1 =Eigenvectors[crane][[1]]

The normalized eigenvector corresponding to the dominant eigenvalue of 1.02686

vec1/Total[vec1]

gamble = {{1,1/2,0,0,0,0},{0,0,1/2,0,0,0},{0,1/2,0,1/2,0,0},{0,0,1/2,0,1/2,0},{0,0,0,1/2,0,0},{0,0,0,0,1/2,1}}; gamble//MatrixForm

MatrixPower[gamble,100.] //MatrixForm

A = {{0,1/2,0,0},{1/2,0,1/2,0},{0,1/2,0,1/2},{0,0,1/2,0}}; MatrixForm[A]

B = {{1/2,0,0,0},{0,0,0,1/2}}

Fundamental = Inverse[IdentityMatrix[4]-A]

Fundamental//MatrixForm

B.Fundamental //MatrixForm