Part 2.

To complete this part of the lab assignment, you will load this worksheet into Sage and interact with it by evaluating the cells below to carry out a solution to the last exercise of Homework 4. 

In that problem we are given

\[A = \left[\begin{matrix}1&1&1\\0&1&1\\1&2&1\end{matrix}\right] \; \text{ and } \; \mathbf{b} = \left[\begin{matrix}3\\0\\1\end{matrix}\right].\]

Using the matrix and vector constructors, define $A$ and $\mathbf{b}$ in Sage by evaluating the next cell.

{{{id=9| A = matrix([[1,1,1],[0,1,1],[1,2,1]]) b = vector([3,0,1]) /// }}}

The problem in Homework 4 asked for the inverse of $A$.  To compute $A^{-1}$ by hand, we augment $A$ with an identity matrix and then perform Gaussian elimination.  

Although Sage has an inverse command, we will not use it just yet.  In fact, using the built-in inverse command at this point would defeat the purpose of this exercise, so don't use it!

Instead, we will follow the same procedure carried out when solving the homework problem by hand (but this time we leave most of the tedium to Sage).  

First, augment $A$ with the identity matrix by evaluating the next cell.

{{{id=13| AI3 = A.augment(matrix([[1,0,0],[0,1,0],[0,0,1]]), subdivide=True); print AI3 /// }}}

Take note of how Sage lets us augment a matrix with an entire matrix (not just a single vector as we were doing earlier).  

(By the way, we don't really need the "subdivide=True" option, but it makes the output prettier. Re-evaluate that cell without the subdivide option, if you want to see the difference.)

Finally, we compute the echelon form of the augmented matrix, which is easy (almost too easy) with Sage.

{{{id=12| AI3.rref() /// [ 1 0 0| 1 -1 0] [ 0 1 0|-1 0 1] [ 0 0 1| 1 1 -1] }}}

Exercises

 Exercise 2.1. Define a new matrix in Sage, called $B$, and set it equal to the inverse of the matrix $A$ above.

(Refer to the row-reduced echelon form that we just computed. Do not use the Sage inverse command here. Be sure to remove the hashtag before evaluating the cells below.)

{{{id=11| # B = matrix([[fill in here]]) /// }}}

Exercise 2.2. Use Sage to check that $B$ really is the inverse of $A$ by computing $BA$ and $AB$.

{{{id=25| # (fill in here) /// }}}

Exercise 2.3. Now that you have verified that $B$ is the inverse of $A$, use the matrix $B$ to compute a solution to $A\mathbf{x} = \mathbf{b}$, where $\mathbf{b}$ is the vector we already defined above.

(Hint: this is an easy computation involving only the matrix $B$ and the vector $\mathbf{b}$.)

{{{id=26| # x = (fill in here) /// }}}

Check that your answer is correct by evaluating the next cell.

{{{id=33| A*x == b /// }}}

If Sage returned the result True, congratulations!  You have completed Lab 2.  

Important: to get credit for Part 2 of this lab assignment, you must save your completed Sage worksheet as a .sws file and submit it on Blackboard.

(This link might work. Otherwise, find the submission page under the Course Content link on the Blackboard page for this course.)