08.02.2015 Views

Sage Reference Manual: Matrices and Spaces of Matrices - Mirrors

Sage Reference Manual: Matrices and Spaces of Matrices - Mirrors

Sage Reference Manual: Matrices and Spaces of Matrices - Mirrors

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Sage</strong> <strong>Reference</strong> <strong>Manual</strong>: <strong>Matrices</strong> <strong>and</strong> <strong>Spaces</strong> <strong>of</strong> <strong>Matrices</strong>, Release 6.1.1<br />

Solving over a polynomial ring:<br />

sage: x = polygen(QQ, ’x’)<br />

sage: A = matrix(2, [x,2*x,-5*x^2+1,3])<br />

sage: v = vector([3,4*x - 2])<br />

sage: X = A \ v<br />

sage: X<br />

((-8*x^2 + 4*x + 9)/(10*x^3 + x), (19*x^2 - 2*x - 3)/(10*x^3 + x))<br />

sage: A * X == v<br />

True<br />

Solving some systems over Z/nZ:<br />

sage: A = Matrix(Zmod(6), 3, 2, [1,2,3,4,5,6])<br />

sage: B = vector(Zmod(6), [1,1,1])<br />

sage: A.solve_right(B)<br />

(5, 1)<br />

sage: B = vector(Zmod(6), [5,1,1])<br />

sage: A.solve_right(B)<br />

Traceback (most recent call last):<br />

...<br />

ValueError: matrix equation has no solutions<br />

sage: A = Matrix(Zmod(128), 2, 3, [23,11,22,4,1,0])<br />

sage: B = Matrix(Zmod(128), 2, 1, [1,0])<br />

sage: A.solve_right(B)<br />

[ 1]<br />

[124]<br />

[ 1]<br />

Solving a system over the p-adics:<br />

sage: k = Qp(5,4)<br />

sage: a = matrix(k, 3, [1,7,3,2,5,4,1,1,2]); a<br />

[ 1 + O(5^4) 2 + 5 + O(5^4) 3 + O(5^4)]<br />

[ 2 + O(5^4) 5 + O(5^5) 4 + O(5^4)]<br />

[ 1 + O(5^4) 1 + O(5^4) 2 + O(5^4)]<br />

sage: v = vector(k, 3, [1,2,3])<br />

sage: x = a \ v; x<br />

(4 + 5 + 5^2 + 3*5^3 + O(5^4), 2 + 5 + 3*5^2 + 5^3 + O(5^4), 1 + 5 + O(5^4))<br />

sage: a * x == v<br />

True<br />

Solving a system <strong>of</strong> linear equation symbolically using symbolic matrices:<br />

sage: var(’a,b,c,d,x,y’)<br />

(a, b, c, d, x, y)<br />

sage: A=matrix(SR,2,[a,b,c,d]); A<br />

[a b]<br />

[c d]<br />

sage: result=vector(SR,[3,5]); result<br />

(3, 5)<br />

sage: soln=A.solve_right(result)<br />

sage: soln<br />

(-b*(3*c/a - 5)/(a*(b*c/a - d)) + 3/a, (3*c/a - 5)/(b*c/a - d))<br />

sage: (a*x+b*y).subs(x=soln[0],y=soln[1]).simplify_full()<br />

3<br />

sage: (c*x+d*y).subs(x=soln[0],y=soln[1]).simplify_full()<br />

5<br />

sage: (A*soln).apply_map(lambda x: x.simplify_full())<br />

(3, 5)<br />

256 Chapter 7. Base class for matrices, part 2

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!