Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168731
Image: ubuntu2004
5.1. a(1,5,3)a(1,5,3) b(2,-2,0)$.
a=vector([-1,5,3]);a
(-1, 5, 3)
b=vector([2,-2,0]);b
(2, -2, 0)
5.2. aa bb :
aLaTeX\LaTeXb$;
a+b
(1, 3, 3)
LaTeX\LaTeX3a-2b$;
3*a-2*b
(-7, 19, 9)
aLaTeX\LaTeXb$;
a*b
-12
aLaTeX\LaTeXb$;
a.cross_product(b)
(6, 6, -8)
aLaTeX\LaTeXb$.
abs(a)
sqrt(35)
abs(b)
2*sqrt(2)
5.3. M=(123456) M=\left(\begin{array}{cc} 1 & 2\\ 3 & 4\\ 5 & 6 \end{array} \right)
M=matrix([[1,2],[3,4],[5,6]]);M
[1 2] [3 4] [5 6]
5.4. :
;
IM=identity_matrix(4);IM
[1 0 0 0] [0 1 0 0] [0 0 1 0] [0 0 0 1]
3 \times 5$;
ZM=zero_matrix(3,5);ZM
[0 0 0 0 0] [0 0 0 0 0] [0 0 0 0 0]
-7LaTeX\LaTeX3$;
DM=diagonal_matrix([-7,3]);DM
[-7 0] [ 0 3]
.
RM=random_matrix(ZZ,5,3);RM
[ 1 -2 1] [ -3 1 -1] [ -2 -1 -15] [ 1 3 -1] [ 1 2 -1]
5.5. :
3*RM
[ 3 -6 3] [ -9 3 -3] [ -6 -3 -45] [ 3 9 -3] [ 3 6 -3]
aa;
M*a
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/notebook/sage_notebook/worksheets/admin/12/code/85.py", line 6, in <module> exec compile(ur'M*a' + '\n', '', 'single') File "/usr/local/sage/local/lib/python2.5/site-packages/sympy/plotting/", line 1, in <module> File "element.pyx", line 2122, in sage.structure.element.Matrix.__mul__ File "coerce.pyx", line 295, in sage.structure.coerce.CoercionModel_cache_maps.bin_op_c TypeError: unsupported operand parent(s) for '*': 'Full MatrixSpace of 3 by 2 dense matrices over Integer Ring' and 'Ambient free module of rank 3 over the principal ideal domain Integer Ring'
(3;4)(-3;4);
M*vector([-3,4])
(5, 7, 9)
;
M*IM
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/notebook/sage_notebook/worksheets/admin/12/code/87.py", line 6, in <module> exec compile(ur'M*IM' + '\n', '', 'single') File "/usr/local/sage/local/lib/python2.5/site-packages/sympy/plotting/", line 1, in <module> File "element.pyx", line 2122, in sage.structure.element.Matrix.__mul__ File "coerce.pyx", line 295, in sage.structure.coerce.CoercionModel_cache_maps.bin_op_c TypeError: unsupported operand parent(s) for '*': 'Full MatrixSpace of 3 by 2 dense matrices over Integer Ring' and 'Full MatrixSpace of 4 by 4 dense matrices over Integer Ring'
.
M*DM
[ -7 6] [-21 12] [-35 18]
5.6.
A=random_matrix(ZZ,4,4);A
[ -1 -1 1 -31] [ -1 -1 -14 7] [ 1 1 -17 1] [ 4 -1 21 -2]
det(A)
5290
5.7. .
B=random_matrix(QQ,2,4);B
[ 1 -2 0 1] [ 0 2 1 -2]
B.transpose()
[ 1 0] [-2 2] [ 0 1] [ 1 -2]
5.8. (1111222233112517)   \left(\begin{array}{cccc} 1 & 1 & 1 & 1\\ 2 & 2 & 2 & 2\\ 3 & -3 & -1 & 1\\ 2 & -5 & 1 & 7 \end{array} \right)\;   (1123013425140021)  \; \left(\begin{array}{cccc} 1 & -1 & 2 & 3\\ 0 & 1 & 3 & 4\\ -2 & 5 & 1 & -4\\ 0 & 0 & 2 & -1 \end{array} \right)\; , .
C=matrix([[1,1,1,1],[2,2,2,2],[3,-3,-1,1],[2,-5,1,7]]);C
[ 1 1 1 1] [ 2 2 2 2] [ 3 -3 -1 1] [ 2 -5 1 7]
det(C)
0
C^-1
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/notebook/sage_notebook/worksheets/admin/12/code/95.py", line 6, in <module> exec compile(ur'C**-Integer(1)' + '\n', '', 'single') File "/usr/local/sage/local/lib/python2.5/site-packages/sympy/plotting/", line 1, in <module> File "matrix0.pyx", line 2211, in sage.matrix.matrix0.Matrix.__pow__ File "element.pyx", line 1459, in sage.structure.element.RingElement.__pow__ File "element.pyx", line 3026, in sage.structure.element.generic_power_c File "matrix0.pyx", line 2168, in sage.matrix.matrix0.Matrix.__invert__ File "matrix_rational_dense.pyx", line 498, in sage.matrix.matrix_rational_dense.Matrix_rational_dense.__invert__ File "matrix_rational_dense.pyx", line 582, in sage.matrix.matrix_rational_dense.Matrix_rational_dense.invert File "matrix_integer_dense.pyx", line 2502, in sage.matrix.matrix_integer_dense.Matrix_integer_dense._invert_iml ZeroDivisionError: input matrix must be nonsingular
D=matrix([[1,-1,2,3],[0,1,3,4],[-2,5,1,-4],[0,0,2,-1]]);D
[ 1 -1 2 3] [ 0 1 3 4] [-2 5 1 -4] [ 0 0 2 -1]
det(D)
24
D.inverse()
[ 31/12 -11/8 19/24 -11/12] [ 11/12 -3/8 11/24 -7/12] [ -1/12 1/8 -1/24 5/12] [ -1/6 1/4 -1/12 -1/6]