Matrix Operations

Part 1. Properties of Matrix Multiplication

Define the matrices A, B, and F:  (The variables C, D, and E are reserved in Mathematica.)  Note that the postfix command MatrixForm is not included in the definition command.  Doing so would prevent Mathematica from executing subsequent matrix operations.

A  =  {{1, 0, -1, 3}, {2, 1, 4, -2}, {0, -5, 0, 
            1}, {-1, 2, -1, 3}};
% // MatrixForm

B  =  {{2, 1, 0, 7}, {-2, 5, 1, 2}, {4, 1, 
            3, -6}, {4, -4, -1, 5}};
% // MatrixForm

F  =  {{2, 1, -5, -2}, {-3, 4, -1, 3}, {0, 2, 0, 
            1}, {7, 13, -52, 3}};
% // MatrixForm

Compute the product AB. The Dot operator "." is used for matrix multiplication in Mathematica.

A . B // MatrixForm

Using the following input cell, enter commands to complete steps 1, 2, and 3.

Create a matrix with random integer entries.  Note that because Mathematica does not have a random matrix function, we need to define one first.  We will define one that generates integers in [-100,100].

RandomMatrix[n_] :=  
        Table[Table[Random[Integer, {-100, 100}], {j, n}], {i, 
            n}];

R  =  RandomMatrix[4];
% // MatrixForm

Using the following input cell, enter commands to complete steps 4, 5, and 6.

Part 2. The Product AX as a Linear Combination

We define the 4-dimensional standard unit vectors (Subscript[e, 1]), (Subscript[e, 2]), (Subscript[e, 3]), and (Subscript[e, 4]).  Convince yourself that our following definition is correct.

I4  =  IdentityMatrix[4];
e1  =  I4[[1]];
e2  =  I4[[2]];
e3  =  I4[[3]];
e4  =  I4[[4]];

Note that Mathematica treats vectors as lists, and you need not transpose a vector into a column before premultiplication by a matrix.  The matrix Dot operator does this for you automatically.  However, Mathematica displays row and column vectors both as lists, so the user needs to interpret whether the result is a column or row vector.  For reference we reproduce here the matrix A defined in Part 1.

MatrixForm[A]

Compute the product A(Subscript[e, 1]), and compare the result with the first column of A.  To obtain the ith column of a matrix M, we use the syntax M[[All, i]].

A . e1

A[[All, 1]]

Alternatively, we could have transposed the matrix first and then extracted the first column, Transpose[M][[1]].  This approach is especially useful when we need to carry out a series of column operations.

Transpose[A][[1]]

Explain why the ith column is equal to the product of A and the ith standard unit vector.

Answer:

Answer to step 1:

Enter the vector x, and answer steps 2 and 3 using the following input cell.

x  =  {2, -3, 4, -5};

Part 3. Special Matrices

Here are the matrices from Part 1.

A // MatrixForm

B // MatrixForm

Create a 4 x 4 identity matrix.

Id  =  IdentityMatrix[4];
% // MatrixForm

Create a 4 x 4 zero matrix.

<< LinearAlgebra`MatrixManipulation`
Z  =  ZeroMatrix[4];
Z // MatrixForm

Alternatively, we could have chosen not to load the package, and just use the DiagonalMatrix function.  DiagonalMatrix[list] creates a diagonal matrix whose entries along the main diagonal are the elements of list.

DiagonalMatrix[{0, 0, 0, 0}] // MatrixForm

Carry out the step 1 calculations using the input cell below.

Answer to step 2:

If possible, find the inverses of the matrices A and B.

Inverse[A] // MatrixForm

Inverse[B] // MatrixForm

Experiment with random matrices.  Enter the following lines several times.

R  =  RandomMatrix[4];
% // MatrixForm

S  =  Inverse[R];
% // MatrixForm

MatrixForm[R . S]

MatrixForm[S . R]

Enter the following diagonal matrices, and carry out steps 5 and 6.

D1  =  DiagonalMatrix[{1, 2, -1, 3}];
% // MatrixForm

D2  =  DiagonalMatrix[{4, -1, 5, 2}];
% // MatrixForm

Part 4. Determinants

Here again are the matrices from Part 1.

A // MatrixForm

B // MatrixForm

The Mathematica command for determinant is Det.

Det[A]

Here are the identity, zero, and diagonal matrices from Part 3.

Id // MatrixForm

Z // MatrixForm

D1 // MatrixForm

D2 // MatrixForm

Experiment with determinants of products.

R  =  RandomMatrix[4];
% // MatrixForm

S  =  RandomMatrix[4];
% // MatrixForm

Det[R . S]
Det[S . R]
Det[R]*Det[S]

Enter another random 4 x 4 matrix P.

P  =  RandomMatrix[4];
% // MatrixForm

Examine the determinant of (P^(-1))AP.

Q  =   Inverse[P] . A . P;
% // MatrixForm

Det[Q]
Det[A]

Explore determinants of sums of matrices.

Det[A + B]
Det[A] + Det[B]

Examine formulas for determinants.

T  =  Array[f, {2, 2}];
% // MatrixForm
Det[T]

Part 5. Systems of Linear Equations

Set up and solve a system of linear equations.

A // MatrixForm
b  =  {1, -2, 11, 3}

LinearSolve[A, b]

Check the answer from the preceding calculation.

A . %

Solve the system another way.

Inverse[A] . b

Using the following input cell, enter commands to carry out steps 3, 4, and 5.

Part 6. Summary

Answers to the questions in Part 6: