Matrix Operations

In this page, we will see how to perform basic manipulations with matrices.

Matrix Entries, Rows, Columns & Basic Operations

Given a matrix $M$, we can access its entries as follows:

> M = matrix{{1,2,3}, {4,5,6}, {7,8,9}} -- constructs a matrix M with rows given by {1,2,3}, {4,5,6} and {7,8,9}
> M_(0,1) -- this will output the number 2
> M_{0,1} -- accesses the columns 0 and 1 of the matrix
> M^{1,2} -- accesses the rows 1 and 2 of the matrix M

To multiply two matrices, we can use the * operator:

> M = matrix{{1,2,3}, {4,5,6}, {7,8,9}}
> N = matrix{{1,1,0}, {0,1,0}, {0,0,1}}
> M * N -- outputs the prodcut of M and N

Inverse, Transpose and Adjugate

When taking the inverse, first make sure that you are working over the correct base ring, as Macaulay2 will compute the inverse in the same base ring as the matrix was defined on. Thus, if you want the inverse over the field of fractions of a domain, you should first convert the matrix to a matrix over the field of fractions.

Having done the above, you can compute the inverse of a matrix as follows:

> M = matrix{{1,2,3}, {4,5,6}, {7,8,9}}
> inverse M
Previous
Next