213 - A15 - Vectors and Linear Systems

29 days ago by Professor213

In this worksheet, the user will enter vectors (possibly random) interactively and explore taking various combinations of these vectors for solving systems. 

John Travis

Mississippi College

Linear Combinations of vectors and Span

The Span of a set of vectors {$A_1 A_2 ... A_n$} is the collection of vectors which can be obtained by taking a linear combination $x_1A_1+ x_2A_2+ ... +x_nA_n$of those vectors. 

Visually, this means determining whether an arbitrary vectors b can be written as a linear combination of the vectors $ [ A_1 A_2 ... A_n ] = A$.  That is, you can add the n (possibly scaled) vectors together using the paralleogram law to obtain b. 

Starting with a two-dimensional setting, see if you can find values of $x_1$ and  $x_2$ so that a linear combination of $A_1$ and $A_2$ equals the red vector $b$.

%hide %auto # Finding when a vector b is in the span of other vectors in 2-space @interact def _(A=random_matrix(QQ,2,2), b=matrix(QQ,2,1,(1,2)), x1=input_box(default=1,width=5,label="$x_1$"), x2=input_box(default=1,width=5,label="$x_2$"), Show_Exact=checkbox(False,label="Click to show the exact answer."), auto_update=false ): mida = min(max(A)) b = b.transpose()[0] 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 = arrow((0,0),x1*At[0]) Col2 = arrow(x1*At[0],x1*At[0]+x2*At[1]) ColB = arrow((0,0),b,rgbcolor=(1,0,0),width=5) # answer = text("Actual value ($x_1,x_2$)="+str(x),(0,0),color=(0,1,0)) if Show_Exact: x = A\b # Now, we show what the final result should look like Exact1 = arrow((0,0),x[0]*At[0],rgbcolor=(0,1,0),width=1) Exact2 = arrow(x[0]*At[0],x[0]*At[0]+x[1]*At[1],rgbcolor=(0,1,0),width=1) pretty_print(html("The light green vectors represent one (of possibly many) exact solution.")) pretty_print(html("Actual value ($x_1,x_2$)="+str(x) )) G = Col1+Col2+ColB+Exact1+Exact2 else: G = Col1+Col2+ColB show(G,frame=False) 
       
$x_1$ 
$x_2$ 
Click to show the exact answer. 

Click to the left again to hide and once more to show the dynamic interactive window

Experiment in the 2D case above by playing with several of the randomly generated problems.  If you don't like one that the computer has come up with, just generate a nicer one.

Without using the "exact answer" selection above, approximate the solution to the following linear system using the routine above.  Double click on this cell and place your answer in the slot below.

$3x_1 + 5x_2 = 12$

$-x_1 + 7x_2 = 0$

Your answer:  $x_1 =$ _______ and $x_2 =$ _________

 

For a little harder problem in 3D, see if you can find values of $x_1, x_2$ and  $x_3$ so that a linear combination of $A_1, A_2$ and $A_3$ equals the red vector $b$.

%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!' 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,thickness=8) Col2 = line3d([x1*At[0],x1*At[0]+x2*At[1]],arrow_head=True,thickness=8) Col3 = line3d([x1*At[0]+x2*At[1],x1*At[0]+x2*At[1]+x3*At[2]],arrow_head=True,thickness=8) ColB = line3d([(0,0,0),b],arrow_head=True,rgbcolor=(1,0,0),thickness=10) # 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=8) 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=8) 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=8) if Show_Exact: print html("The <font color=green><b>light green</b></font> vectors represent one (of possibly many) exact solution.") 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) 
       
$x_1$ 
$x_2$ 
$x_3$ 
Click to show the exact answer. 

Click to the left again to hide and once more to show the dynamic interactive window

Using this worksheet, solve problem number 14 on page 38 of the text.  Place your answers below.

b = random_vector(ZZ,2) print b # bt = b.transpose() A = random_matrix(ZZ,2,2) At = A.transpose() # Notice the correct exact answer is given by x = A\b # Finding when a vector b is in the span of other vectors in 2-space @interact def _(x1=slider(-3,3,1/20,1), x2=slider(-3,3,1/20,1),zoomin=checkbox(default=false,label='Zoom In')): G = Graphics() if zoomin==false: G += arrow((0,0),At[0],color='lightgray') G += arrow(At[0],At[0]+At[1],color='lightgray') G += arrow((0,0),x1*At[0],rgbcolor=(0,0,1)) G += arrow(x1*At[0],x1*At[0]+x2*At[1],rgbcolor=(0,1,0)) G += text("A1",(x1*At[0][0]/2,x1*At[0][1]/2),fontsize=15,color='purple') G += text("A2",(x1*At[0][0]+x2*At[1][0]/2,x1*At[0][1]+x2*At[1][1]/2),fontsize=15,color='purple') G += text("$b_1$",(0.5,0),fontsize=20,color='purple') G += point(x1*At[0],color='blue',pointsize=40) G += point(x1*At[0]+x2*At[1],color='green',pointsize=40) # Add fixed originals and dashed modified version of these scalex=2 scaley=2 show(G,frame=False,xmin=-1*scalex,xmax=scalex,ymin=-1*scaley,ymax=scaley) 
       

