Home page for accesible maths LAB100

Style control - access keys in brackets

Font (2 3) - + Letter spacing (4 5) - + Word spacing (6 7) - + Line spacing (8 9) - +

2 Further Subsetting

As well as extracting a single number from a matrix, the square brackets can also be used to extract vectors. In this case we only need to specify one number either before or after the comma depending on whether we wish to extract a row or column respectively. In general, to extract the mth row for matrix F we would execute:

F[ m, ]

Alternatively we can extract the nth column from matrix F by:

F[ , n ]

Try the following examples using the matrices that you created earlier in the workshop and note whether the command extracted a row or a column to create the vector.

A[ 2, ]

B[ , 3 ]

C[ 1, ]

C[ , 2 ]

D[ , 1 ]

E[ 3, ]

In addition to extracting vectors, we can use negative subsetting extract everything from the matrix excluding the specified row or column. For example, reporting matrix C without the third row can be obtained by executing:

C[ -3, ]

Or, to report matrix A without the first column can be obtained by executing:

A[ , -1 ]

Finally, if we supply the function diag with a square matrix then it will extract the diagonal elements

diag(H)