CoCalc
SharedLab 06 / Lab6-turnin.sagewsOpen in CoCalc
Authors: Enrique Jimenez, Omeed Zokaeim
Views : 4
# Lab 6

# Name: Omeed Zokaeim
# I worked on this code with:

# Please do all of your work for this week's lab in this worksheet. If
# you wish to create other worksheets for scratch work, you can, but
# this is the one that will be graded. You do not need to do anything
# to turn in your lab. It will be collected by your TA at the beginning
# of (or right before) next week’s lab.

# Be sure to clearly label which question you are answering as you go and to

#43
@interact
def mycoordinatefunction(r=(-10,10),s=(-10,10), target=vector([2,3])): #this creates sliders for scalar by setting up an interactive function
u=r*vector ([1 ,2]) #defines the basis, our vectors u and v.
v=s*vector ([1 ,.5])
wee= u+v #this calculates the sum of u + v and assigns it to our variable
p=plot(u, axes_labels=["x", "y"]) + plot(v, color="red") + plot(wee, color="purple") + plot(target, color="yellow") + point(target, size=50, color="green") #plots vectors u and v, their sum, and our point, on the same set of axes through overlaying them
show(p)

#44
@interact
def mycoordinatefunction(r=(-10,10),s=(-10,10), target=vector([2,3])):
u=r*vector ([5,2]) #this defines a new basis by changing our vectors
v=s*vector ([3,.5])
wee=[(u[0]+v[0] ,u[1]+v[1])]
p=plot(u, axes_labels=["x", "y"]) + plot(v, color="red") + plot(u+v, color="purple") + list_plot(wee, size=50, color="yellow") + point(target, size=50, color="green")
show(p)

#45
@interact
def mycoordinatefunction(r=(-10,10),s=(-10,10), target=vector([2,3])):
u=r*vector ([1 ,1]) #define basis.
v=s*vector ([2 ,2])
wee=[(u[0]+v[0] ,u[1]+v[1])]
p=plot(u, axes_labels=["x", "y"]) + plot(v, color="red") + plot(u+v, color="purple") + list_plot(wee, size=50, color="yellow") + point(target, size=50, color="green")
show(p)
show(wee)

#46
t=matrix(RDF, [[1, 1] ,[2, 1/2]]) #defines the 2x2 matrix
t*vector([4/3, 2/3]) #this verifies the matrix's ability to convert from r,s to x,y corrdinates for point (2 ,3)
t*vector([ -4 ,0]) #verifies for point ( -4 , -8)
t*vector([ -2.6 ,5.6]) #verifies for point (3 , -2.4)

(2.0, 3.0) (-4.0, -8.0) (2.9999999999999996, -2.4000000000000004)
#I notice that the t matrix successfully converts r,s-coordinates back into the x,y coordinate system.

#47
w=matrix(RDF, [[ -1/3 ,2/3], [4/3 , -2/3]]) #thia defines a new matrix corresponding to our expanded system of equations

#48
w*vector([1 , -6])

(-4.333333333333333, 5.333333333333333)
#The interactive in #43 gives the R,S coordinates (-4.33, 5.33) which correspond to the point (1,-6) used here. This checks out.

#49
w*vector([4 ,5])

(1.9999999999999998, 2.0)
#The interactive in #43 gives the R,S coordinates (2, 2) which corresponds to the point (4,5) used here. This checks out as well, even with a very small sage rounding error.

#50
t.inverse()

[-0.3333333333333333 0.6666666666666666] [ 1.3333333333333333 -0.6666666666666666]
#This matrix is the same as the one obtained in number 47, so the results again check out exactly.

#51
m=matrix(RDF, [[7,-4], [4,-3]])
m.eigenvectors_right()

[(5.0, [(0.8944271909999159, 0.4472135954999579)], 1), (-1.0, [(0.4472135954999579, 0.8944271909999159)], 1)]
#Eigenvector u=[1,2], a multiple of (0.447213,0.894427), has an eigenvalue of -1, and eigenvector v=[1,0.5], a multiple of (0.894427,0.447213) has an eigenvalue of 5.

#52
w*m*t

#The product of these matrices, that is their composition, gives us a diagonal matrix. The numbers in the diagonal correspond to the eigenvalues that we obtained in #51 and the anti-diagonal should have both numbers as zero (sage has a very small rounding error but the top right number is essentially zero).