Objectives
At this point, we've learned the basic mathematical concepts and notation for expressing linear systems symbolically and in terms of a matrix. We've also learned how to solve those systems using elimination. More formally, in the context of matrices, we've learned how to place a matrix into reduced row echelon form using Gauss-Jordan elimination. In principle, these processes are fairly simple but can be tedious - particularly, as we move to larger systems.
Thus, in this lab, we'll learn how to automate these processes on the computer.
Solving linear systems is an absolutely fundamental part of computational science. As a result, there are loads of systems to choose from for this task and no single system that's the best possible choice for everyone. For this class, I've chosen to use SageMath. Advantages of this choice include:
-
Sage has both symbolic and numeric tools.
(Many systems neglect symbolics to focus on numerics. There's very good reason for this but that might not be ideal at the introductory level.) - Sage is free and open! I mean extremely free. For example, you can access it with no login online via the Sage Cell Server.
- To expand on the previous point, the blocks of code in this document are live. You can evaluate them, edit them, and evaluate any Sage code you want. This is all powered via the Sage Cell Server.
Expressing and solving linear systems of equations
At its most elementary level, linear algebra deals with systems of linear equations. Sage is able to deal with symbolic expressions and we can certainly express and solve linear systems symbolically. Suppose, for example, that we'd like to solve the following system:
$$ \begin{align} 3x_1-4x_2+6x_3-2x_4 &= 2 \\ 3x_2 - x_4 &= 9 \\ 5x_1-2x_2-3x_3-3x_4 &= -8 \\ 9x_1+x_2-4x_3+2x_4 &= 8 \end{align} $$
We can do so very easily with Sage's solve
command:
Note that we get exactly one solution. Here are a couple of obvious modifications you should think about.
- Try removing one equation so that we have an underdetermined system. How can you interpret the result? What happens if we remove two equations?
- How might you modify the system so that it is inconsistent? What type of result does Sage return in that case?
Problem 1
Use Sage's solve
command to solve the following system.
What happens if you delete two of the equations?
You should post your answer as a comment to this forum discussion. Be sure to:
- Describe the the problem with prose and your initial typeset system.
- Include the code you used to solve the problem.
- Recall that a block of code can be displayed as code by simply indenting four spaces.
- Include the output of your command, also as a code block.
- Describe your interpretation of the output.
- Repeat the process for the modified, undetermined system you obtained by removing two of the equations.
Reduced Row Echelon Form
As we've seen, systems of equations can be represented more compactly using matrices. In this context, the process of solving the system can be expressed in terms of placing the matrix into reduced row echelon form. Working with matrices at this level is often more efficient than working with systems of equations - on the computer, as well as by hand. Thus, it's not surprising that Sage has tools to define and work with matrices directly. Suppose, for example, that we'd like to find the Reduced Row Echelon Form of $$ \left( \begin{array}{cccccc} -2 & -8 & -1 & -8 & -6 & -5 \\ 16 & -8 & 8 & 6 & -5 & 0 \\ 8 & 8 & 4 & -8 & -4 & -1 \\ 8 & -16 & 4 & 14 & -1 & 1 \\ -12 & 3 & -6 & -5 & 2 & -4 \\ \end{array} \right). $$ We can do so with the following Sage code:
Problem 2
Use Sage to find the reduced row echelon form of the following matrix:
If we view this matrix as the augmented matrix of a system, what is the system and what is the solution?
You should post your answer as a comment to this forum discussion. Be sure to:
- Describe the the problem with prose and your initial typeset matrix.
- Include the code you used to solve the problem.
- Include the output of your command, also as a code block.
- Describe your interpretation of the output - including the solution of the corresponding system in terms of any free variables.