# This cell illustrates basis coordinates for a vector in the span of a 2D subspace
var('x,y,z,u,v')
@interact
def _(v1 = input_box(vector([3,6,2]),width=10,label='$v_1$'),
v2 = input_box(vector([-1,5,3]),width=10,label='$v_2$'),
v3 = input_box(vector([107/6,142/3,18]),width=10,label='$x$')):
n = v1.cross_product(v2)
# Compute the basis coordinates for v3 relative to v1 and v2
A = matrix([v1,v2,v3]).transpose().rref()
c1 = A[0,2]
c2 = A[1,2]
G = Graphics()
if (c1==0) & (c2==0):
print "V3 is not in the span of V1 and V2"
G += text3d('x is not in the span of V1 and V2',(1,1,5))
else:
G += text3d('Basis Coordinates = ('+str(c1)+','+str(c2)+')',(c1,c2,5))
if (c1==0) & (c2==0):
c1=1
c2=1
# Let's assume c1 and c2 are positive for now
a = floor(c1)+1
b = floor(c2)+1
for k in range(a):
# G += arrow((k*v1[0],k*v1[1],k*v1[2]),((k+1)*v1[0],(k+1)*v1[1],(k+1)*v1[2]),color='red',width=3)
for j in range(b):
here = (k*v1[0]+j*v2[0],k*v1[1]+j*v2[1],k*v1[2]+j*v2[2])
there =((k+1)*v1[0]+j*v2[0],(k+1)*v1[1]+j*v2[1],(k+1)*v1[2]+j*v2[2])
G += arrow(here,there,color='red',width=3)
for k in range(b):
for j in range(a):
here = (k*v2[0]+j*v1[0],k*v2[1]+j*v1[1],k*v2[2]+j*v1[2])
there =((k+1)*v2[0]+j*v1[0],(k+1)*v2[1]+j*v1[1],(k+1)*v2[2]+j*v1[2])
G += arrow(here,there,color='red',width=3)
G += arrow((0,0,0),(v1[0],v1[1],v1[2]),color='orange',zorder=3,width=4)
G += text3d('v1',(v1[0]/2,v1[1]/2,v1[2]/2))
G += arrow((0,0,0),(v2[0],v2[1],v2[2]),color='orange',zorder=3,width=4)
G += text3d('v2',(v2[0]/2,v2[1]/2,v2[2]/2))
G += arrow((0,0,0),(v3[0],v3[1],v3[2]),color='green',zorder=3,width=6)
G += parametric_plot3d((c1*v1[0]*u+c2*v2[0]*v, c1*v1[1]*u+c2*v2[1]*v, c1*v1[2]*u+c2*v2[2]*v), (u, 0, 1.2), (v, 0, 1.2), mesh=True,opacity=0.6)
G.show(spin=False)
|
Click to the left again to hide and once more to show the dynamic interactive window
|