previous  next
3.7.1. Introduction to Matrices
An m x n matrix is represented in CoCoA by the list of its rows
 
      Mat(R_1,...,R_m)

where each R_i is of type LIST and has length n.  A matrix has type
MAT.  The (A,B)-th entry of a matrix M is given by M[A][B] or M[A,B].

Example

Use R ::= Q[x,y,z];
M := Mat([[x,y,xy^2],[y,z^2,2+x]]);
M;
Mat[
  [x, y, xy^2],
  [y, z^2, x + 2]
]
-------------------------------
M[1][3];
xy^2
-------------------------------
M[1,3];
xy^2
-------------------------------

The following operations are defined as one would expect for matrices

  M^A, +M, -N, M+N, M-N, M*N, F*M, M*F

where M,N are matrices, A is a non-negative integer, and F is a
polynomial or rational function, with the obvious restrictions on the
dimensions of the matrices involved.

Example

Use R ::= Q[x,y];
N := Mat([[1,2],[3,4]]);
N^2;
Mat[
  [7, 10],
  [15, 22]
]
-------------------------------
x/y * N;
Mat[
  [x/y, 2x/y],
  [3x/y, 4x/y]
]
-------------------------------
N + Mat([[x,x],[y,y]]);
Mat[
  [x + 1, x + 2],
  [y + 3, y + 4]
]
-------------------------------