Chapter 8. Matrices in GEL

8.1. Matrix support

To enter matrixes use one of the following two syntaxes. You can either enter the matrix separating values by commas and rows by semicolons, or separating values by tabs (not usually easily possible on the console, only in files) and rows by returns, or any combination of the two. So to enter a 3x3 matrix of numbers 1-9 you could do

[1,2,3;4,5,6;7,8,9]
or
[1 2 3
 4 5 6
 7 8 9]
or
[1, 2, 3
 4, 5, 6
 7, 8, 9]
Do not use both ';' and return at once on the same line though. Also do not mix tabs and commas. It is just safest to use commas as separators.

You can also use the matrix expansion functionality to enter matricies. For example you can do:

a = [ 1, 2, 3
      4, 5, 6
      7, 8, 9]
b = [ a,  10
      11, 12]
and you should get
[1  2  3  10
 4  5  6  10
 7  8  9  10
 11 11 11 12]
similiarly you can build matricies out of vectors and other stuff like that.

Another thing is that non-specified spots are initialized to 0, so

[1, 2, 3
 4, 5
 6]
will end up being

[1 2 3
 4 5 0
 6 0 0]

Note

Be careful about using whitespace and returns for expressions inside the [ ] brackets, as they have a slightly different meaning and could mess you up.