var('r')
A=matrix([[5,2*r,r],[3,6,2*r-1],[2,r-1,3*r]])
print "Matrix A is given as:\n",A
b=matrix([[2],[3],[5]])
print "Matrix b is given as:\n",b
var('x1,x2,x3')
X=matrix([[x1],[x2],[x3]])
print "Matrix X is given as:\n",X
print "To solve matrix AX=b ,find inverse for A"
print "Inverse is only possible if the matrix is non-singular i.e determinant of matrix is not zero."
x(r)=A.det()
print "Determinant of A \nx(r)=",x(r)
print "To solve this problem consider any valid value for r.For instance consider r=1.So x(1)=",x(1)
K1=A(1)
print "A(1)=\n" ,K1
K=A(1).inverse()
print "X=(A(1).inverse)*b"
print "Resultant matrix X=\n",K*b
X=K*b
print "Value of x1=",X[0]
print "Value of x2=",X[1]
print "Value of x3=",X[2]