## Vectors and matrices

A vector in GAP is simply a list of numbers. One can access elements of a list using square brackets as well. A list of (row) vectors is a matrix. GAP knows matrix arithmetic.

```gap> vec:=[1,2,3,4];
[ 1, 2, 3, 4 ]
gap> vec[3]+2;
5
gap> mat:=[[1,2,3,4],[5,6,7,8],[9,10,11,12]];
[ [ 1, 2, 3, 4 ], [ 5, 6, 7, 8 ], [ 9, 10, 11, 12 ] ]
gap> mat*vec;
[ 30, 70, 110 ]
gap> mat:=[[1,2,3],[5,6,7],[9,10,12]];
[ [ 1, 2, 3 ], [ 5, 6, 7 ], [ 9, 10, 12 ] ]
gap> mat^5;
[ [ 289876, 342744, 416603 ], [ 766848, 906704, 1102091 ],
[ 1309817, 1548698, 1882429 ] ]
gap> RankMat(mat);
3
gap> DeterminantMat(mat);
-4
```
The command Display can be used to get a nicer output:
```gap> 3*mat^2-mat;
[ [ 113, 130, 156 ], [ 289, 342, 416 ], [ 492, 584, 711 ] ]
gap> Display(last);
[ [  113,  130,  156 ],
[  289,  342,  416 ],
[  492,  584,  711 ] ]
```
We can also calculate in matrices modulo a number:
```gap> mat:=[[1,2,3],[5,6,7],[9,10,12]]*One(im);
[ [ Z(7)^0, Z(7)^2, Z(7) ], [ Z(7)^5, Z(7)^3, 0*Z(7) ],
[ Z(7)^2, Z(7), Z(7)^5 ] ]
gap> Display(mat);
1 2 3
5 6 .
2 3 5
gap> mat^-1+mat;
[ [ Z(7)^4, Z(7)^4, Z(7)^4 ], [ Z(7)^3, Z(7)^0, Z(7)^5 ],
[ Z(7), Z(7)^0, Z(7)^3 ] ]
```

david joyner 2008-04-20