Basic Steps and 
the Traffic Roundabout

In which we use Mathematica to do some basic Linear Algebra activities. (I hope at least some of you have goofed around with it before now.)

First, let’s enter a matrix. Click the menu “Insert” and select Table/Matrix > New. Also, choosing the “Create: Matrix” option (top left after clicking on the appropriate menu selection) puts it in matrix form, rather than table. (The two outputs are interchangeable for Mathematica, but they present as different.)

It is very convenient to name a matrix (or anything in Mathematica) for later use, so I’ll name the example below after my Linear Algebra teacher (who was very boring, but very nice.) Here’s Ray.

Ray=({{0, -1, -1}, {1, 2, 1}, {-1, -1, 0}})

You’ll notice above that the output of Ray is how Mathematica “thinks” of a matrix: It’s a particular kind of array. CS people, you may begin to quiver with excitement. Math people, you may continue to look blank.

If you wish to see Ray in a standard form, either use the “display” key in the bar below the output, or use the command MatrixForm[Ray].

MatrixForm[Ray]

For the Traffic Roundabout problem, we got a large matrix with lots of 0s and a diagonal of -1s. When we use the Insert command, it let’s us designate a single number for all the entries of the matrix, plus the option of 1s down the diagonal. That seems to me to be easier to enter, but do what seems best to you.

We’ll name the augmented matrix Randy, because it sounds like “Roundy.”

Randy=(({{-1, 0, 0, 0, 0, 1, -60}, {1, -1, 0, 0, 0, 0, 70}, {0, 1, -1, 0, 0, 0, -100}, {0, 0, 1, -1, 0, 0, 90}, {0, 0, 0, 1, -1, 0, -80}, {0, 0, 0, 0, 1, -1, 80}}))

After putting in the “all 0s, 1s on the diagonal” matrix, I changed the numbers that needed to be changed.

Let’s look at it in matrix form. (You may also use the bar underneath the output up above.)

MatrixForm[Randy]

The RowReduce[matrix] command will put a consistent matrix in REF. Here goes!

Rowdy=RowReduce[Randy]

Putting Rowdy into matrix form:

MatrixForm[Rowdy]

If I’d forgotten or didn’t want to use an augmented matrix, then I could have used the LinearSolve[matrix, vector] command to find what is the last column of the augmented matrix up above. The Drop[matrix, 0, {column-number}] command drops the chosen column. We’ll drop the 7th column, the augmented column, to get a look at Rhodey.

Rhodey=Drop[Randy,0,{7}]

MatrixForm[Rhodey]

Just what we wanted! Now, let’s grab the augmenting column, and name it InOut.

InOut=Drop[Randy,0,6]

MatrixForm[InOut]

Again, just what we wanted! Finally, the command to solve the matrix equation is, as I wrote above, in this case, LinearSolve[Rhodey, InOut].

LinearSolve[Rhodey,InOut]

MatrixForm[{{60},{-10},{90},{0},{80},{0}}]

And so we see that that method also produces the same solution. The next step is notice that the 6th variable is free, then write out the general solution, and then take it from there.