Home Online Manual
Top
Back: matrix type cast
Forward: matrix related functions
FastBack: map
FastForward: module
Up: matrix
Top: Singular Manual
Contents: Table of Contents
Index: Index
About: About this document

4.12.4 matrix operations

+
addition with matrix or poly; the polynomial is converted into a diagonal matrix

-
negation or subtraction with matrix or poly (the first operand is expected to be a matrix); the polynomial is converted into a diagonal matrix

*
multiplication with matrix or poly; the polynomial is converted into a diagonal matrix

/
division by poly

==, <>, !=
comparators

matrix_expression [ int_expression, int_expression ]
is a matrix entry, where the first index indicates the row and the second the column


Example:

 
  ring r=32003,x,dp;
  matrix A[3][3] = 1,3,2,5,0,3,2,4,5; // define a matrix
  print(A); // nice printing of small matrices
==> 1,3,2,
==> 5,0,3,
==> 2,4,5 
  A[2,3];   // matrix entry
==> 3
  A[2,3] = A[2,3] + 1; // change entry
  A[2,1..3] = 1,2,3;   // change 2nd row
  print(A);
==> 1,3,2,
==> 1,2,3,
==> 2,4,5 
  matrix E[3][3]; E = E + 1;  // the unit matrix
  matrix B =x*E - A;
  print(B);
==> x-1,-3, -2,
==> -1, x-2,-3,
==> -2, -4, x-5
  // the same (but x-A does not work):
  B = -A+x;
  print(B);
==> x-1,-3, -2,
==> -1, x-2,-3,
==> -2, -4, x-5
  det(B);        // the characteristic polynomial of A
==> x3-8x2-2x-1
  A*A*A - 8 * A*A - 2*A == E;  // Cayley-Hamilton
==> 1
  vector v =[x,-1,x2];
  A*v; // multiplication of matrix and vector
==> _[1,1]=2x2+x-3
==> _[2,1]=3x2+x-2
==> _[3,1]=5x2+2x-4
  matrix m[2][2]=1,2,3;
  print(m-transpose(m));
==> 0,-1,
==> 1,0