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([[0.8],[-1.22],[-5.48]])
bt = b.transpose()
A=matrix([[2,1,1],[-2,-0.7,-1],[-1.5,4.7,2]])
At =A.transpose() # so that we can easily slice the matrix by rows instead of columns
# 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(-2,2,1/5,), x2=slider(-2,2,1/5,), x3=slider(-2,2,1/5,)):
G = line3d([(0,0,0),x1*At[0]],arrow_head=True,rbgcolor=(1,0,0))
G += line3d([x1*At[0],x1*At[0]+x2*At[1]],arrow_head=True)
G += line3d([x1*At[0]+x2*At[1],x1*At[0]+x2*At[1]+x3*At[2]],arrow_head=True)
G += line3d([(0,0,0),(0.8,-1.22,-5.48)],arrow_head=True,rgbcolor=(1,0,0),line_width=5)
G += text3d("A1",(x1*At[0][0]/2,x1*At[0][1]/2,x1*At[0][2]/2),fontsize=30,color='purple')
G += text3d("A2",(x1*At[0][0]+x2*At[1][0]/2,x1*At[0][1]+x2*At[1][1]/2,x1*At[0][2]+x2*At[1][2]/2),fontsize=30,color='purple')
G += text3d("A3",(x1*At[0][0]+x2*At[1][0]+x3*At[2][0]/2,x1*At[0][1]+x2*At[1][1]+x3*At[2][1]/2,x1*At[0][2]+x2*At[1][2]+x3*At[2][2]/2),fontsize=30,color='purple')
G += text3d("b",(0.8/2,-1.22/2,-5.48/2),fontsize=40,color='purple')
show(G,frame=False)
record_answer((x1,x2,x3))
var jqSave = $.noConflict(true);
jqSave(function () {
sagecell.makeSagecell({
inputLocation: '#sagecell',
template: sagecell.templates.minimal,
autoeval: true,
linked: true,
evalButtonText: 'Click Here to Evaluate/Reload'
});
});
$ = 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