Click to the left again to hide and once more to show the dynamic interactive window

 
       
# this cell is a copy of the first cell but prepared for use as a webwork question A=random_matrix(QQ,2,2)*2 while det(A)==0: A=random_matrix(QQ,2,2) b=random_matrix(QQ,2,1) while b==matrix([[0],[0]]): b=random_matrix(QQ,2,1) mida = min(max(A)) b = b.transpose()[0] x = A\b At = A.transpose() # Finding when a vector b is in the span of other vectors in 2-space @interact def _(x1=slider(-4,4,1/10,1,label="$x_1$"), x2=slider(-4,4,1/10,1,label="$x_2$")): pretty_print(html("When solving \[Ax=b\]solution $x$ can be determined by finding a vector whose values are the coefficients")) pretty_print(html("which make a linear combination of the columns of A equal b. In the interactive cell below")) pretty_print(html("<font color=blue><b>$A_1$</b></font> represents the first column of A while")) pretty_print(html("<font color=green><b>$A_2$</b></font> represents the second column of A.")) pretty_print(html("Determine values of $x_1$ and $x_2$ so that $x_1 A_1 + x_2 A_2 = $<font color=red><b>$b$</b></font>.")) Col1 = arrow((0,0),x1*At[0],rgbcolor=(0,0,1))+text("$A_1$",(x1*At[0][0]/2,x1*At[0][1]/2),fontsize=30,color="black") Col2 = arrow(x1*At[0],x1*At[0]+x2*At[1],rgbcolor=(0,1,0))+text("$A_2$",(x1*At[0][0]+x2*At[1][0]/2,x1*At[0][1]+x2*At[1][1]/2),fontsize=30,color="black") ColB = arrow((0,0),b,rgbcolor=(1,0,0),width=5)+text("$b$",(b[0]/2,b[1]/2),fontsize=30,color="black") G = Col1+Col2+ColB show(G,frame=False) 
       

Click to the left again to hide and once more to show the dynamic interactive window

# this cell is a variant of the first cell but prepared for use as a webwork question A=matrix(QQ,[[1,2],[3,4]])*3 print A b=matrix(QQ,[[2],[1]]) print b mida = min(max(A)) b = b.transpose()[0] x = A\b At = A.transpose() # Finding when a vector b is in the span of other vectors in 2-space @interact def _(x1=slider(-3,3,1/100,1,label="$x_1$"), x2=slider(-3,3,1/100,1,label="$x_2$")): pretty_print(html("When solving \[Ax=b\]solution $x$ can be determined by finding a vector whose values are the coefficients")) pretty_print(html("which make a linear combination of the columns of A equal b. In the interactive cell below")) pretty_print(html("<font color=blue><b>$A_1$</b></font> represents the first column of A while")) pretty_print(html("<font color=green><b>$A_2$</b></font> represents the second column of A.")) pretty_print(html("Determine values of $x_1$ and $x_2$ so that $x_1 A_1 + x_2 A_2 = $<font color=red><b>$b$</b></font>.")) Col1 = arrow((0,0),x1*At[0],rgbcolor=(0,0,1))+text("$A_1$",(x1*At[0][0]/2,x1*At[0][1]/2),fontsize=30,color="black") Col2 = arrow(x1*At[0],x1*At[0]+x2*At[1],rgbcolor=(0,1,0))+text("$A_2$",(x1*At[0][0]+x2*At[1][0]/2,x1*At[0][1]+x2*At[1][1]/2),fontsize=30,color="black") ColB = arrow((0,0),b,rgbcolor=(1,0,0),width=5)+text("$b$",(b[0]/2,b[1]/2),fontsize=30,color="black") G = Col1+Col2+ColB show(G,frame=False) 
       

Click to the left again to hide and once more to show the dynamic interactive window

A = random_matrix(ZZ,4,4) show(A) A.echelon_form() 
       
[1 0 0 1]
[0 0 1 1]
[0 0 0 2]
[0 0 0 0]
[1 0 0 1]
[0 0 1 1]
[0 0 0 2]
[0 0 0 0]