# Basic Sage emphasizing linear algebra and graph theory commands
# by Leslie Hogben
# Anything that starts with a number sign is a comment
# This is an example of a comment
# If you can't see everything in a cell, drag the lower right corner
# to make it bigger.
# Sage is cell based and chronological.
# This means Sage knows what you have entered previously and
# uses the last entered value.
# You do not have to go from the top down.
# To enter (evaluate) the cell, place the curser in the cell
# (and click to get a vertical cursor "|").
# Then press the SHIFT and RETURN keys at the same time.
# Enter this cell to compute 2+3*4 and assign it to the variable a
a=2+3*4
# Enter this cell to see what you just computed.
a
# Edit and enter this cell to do your own computations.
# Do this repeatedly.
b=6*2-5
b
# Make a new cell by clicking when you see a horizontal blue line
# (mover cursor between cells).
# Enter your own computation in your new cell.
# complex arithmetic
a=1+i
print a
a*a
conjugate(a)
1/a
# ordinary functions
sin(1.5)
e^1.
################################
# GETTING INFORMATION FROM SAGE
################################
# Now we will enter matrices and do arithmetic with them.
# You have to tell Sage that what you are entering is a matrix.
m1=matrix([[1,2],[3,4]])
m1
# this is a pretty way to display a matrix (if it works)
show(m1)
m2=matrix([[7,-3],[0,5]])
show(m2)
# Matrix arithmetic is pretty self evident
m1+m2
m1*m2
m2^2
# inverse
m1^(-1)
# matrix entry
# Sage numbers starting with zero so the rest of the world would call this the 1,1-entry
# but Sage calls it the 0,0-entry
m1[0,0]
m1
m1[0,1]
m2.column(1)
mm=copy(m2)
mm.set_column(1,[0,0])
mm
mm[1,0]=-1
mm
identity_matrix(3)
rank(m1)
transpose(m1)
det(m1)
charpoly(m1)
# Vectors
# vectors are different from matrices, but can be multiplied by matrices
# and wil orient as needed when clear
v = vector([2, 1, -2])
identity_matrix(3)*v
v*identity_matrix(3)
# vectors cannot be transposed without conversion to matrix
transpose(v)
# to transpose first convert to matrix
w=matrix([v])
show(w)
show(transpose(w))
# it is not recommended to muliply vectors as below
# but it is treated as dot product if you do
v*v
show(v)
norm(v)
# Sage uses weird notation for a lot of its functions, using
# "x.function()"
# rather than function(x). Most are available this way, and
# this is the only way some are available