up previous next
matrix    --    convert a list into a matrix


Syntax
matrix(LofL: LIST): MAT
matrix(R: RING, LofL: LIST): MAT
matrix(R: RING, M: MAT): MAT

Description
These functions construct a matrix. The 2nd and 3rd forms produce a matrix over the specified ring R (or error if the entries in LofL or M cannot be mapped into R).

In the first form, where the ring is not specified, CoCoA "guesses" the ring: if all elements of LofL are INT or RAT the resulting matrix is in QQ (otherwise it picks the biggest ring from the given elements and uses that).

The third form is equivalent to CanonicalHom(RingOf(M),R)(M) (See CanonicalHom ).

LofL must be a rectangularLIST of LIST of RINGELEMs or INTs or RATs.

Example
/**/  L := [[1,2],[3,4]];
/**/  mat(L);
matrix(QQ,
 [[1, 2],
  [3, 4]])
/**/  mat(ZZ,L);
matrix(ZZ,
 [[1, 2],
  [3, 4]])

/**/  P ::= QQ[x,y];
/**/  M := mat(P,L); print M;
matrix( /*RingWithID(3, "QQ[x,y]")*/
 [[1, 2],
  [3, 4]])
/**/  RingOf(M);
RingWithID(3, "QQ[x,y]")

/**/ M := IdentityMat(ZZ,2);
/**/ matrix(QQ, M); // promotion mapping: ZZ to QQ
matrix(QQ,
 [[1, 0],
  [0, 1]])

See Also