This is a tiny step down the path we will take this Fall using SageMath through Jupyter - and hosted by CoCalc - to illustrate key concepts during the course of CS410. Today, the very basics of formulas and linear algebra.

Ross Beveridge, August 25, 2020

1

In [33]:

%display latex latex.matrix_delimiters(left='|', right='|') latex.vector_delimiters(left='[', right=']')

2

To begin, you can designate variables that will be treated as symbolic as opposed to values.

3

In [34]:

var('a','b','c','d','x','y')

4

$\left(a, b, c, d, x, y\right)$

Next you can create vectors and matrices which are symbolic (not numeric - yet)

5

In [39]:

mm = matrix([[a,b],[c,d]]) uu = vector([x,y]) mm,uu

6

$\left(\left|\begin{array}{rr}
a & b \\
c & d
\end{array}\right|, \left[x,\,y\right]\right)$

But notice all we have done so far is to implicitly create a sequence of the two objects, the matrix and the vector, and print them back in the basic Python/Jupyter/SageMath Read-Eval-Pring Loop. What if we want to create better formed equations?

7

In [40]:

pretty_print("m = ", mm, " and", " u = ", uu)

8

$\verb|m|\phantom{\verb!x!}\verb|=| \left|\begin{array}{rr}
a & b \\
c & d
\end{array}\right| \phantom{\verb!xx!}\verb|and| \phantom{\verb!xx!}\verb|u|\phantom{\verb!x!}\verb|=| \left[x,\,y\right]$

Next complication is that a matrix times a vector becomes somewhat an issue deep in the particulars of any given language. Conceptually, it may at times be simplest to realize that a vector is - when doing matrix multiplication - just a one dimensional matrix. So below we arrive at the simple case of a 2x2 matrix times a 2x1 vector/matrix

9

In [37]:

um = matrix(uu).transpose() pretty_print(LatexExpr("M = "), mm, ", ", LatexExpr("U = "), um)

10

$M = \left|\begin{array}{rr}
a & b \\
c & d
\end{array}\right| \verb|,| U = \left|\begin{array}{r}
x \\
y
\end{array}\right|$

In [38]:

vm = mm * um pretty_print(vm, " = ", mm, "*", um)

11

$\left|\begin{array}{r}
a x + b y \\
c x + d y
\end{array}\right| \phantom{\verb!x!}\verb|=| \left|\begin{array}{rr}
a & b \\
c & d
\end{array}\right| \verb|*| \left|\begin{array}{r}
x \\
y
\end{array}\right|$

And while it may not seem like much, notice that SageMath carried out the symbolic computation of multiplying a matrix and a column vector. Put simply, anyone spending much of their life working with linear algebra in contexts such as computer graphics, should master a tool such as SageMath (Maple, Mathematic, ..). The reason is that true understanding comes from personal experience working back and forth between multiple ways of conceptualizing a problem, and hence any tool that does the routine part for you is helpful.

12