Math317-Lab2
system:sage


<h2>Part 2.</h2>
<p>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.&nbsp;</p>
<p>In that problem we are given</p>
<p>\[A = \left[\begin{matrix}1&amp;1&amp;1\\0&amp;1&amp;1\\1&amp;2&amp;1\end{matrix}\right] \; \text{ and } \; \mathbf{b} = \left[\begin{matrix}3\\0\\1\end{matrix}\right].\]</p>
<p>Using the matrix and vector constructors, define $A$ and $\mathbf{b}$ in Sage by evaluating the next cell.</p>

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

<p>The problem in Homework 4 asked for the inverse of $A$. &nbsp;To compute $A^{-1}$ by hand, we augment $A$ with an identity matrix and then perform Gaussian elimination. &nbsp;</p>
<p>Although Sage has an inverse command, we will not use it just yet. &nbsp;In fact, using the built-in inverse command at this point would defeat the purpose of this exercise, so don't use it!</p>
<p>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). &nbsp;</p>
<p>First, augment $A$ with the identity matrix by evaluating the next cell.</p>

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

<p>Take note of how Sage lets us augment a matrix with an entire matrix (not just a single vector as we were doing earlier). &nbsp;</p>
<p>(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.)</p>

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

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

<h2>Exercises</h2>

<p>&nbsp;<strong>Exercise 2.1.</strong> Define a new matrix in Sage, called $B$, and set it equal to the inverse of the matrix $A$ above.</p>
<p>(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.)</p>

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

<p><strong>Exercise 2.2.</strong> Use Sage to check that $B$ really is the inverse of $A$ by computing&nbsp;$BA$ and $AB$.</p>

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

<p><strong>Exercise 2.3.</strong> 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.</p>
<p>(Hint: this is an easy computation involving only the matrix $B$ and the vector $\mathbf{b}$.)</p>

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

<p>Check that your answer is correct by evaluating the next cell.</p>

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

<p>If Sage returned the result True, congratulations! &nbsp;You have completed Lab 2. &nbsp;</p>
<p><strong>Important:</strong> 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.</p>
<p>(<a href="https://bb.its.iastate.edu/webapps/blackboard/content/listContentEditable.jsp?content_id=_2671137_1&amp;course_id=_50962_1" target="_blank">This link</a> might work. Otherwise, find the submission page under the Course Content link on the Blackboard page for this course.)</p>