Solve A x= b by finding coefficients for the columns of A which show b lies in their span.
from sage.misc.html import HtmlFragment
def record_answer(ansVals): pretty_print( HtmlFragment('<input type=hidden size=15 name="sageAnswer" id ="sageAnswer" value="%s"><input type=hidden name="previous_sageAnswer" id = "previous_sageAnswer" value="">'%(ansVals,) ) )
b = matrix([[4.2],[-3.63]])
bt = b.transpose()
A=matrix([[2,1],[-2,-0.7]])
At =A.transpose()
# Notice the correct exact answer is given by x = A\b
var('A1')
# Finding when a vector b is in the span of other vectors in 2-space
# NOTICE the initialization using and in the slider
@interact
def _(x1=slider(-3,3,1/20,), x2=slider(-3,3,1/20,),zoomin=checkbox(default=false,label='Zoom In')):
(b1,b2,a11,a12,a21,a22) = (4.2,-3.63,2,1,-2,-0.7) # Convert WeBWorK variables to normal Sage variables
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 += arrow((0,0),(b1,b2),rgbcolor=(1,0,0),width=5)
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",(b1/2,b2/2),fontsize=20,color='purple')
G += point(x1*At[0],color='blue',pointsize=40)
G += point((b1,b2),color='red',pointsize=30)
G += point(x1*At[0]+x2*At[1],color='green',pointsize=40)
G += point((b1,b2),color='red',pointsize=20)
# Add fixed originals and dashed modified version of these
if zoomin:
show(G,frame=False)
scalex = 2
scaley = 2
else:
scalex = 2*max(abs(a11),abs(a12),abs(b1))
scaley = 2*max(abs(a21),abs(a22),abs(b2))
show(G,frame=False,xmin=-1*scalex,xmax=scalex,ymin=-1*scaley,ymax=scaley)
record_answer((x1, x2))
var jqSave = $.noConflict(true);
jqSave(function () {
sagecell.makeSagecell({
inputLocation: '#sagecell',
template: sagecell.templates.minimal,
autoeval: true,
linked: true,
evalButtonText: 'Click to run (or reset) vector display.'
});
});
$ = jQuery = jqSave;
When you are comfortable with the coefficients that you have chosen, press
the submit button below.

When solving ** A_1** represents the first column of A while