Mathematica Lab 8

MATH 220E Spring 2025

This week we will learn about the determinant of a matrix. Basically the determinant of a matrix is a number, which is calculated from the entries in the matrix. This number actually gives us information about the matrix.

In this lab we will investigate what happens to the determinant of a matrix A when we perform elementary row operations on A. You don’t need to know what the determinant really is in order to perform this investigation.

There is no reason why row operations should not change the determinant calculation, but maybe it is predictable how row operations will change the determinant. Let’s investigate!

This lab contains 12 problems, each of which is relatively short. Put your solutions to these problems in a separate Mathematica notebook. Use sentences to explain your work. Be sure to include all necessary code, such as definitions of matrices, so that the code in that notebook will run without errors.

Computing Determinants

Here is a matrix A:

A={{-6,-6,35,-16},{1,2,-4,2},{-17,-13,73,-34},{-31,-47/2,257/2,-60}};
MatrixForm[A]

To compute the determinant of A, use the function Det, like this:

Det[A]

Row Operation 1: Multiplying a row by a (nonzero) scalar

IMPORTANT: We don't want to change the original matrix A because will still need it for reference later on. So we're going to create a duplicate of A and call it B. Then we will perform a row operation on B. Here is how we create B:

B=A;
MatrixForm[B]

Remember that you can isolate a row or column of a matrix, like this:

B[[1]]

B[[All,1]]

Now let’s do a row operation on B. We will multiply the first row of B by 3, compute the determinant, and see what happens:

B[[1]]=3*B[[1]]; 
MatrixForm[B]

Det[B]

Interesting! Now, let’s see what happens if a different row is multiplied by 3 instead of the first row.

We’ll do this for each row of the original matrix A, one at a time, using a For loop. Before each row operation, we will “reset” B by making a new copy of A, stored as B.

Remember that when we put several statements inside of a loop (that is, when we want the loop to do several things each time it runs), these statements must be separated by semicolons. The following loop contains three statements (set B equal to A, change one row of B, and then print the determinant of B).

For[i=1,i≤4,i++,
B=A;
B[[i,All]]=3*B[[i,All]]; 
Print[Det[B]]
]

What do you notice?

Problem 1

Change the loop above so that you multiply each of the columns of A by 2, one at a time, and compute the resulting determinants. (So what you're really doing are column operations — crazy!)

Problem 2

Repeat the row example above with two other nonzero scalars (choose a positive number other than 3, and then choose a negative number). Then write (in English sentences) a conjecture as to what changes with the determinant of a matrix when a single row or a single column is multiplied by a constant c. (A conjecture is a precise statement of what you think is true based on your computations.)

Multiplying two rows

Now we’ll multiply two rows by 3 and see how the determinant changes. Note that we have nested For loops below.

For[i=1,i≤4,i++,
For[j=1,j<i,j++,
B=A;
(* Print[{i,j}]; *)
B[[i]]=3*B[[i]];
B[[j]]=3*B[[j]];
Print[Det[B]]
]
]

Problem 3

The nested loop above performs a total of 6 computations above. Which 6 pairs of rows are being multiplied by 3? (If you’re not sure, uncomment the other Print statement and run the code again.)

Problem 4

Write (in English sentences) a conjecture about what changes with the determinant of a matrix when two rows are multiplied by the same scalar c.

Problem 5

Modify the code to add another For loop so that you see what happens to the determinant when three rows are multiplied by the same scalar (of your choice).

Problem 6

Write (in English sentences) a conjecture about what changes with the determinant of an n×n matrix when the entire matrix is multiplied by the scalar c.  Explain.

Row Operation 2: Swapping two rows

Now we'll see what happens to the determinant of a matrix when two rows are swapped (interchanged). The next code shows how to swap rows 1 and 2, and then compute the determinant.

B=A; 
B[[1]]=A[[2]]; 
B[[2]]=A[[1]]; 
MatrixForm[B]
Print[Det[B]]

Problem 7

Swap rows 3 and 4. What is the new determinant?

Problem 8

Swap rows 1 and 2, and then swap rows 3 and 4. What is the new determinant?

Problem 9

(a) Write (in English sentences) a conjecture about what changes with the determinant of a matrix when a pair of rows are interchanged. 
(b) Write (in English sentences) a conjecture about what changes with the determinant of a matrix when k pairs of rows are interchanged.

Row Operation 3: Adding a multiple of one row to another row

Now we'll see what happens when a multiple of one row is added to another row. First, we redefine B to a new copy of A. Then, we add 3 times row 2 to row 1, and store the result in row 1.

B=A;
B[[1]]=B[[1]]+3*B[[2]]
MatrixForm[B]

Now we calculate the new determinant.

Det[B]

Problem 10

Use a nested For to replace row i with [row i +3×row j ] for each pair of i and j such that i<j. Once that is done, compute the determinant.

Problem 11

Write (in English sentences) a conjecture about what changes with the determinant of a matrix  when row i is replaced by [row i+b×row j].

Problem 12

Replace row 2 with [3row 2+row 3]. Now what happens to the determinant? How is this situation different than what happened in Problems 10 and 11? Hint: Explain how the row operation used in Exercise 10 and the one here are different. Which one is really doing Row Operation 3?

When finished, submit your Mathematica notebook to the Mathematica Lab 8 assignment on Moodle.