[back] [prev] [next] [index] [root]

 


MatElt

Returns or modifies an matrix entry or row.

Syntax:

a := MatElt(M, row, col);
a := M[row][col];
M[row][col] := a;
r := M[row];
M[row] := L;

element of the ring the matrix entries come from
  a  
matrix
  M  
small integer
  row  
small integer
  col  
an object of the type "KANT matrow"
  r  
either a list, a "KANT matrix", or a "KANT matrow"
  L  

Description:

The first two syntax variants are equivalent and return the ( row, col)-th entry of the matrix M.\smallskip The third variant sets a single entry of the matrix. The object must be convertible to an element of the ring over which the matrix is defined. The fourth syntax retrieves a matrix row. This is an object of the type "KANT matrow". This object can be converted to a proper matrix (with only one row) with a call of IsMat. It can also be used as a row for another matrix. The fifth syntax sets a row of the matrix. For this purpose the matrix is converted into a list of rows (of the type "KANT matrix"). Then the row-th entry of this list is either replaced by of set to the right hand side of the assignment. Now M is still a list a should be converted to a matrix with a call of IsMat. IsMat also determines a ring all entries of the matrix belong to. So by setting a new row or modifying an existing one the matrix might change its ring.


Example:

Get certain entries of the matrix \left(\begin{array}{cccc} 3 & 7 & 10 & 2 90 & 101 & 87 & 2 12 & 34 & 2 & 0 20 & 25 & 40 & 1 \end{array}right) and modify them.

kash> M := Mat(Z,[[3,7,10,2],[90,101,87,2],[12,34,2,0],[20,25,40,1]]);
[  3   7  10   2]
[ 90 101  87   2]
[ 12  34   2   0]
[ 20  25  40   1]
kash> MatElt(M,1,1);
3
kash> M[2][2];
101
kash> r:=M[4];
[20 25 40  1]
kash> TYPE(r);
"KANT matrow"
kash> IsMat(r);
true
kash> r;
[20 25 40  1]
kash> TYPE(r);
"KANT matrix"
kash> M[4][4]:=22;;M;
[  3   7  10   2]
[ 90 101  87   2]
[ 12  34   2   0]
[ 20  25  40  22]
kash> M[3]:=[-1,2,-1,4];;M;
[ [ 3  7 10  2], [ 90 101  87   2], [ -1, 2, -1, 4 ], [20 25 40 22] ]
kash> IsMat(M);
true
kash> M;
> [  3   7  10   2]
[ 90 101  87   2]
[ -1   2  -1   4]
[ 20  25  40  22]


<- back[back] [prev] [next] [index] [root]