CoCalc Public FilesLab 9 / Lab9-turnin.ipynb
Author: Nushrat Esha
Views : 171
Compute Environment: Ubuntu 20.04 (Default)
In [ ]:
# Name: Nushrat Esha
# I worked on this code with: Ryan, Xavier, and Fuijia

# 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


In [1]:
#46
u=vector([1,2])
v=vector([1,0.5])
T=column_matrix(RDF, [u,v])
show(T)

$\left(\begin{array}{rr} 1.0 & 1.0 \\ 2.0 & 0.5 \end{array}\right)$
In [9]:
#47
R=1.35
S=0.65
T*vector([R, S])

# when verified, the value is very close to the point, with one of the numbers, 3.025, being slightly greater than 3

(2.0, 3.0250000000000004)
In [10]:
#48a
# point (-5, 1.2)
R=2.45
S=-7.5
T*vector([R, S])

(-5.05, 1.1500000000000004)
In [11]:
#48b
# point (-4, -8)
R=-4
S=0
T*vector([R, S])

(-4.0, -8.0)
In [15]:
#49
# expand the equations - (1) R = X -S  (2) S = 1.5*X - 0.67*Y
W=matrix(RDF, [[-0.33, 0.66], [1.33, -0.66]])
show(W)

$\left(\begin{array}{rr} -0.33 & 0.66 \\ 1.33 & -0.66 \end{array}\right)$
In [21]:
#50
W*vector([1,-6])

(-4.29, 5.29)
In [29]:
#50 check
@interact
def plotvectors(R=(-10,10, 0.1), S=(-10,10, 0.1), target=vector([1, -6])):
u=R*vector([1,2])
v=S*vector([1,0.5])
p_u=plot(u, color="red", aspect_ratio=1.0, legend_label="u", legend_color="black")
p_v=plot(v, color="green", legend_label="v", legend_color="black")
p_s=plot(R*u+S*v, color="blue", legend_label="sum", legend_color="black")
p_t=plot(target, color="black", legend_label="goal", legend_color="black")
show(p_u + p_v + p_s + p_t)

# the target was hit

In [26]:
#51
# point (3, -7)
W*vector([3,-7])

(-5.61, 8.61)
In [30]:
#51 check
@interact
def plotvectors(R=(-10,10, 0.1), S=(-10,10, 0.1), target=vector([3, -7])):
u=R*vector([1,2])
v=S*vector([1,0.5])
p_u=plot(u, color="red", aspect_ratio=1.0, legend_label="u", legend_color="black")
p_v=plot(v, color="green", legend_label="v", legend_color="black")
p_s=plot(R*u+S*v, color="blue", legend_label="sum", legend_color="black")
p_t=plot(target, color="black", legend_label="goal", legend_color="black")
show(p_u + p_v + p_s + p_t)

# the target was hit

In [23]:
#52
T.inverse()

[-0.3333333333333333 0.6666666666666666] [ 1.3333333333333333 -0.6666666666666666]
In [31]:
#53
# the result from number 49 and number 52 are the same, the W matrix and the inverse T matrix are equal to each other

In [24]:
#54
M=matrix(RDF, [[7,-4],[4,-3]])
u=vector([1,2])
v=vector([1,.5])
M.eigenvectors_right()

# the eigenvalues are 5 and -1

[(5.0, [(0.8944271909999159, 0.4472135954999579)], 1), (-1.0, [(0.4472135954999579, 0.8944271909999159)], 1)]
In [33]:
#55
W*M*T
# this is a diagonalized matrix and the eigenvalues are 5 and -1. It is a diagonal matrix because it has  values that are very close to 0 on the nondiagonals and this occurs because of the rounding difference. Since this is a diagonalized matrix, this means that the eigenvalues are 5 and -1 as computed in question 54.

[ -0.99 5.551115123125783e-17] [-0.010000000000000675 5.0]
In [ ]: