## Section 1.4 CAS - Systems of Equations

ΒΆ###### Objectives

- Input vectors and matrices
- Multiply matrices and vectors
- plot vectors in two and three dimensions
- perform elementary row operations
- solve systems of equations
- enter comments so that your code can be understood
- get help

### Subsection 1.4.1 A Few Basic Commands

Vectors are entered into sage like so:

v=vector([7,-1])

And matrices like this:

A=matrix([[2,3],[4,5]])

Finish entering the vector and matrix in the Sage Cell, then hit `Evaluate (Sage)`

.

*Comments and Comprehension Check*

- Looking at the output what is the difference between
`print`

and`pretty_print`

? - In
`pretty_print(A,v,"=",Av_product)`

it actually prints the values for the matrix and vector, but in`pretty_print("av+bu=",linear_combo)`

it prints the letters, what is the difference in how these were entered? - Sage is a little sloppy with its vectors, it always writes them horizontally. In one of the print commands change
`v`

to`matrix(v).transpose()`

, what happens? - Try adding these lines to the end and re-evaluating the cell:
print type(A) print type(v) print type(Av_product) print type(vector(A)) print type(matrix(v))

What does the`type`

command tell you? What happens when you put a matrix inside the`vector`

command or vice versa? - Reload the page and click
`Evaluate (Sage)`

without filling in the missing values, based on what you know should happen try to make some sense of the error messages. - What happens if you put a
`#`

in front of a line of text?

### Subsection 1.4.2 The Big Picture

Next let's get a handle on visualizing our vectors and systems of equations, go ahead and click `Evaluate (Sage)`

to begin.

*Comments and Comprehension Check*

- The first thing you should try is clicking and dragging on the image, what happens? What if click on the image and then scroll?
- Try changing some of the parameters in the plot commands, like
`width`

,`color`

, or`(x,-5,5)`

, what happens when you re-evaluate? - Following the example of
`v_plot`

and`u_plot`

create an arrow plot of the vector \(R\vec{v}\) with the matrix \(R\) provided. - Looking at how the plain and the vector \(\vec{v}\) are plotted, try and add the plots of \(\vec{u}\) and \(R\vec{v}\) to the picture.
- Add the command
`implicit_plot3d?`

to the end of the cell and re-evaluate, what happens? - Now try the same with
`arrow?`

, what do you get? What should you type in if your looking for a three dimensional arrow?

### Subsection 1.4.3 Solving Equations

We can use sage to find solutions to the sorts of systems of equations we have been working on, only it can do the heavy lifting. Let us start with the homogeneouos system:

\begin{align*}
3x+y-z\amp =0\\
-x+7y\amp =0\\
2x+8y-z\amp =0
\end{align*}

Enter the corresponding matrix of coefficients, vector of variables, and zero vector, then click `Evaluate (Sage)`

.

*Comments and Comprehension Check*

- Look carefully at the output; what are the effects of the commands
`augment`

,`swap_rows`

,`rescale_row`

, and`add_multiple_of_row`

? - Using the row commands you just looked at, finish row reducing the matrix to row echelon form in order to find all the possible solutions.
- Now uncomment
`#A.solve_right?`

and learn to use the`solve_right`

command. How do these results compare to what you found using row reduction? - Next try the same with
`#A.solve_right`

? - Finally look at the situation graphically. Start by uncommenting the lines where it says
`#A1 = A.column(0)`

and`#A2 = A.column(1)`

and re-evaluating the Sage Cell. What do these commands do? If you are unsure try using the command`A.column?`

to get help. - Plot the vectors
`A1`

,`A2`

, and`A3`

along with the plane whose plot is defined parametrically with`parametric_plot3d(A1*t+A2*s,(t,-1,1),(s,-1,1))`

. What do you notice about the three vectors and the plane? How does this relate to the solutions for this system?