Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

First CS410 SageMath Notebook for Fall 2020

Views: 284
License: APACHE
Image: ubuntu2004
Kernel: SageMath 9.1

First 410 Notebook Illustrating SageMath on CoCalc

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

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

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

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

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

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

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?

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

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

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

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.