Mathematica Lab 4

MATH 220E Spring 2025

Work through the worksheet below.  Complete the four problems in a separate notebook and submit your work to the Mathematica Lab 3 assignment on Moodle.

Review problems

Problem 1

Type in a 3 x 4 matrix of your choice (make it interesting and not too simple).  Then,  reduce it to reduced row echelon form (RREF), and finally display the reduced form in “nice” form. See Mathematica Lab 2 for a reminder, if you need it.

Problem 2

Using the same 3 x 4 matrix from Problem 1, do each of the following. Using sentences (in text cells) between each line of code to describe what the output of the code means (this makes it look more professional).  Again, see Mathematica Lab 2 for help.
   (a) Extract the 1st column of your matrix, and display that column by itself.
   (b) Extract the 2nd row of your matrix, and display that row by itself.
   (c) Extract  the 3-4 entry (i.e., 3rd row, 4th column - we always list the row first), and diplay that entry by itself.

Vectors in Mathematica

A vector is entered very simply as a list:

u={1,2,3}

Vectors generally get treated as rows of numbers by Mathematica, but later we’ll see how to append them (i.e., add  them on)  as columns to matrices.

First, see how its possible to do some algebra!   We can add vectors and multiply vectors  by scalars as you might expect!  Play around and see if each of the following results make sense to you.

v={4,5,6} 
w={7,8}

u+v

5u

u+w

Appending vectors to matrices (to create the “augmented” column)

A={{1,2,3},{4,5,6},{7,8,9}}

We can append the vector u = (1,2,3) from above either as a row or column to matrix A. We’ll start by adding it on as a fourth row of the matrix A. Mathematica’s Append function will do this for us.

Append[A,u]

MatrixForm[%]

Shortcut Alert: By the way, the use of the % symbol simply makes the input equal to the output from the previous computation!

What if we wanted to add the vector u as a new column of matrix A? This time we’ll add a fourth column to matrix A, but the matrix has to do some “gymnastics” first.   First we “transpose” the matrix A, which simply swaps all the rows with the columns.  Then we append u as a row, then transpose the whole thing back to its original state.  Read the syntax below from right to left, just as you would read a composition of functions.

Transpose[Append[  Transpose[A],u]]
MatrixForm[%]

For fun, you might see what each of the commands does above.  So look at Transpose[A], then Append[Transpose[A], u], and ending with Transpose[Append[Transpose[A], u]]. In each case MatrixForm will make things look nice (but never do Mathematica calculations with the MatrixForm version of the matrix).

RowReduce[%]//MatrixForm

Solving systems of equations (another way)

You already learned (in Mathematica Lab 2) that you can row reduce an augmented matrix with Mathematica, and then find the solution via back substitution by hand.  For example, if the matrix above represents an augmented system with 3 equations, then the solution is:

(Subscript[x, 1])=-(1/3)+(Subscript[x, 3])
(Subscript[x, 2])=(2/3)-2(Subscript[x, 3])
(Subscript[x, 3]) is a free variable

Alternatively, we can use the Solve function as follows, where A is the coefficient matrix and u is the augmented vector (as entered above). Note that in the following code, the dot tells Mathematica you want to multiply matrix A by the vector {(Subscript[x, 1]),(Subscript[x, 2]),(Subscript[x, 3])}. (We will learn more about matrix/vector multiplication soon.)

Solve[A.{x1,x2,x3}==u,{x3,x2,x1}]

Two more problems

Problem 3

Let A be the matrix (({{0, 0, 2, 2, 4}, {0, 1, 2, 4, 8}, {1, 2, 1, 2, 1}, {1, 2, 4, 5, 7}})). Then do the following:

(a) Input the matrix and name it A. Also input the vector u=(0,0,0,0).
(b) Append vector u to A as a column vector and call the new matrix Au. 
(c) Use RowReduce to find the RREF of matrix Au.
(d) Describe the solution set to the augmented system [ A | u ] both algebraically (i.e., as a formula) and geometrically (i.e., what is its shape?).
(e) Are the columns of A linearly independent? How do you know?
(f) Do the columns of A span (ℝ^4)? Why or why not?

Problem 4

Let B be the matrix (({{1, 3, -2, 4}, {3, 0, -1, 8}, {2, 0, 2, 5}, {4, -1, 2, 3}})). Then do the following:

(a) Input the matrix and name it B. Also input the vector v=(1,1,1,1).
(b) Append vector v to B as a column vector and call the new matrix Bv. 
(c) Use RowReduce to find the RREF of matrix Bv.
(d) Describe the solution set to the augmented system [ B | v ] both algebraically (i.e., as a formula) and geometrically (i.e., what is its shape?).
(e) Are the columns of B linearly independent? How do you know?
(f) Do the columns of B span (ℝ^4)? Why or why not?