Previous Up Next

14.2.5  Getting the parts of a matrix

Accessing rows of a matrix.

The rows of a matrix are the elements of a list, and can be accessed with indices using the postfix […] or the prefix at (see Section 6.1.6). For example:

A:=[[1,2,6],[3,4,8],[1,0,1]]

then:

A[0]

or:

at(A,0)
     

1,2,6
          

To extract a column of a matrix, you can first turn the columns into rows with transpose (see Section 15.1.1), then extract the row as above. For example:

tran(A)[1]

or:

at(tran(A),1)
     

2,4,0
          

Individual elements are simply elements of the rows. For example:

A[0][1]
     
2           

This can be abbreviated by listing the row and column separated by a comma:

A[0,1]

or:

at(A,[0,1])
     
2           

The indexing begins with 0; you can have the indices start with 1 by enclosing them in double brackets.

A[[1,2]]
     
2           

Use a range (see Section 6.5.1) of indices to get submatrices. Some examples:

A[1,0..2]
     

3,4,8
          
A[0..2,1]
     

2,4,0
          
A[0..2,1..2]
     



26
48
01



          
A[0..1,1..2]
     


26
48


          

This gives you another way to extract a full column, by specifying all the rows as an index interval.

A[0..2,1]
     

2,4,0
          

Recall that an index of −1 returns the last element of a list, an index of −2 the second to last element, etc.

A[-1]
     

1,0,1
          
A[1,-1]
     
8           
Extracting rows or columns of a matrix (Maple compatibility).

The row (resp. col) command extracts one or several rows (resp. columns) of a matrix.

Examples

row([[1,2,3],[4,5,6],[7,8,9]],1)
     

4,5,6
          
row([[1,2,3],[4,5,6],[7,8,9]],0..1)
     

1,2,3
,
4,5,6
          
col([[1,2,3],[4,5,6],[7,8,9]],1)
     

2,5,8
          
col([[1,2,3],[4,5,6],[7,8,9]],0..1)
     

1,4,7
,
2,5,8
          
Extracting a sub-matrix of a matrix (TI compatibility).

The subMat command finds submatrices of a matrix.

Examples

A:=[[3,4,5],[1,2,6]]
     


345
126


          
subMat(A,0,1,1,2)
     


45
26


          
subMat(A,0,1,1,1)
     


4
2


          
subMat(A,1)

or:

subMat(A,1,0)

or:

subMat(A,1,0,1)

or:

subMat(A,1,0,1,2)
     

126

          

Previous Up Next