All published worksheets from http://sagenb.org
Image: ubuntu2004
A matrix is a rectangular array of values.
\[
A_{m,n} =
\begin{bmatrix}
a_{1,1} & a_{1,2} & \cdots & a_{1,n} \\
a_{2,1} & a_{2,2} & \cdots & a_{2,n} \\
\vdots & \vdots & \ddots & \vdots \\
a_{m,1} & a_{m,2} & \cdots & a_{m,n}
\end{bmatrix}
Note in the computational world, indexing usually begins at .
However, traditional math texts (such as ours) often begin indexing with . An annoyance, maybe, but a good thing to get used to.
You'll see the use of both both types of indexing often. It's just a matter of learning to pay attention to details.
\[
A_{m,n} =
\begin{bmatrix}
a_{0,0} & a_{0,1} & \cdots & a_{0,(n-1)} \\
a_{1,0} & a_{1,1} & \cdots & a_{1,(n-1)} \\
\vdots & \vdots & \ddots & \vdots \\
a_{(m-1),0} & a_{(m-1),1} & \cdots & a_{(m-1),(n-1)}
\end{bmatrix}
$M =
\begin{bmatrix}
a & b & c \\
d & e & f \\
g & h & i
\end{bmatrix}
$
Computationally speaking, we can think of a matrix as a list of lists.
Python supports negative indexing:
Negative indexing can be very useful.
This list of lists we created is structurally a matrix, but it doesn't yet know how to act like a matrix.
It's kind of a dumb matrix.
Sage provides a way to transform a dumb matrix into a smart matrix.
A smart matrix knows how to perform all kinds of useful matrix operations.
To create a smart matrix from a dumb matrix:
is now a smart matrix! A matrix object will automatically display itself as a rectangular array rather than as a list of lists.
The indexing we were using works the same as before:
However, with a matrix object, we also have access to another kind of indexing:
This kind of indexing allows us to specify submatrices:
Now that is a matrix object, we can do all sorts of useful matrixy kinds of things with it.
To find out what these things are, enter '' (the letter followed by a period) in the cell below, if it's not there already, and then press the TAB key.
A window will pop up will all kinds of functions.
Wow! (To close the window, press the escape key.)
We'll be using just a few of those functions.
Here are some examples.
Evaluate the following: