%hide
%auto
# Finding when a vector b is in the span of other vectors in 3-space
@interact
def _(A=random_matrix(QQ,3,3), b=matrix(QQ,3,1,(1,2,3)), x1=input_box(default=1,width=5,label="$x_1$"), x2=input_box(default=1,width=5,label="$x_2$"), x3=input_box(default=1,width=5,label="$x_3$"), Show_Exact=checkbox(False,label="Click to show the exact answer."), auto_update=false ):
mida = max(min(A))
b = b.transpose()[0]
if det(A)<>0:
dependent = False
x = A\b
else:
dependent = True
print 'Vectors are dependent!'
pretty_print(html("Experiment with these values to make the tip of the <font color=red><b>red</b></font> vector <br>line up with the sum (the end) of the <font color=blue><b>blue ones</b></font>"))
At = A.transpose()
Col1 = line3d([(0,0,0),x1*At[0]],arrow_head=True)
Col2 = line3d([x1*At[0],x1*At[0]+x2*At[1]],arrow_head=True)
Col3 = line3d([x1*At[0]+x2*At[1],x1*At[0]+x2*At[1]+x3*At[2]],arrow_head=True)
ColB = line3d([(0,0,0),b],arrow_head=True,rgbcolor=(1,0,0),line_width=5)
# Now, we show what the final result should look like
if not dependent:
Exact1 = line3d([(0,0,0),x[0]*At[0]],arrow_head=True,opacity=0.1,rgbcolor=(0,1,0),thickness=4)
Exact2 = line3d([x[0]*At[0],x[0]*At[0]+x[1]*At[1]],arrow_head=True,opacity=0.1,rgbcolor=(0,1,0),thickness=4)
Exact3 = line3d([x[0]*At[0]+x[1]*At[1],x[0]*At[0]+x[1]*At[1]+x[2]*At[2]],arrow_head=True,opacity=0.1,rgbcolor=(0,1,0),thickness=4)
if Show_Exact:
pretty_print(html("The <font color=green><b>light green</b></font> vectors represent one (of possibly many) exact solution."))
pretty_print(html("Actual value ($x_1,x_2,x_3$)="),str(x))
G = Col1+Col2+Col3+ColB+Exact1+Exact2+Exact3
else:
G = Col1+Col2+Col3+ColB
show(G,frame=True)
|
Click to the left again to hide and once more to show the dynamic interactive window
|