Matrix_Examples

234 days ago by liliana.castanon@tecpabellon

MS = MatrixSpace(QQ,2,3) A = MS([[1,2,3],[4,5,6]]) A 
       
[1 2 3]
[4 5 6]
[1 2 3]
[4 5 6]
A.echelon_form() 
       
[ 1  0 -1]
[ 0  1  2]
[ 1  0 -1]
[ 0  1  2]
MS = MatrixSpace(QQ,3,4) A = MS([[7/15,6/15,2/15,380],[6/15,4/15,5/15,500],[2/15,5/15,8/15,620]]) A 
       
[7/15  2/5 2/15  380]
[ 2/5 4/15  1/3  500]
[2/15  1/3 8/15  620]
[7/15  2/5 2/15  380]
[ 2/5 4/15  1/3  500]
[2/15  1/3 8/15  620]
A.echelon_form() 
       
[  1   0   0 300]
[  0   1   0 300]
[  0   0   1 900]
[  1   0   0 300]
[  0   1   0 300]
[  0   0   1 900]
var('x') f1=plot(7/15*x+6/15*x+2/15*x-380,-1000,1000,color="red") f2=plot(6/15*x+4/15*x+5/15*x-500,-1000,1000,color="blue") f3=plot(2/15*x+5/15*x+8/15*x-620,-1000,1000,color="yellow") show (f1+f2+f3,xmin=-3000, xmax=3000, ymin=-3000, ymax=3000) 
       
var('x') f1=plot(7/15*x+6/15*x+2/15*x-380,-1000,1000,color="red") f2=plot(6/15*x+4/15*x+5/15*x-500,-1000,1000,color="blue") #f1.axes_labels(['foo','bar']) show(f1+f2) #f1.show(aspect_ratio=1) 
       
p.save('my_plot.pdf') 
       
Traceback (click to the left of this block for traceback)
...
NameError: name 'p' is not defined
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_3.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("cC5zYXZlKCdteV9wbG90LnBkZicp"),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/tmp/tmpHeh0oy/___code___.py", line 2, in <module>
    exec compile(u"p.save('my_plot.pdf')" + '\n', '', 'single')
  File "", line 1, in <module>
    
NameError: name 'p' is not defined
f(x)=x^2 line([(x,f(x)) for x in range(5)]) 
       
f(x,y)=x^2-y^2 plot([(x,y,f(x,y)) for x in range(5) for y in range(5)]) 
       
var('x,y,z') p1=implicit_plot3d(x-y+z==1, (x,-2,2),(y,-2,2),(z,-2,2),color='red',viewer='tachyon') p2=implicit_plot3d(2*x+3*y+5*z==10, (x,-2,2),(y,-2,2),(z,-2,2),color='blue',viewer='tachyon') p3=implicit_plot3d(x+y-2*z==0, (x,-2,2),(y,-2,2),(z,-2,2),color='orange',viewer='tachyon') show(p2+p1+p3) 
       
x = var('x') y = var('y') show(plot3d(sin(x+y), (x,-2,2), (y,-2,2)), figsize=5, viewer='tachyon') 
       
b = vector([1,2,2]) A = matrix([[1,2,-1],[2,3,1],[1,-1,0]]) x=A.solve_right(b) print x 
       
(13/8, -3/8, -1/8)
(13/8, -3/8, -1/8)
b = vector([10,1,0]) A = matrix([[2,3,5],[1,-1,1],[1,1,-2]]) x=A.solve_right(b) print x 
       
(1, 1, 1)
(1, 1, 1)
var('x,y,z') p1=implicit_plot3d(x+y+z==-1, (x,-2,2),(y,-2,2),(z,-2,2),color='red',viewer='tachyon') p2=implicit_plot3d(x-y+z==1, (x,-2,2),(y,-2,2),(z,-2,2),color='blue',viewer='tachyon') p3=implicit_plot3d(x+z==2, (x,-2,2),(y,-2,2),(z,-2,2),color='orange',viewer='tachyon') show(p2+p1+p3) 
       
b = vector([-1,1,2]) A = matrix([[1,1,1],[1,-1,1],[1,0,1]]) x=A.solve_right(b) print x 
       
Traceback (click to the left of this block for traceback)
...
ValueError: matrix equation has no solutions
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_19.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("YiA9IHZlY3RvcihbLTEsMSwyXSkKQSA9IG1hdHJpeChbWzEsMSwxXSxbMSwtMSwxXSxbMSwwLDFdXSkKeD1BLnNvbHZlX3JpZ2h0KGIpICAKcHJpbnQgeA=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/tmp/tmpeYjBv1/___code___.py", line 5, in <module>
    x=A.solve_right(b)  
  File "matrix2.pyx", line 301, in sage.matrix.matrix2.Matrix.solve_right (sage/matrix/matrix2.c:3838)
  File "matrix2.pyx", line 419, in sage.matrix.matrix2.Matrix._solve_right_general (sage/matrix/matrix2.c:4611)
ValueError: matrix equation has no solutions
b = vector([380,500,620]) A = matrix([[7/15,6/15,2/15],[5/15,5/15,5/15],[3/15,4/15,8/15]]) x=A.solve_right(b) print x 
       
(-3300, 4800, 0)
(-3300, 4800, 0)
B = matrix([[7/15,6/15,2/15,380],[5/15,5/15,5/15,500],[3/15,4/15,8/15,620]]) B.echelon_form() 
       
[    1     0    -4 -3300]
[    0     1     5  4800]
[    0     0     0     0]
[    1     0    -4 -3300]
[    0     1     5  4800]
[    0     0     0     0]
A= matrix([[2,6,6],[2,7,6],[2,7,7]]) A 
       
[2 6 6]
[2 7 6]
[2 7 7]
[2 6 6]
[2 7 6]
[2 7 7]
A.inverse() 
       
[7/2   0  -3]
[ -1   1   0]
[  0  -1   1]
[7/2   0  -3]
[ -1   1   0]
[  0  -1   1]
B= matrix([[1,0,1],[0,1,1],[1,1,0]]) 
       
B.inverse() 
       
[ 1/2 -1/2  1/2]
[-1/2  1/2  1/2]
[ 1/2  1/2 -1/2]
[ 1/2 -1/2  1/2]
[-1/2  1/2  1/2]
[ 1/2  1/2 -1/2]