Macaulay2 » Documentation
Packages » EdgeIdeals :: adjacencyMatrix
next | previous | forward | backward | up | index | toc

# adjacencyMatrix -- returns the adjacency Matrix of a graph

- Usage:
    `M = adjacencyMatrix G`
- Inputs:
  - G, a graph,
- Outputs:
  - M, a matrix, the adjacency matrix of the graph

## Description

This function returns the adjacency matrix of the given graph G. The (i,j)^{th} position of the matrix is 1 if there is an edge between the i^{th} vertex and j^{th} vertex, and 0 otherwise. The rows and columns are indexed by the variables of the ring and use the ordering of the variables for determining the order of the rows and columns.

    i1 : S = QQ[a..f];

    i2 : G = graph {a*b,a*c,b*c,c*d,d*e,e*f,f*a,a*d}

    o2 = Graph{"edges" => {{a, b}, {a, c}, {b, c}, {a, d}, {c, d}, {d, e}, {a, f}, {e, f}}}
               "ring" => S
               "vertices" => {a, b, c, d, e, f}

    o2 : Graph

    i3 : t = adjacencyMatrix G

    o3 = | 0 1 1 1 0 1 |
         | 1 0 1 0 0 0 |
         | 1 1 0 1 0 0 |
         | 1 0 1 0 1 0 |
         | 0 0 0 1 0 1 |
         | 1 0 0 0 1 0 |

                  6       6
    o3 : Matrix ZZ  <-- ZZ

    i4 : T = QQ[f,e,d,c,b,a];

    i5 : G = graph {a*b,a*c,b*c,c*d,d*e,e*f,f*a,a*d}

    o5 = Graph{"edges" => {{f, e}, {e, d}, {d, c}, {c, b}, {f, a}, {d, a}, {c, a}, {b, a}}}
               "ring" => T
               "vertices" => {f, e, d, c, b, a}

    o5 : Graph

    i6 : t = adjacencyMatrix G -- although the same graph, matrix is different since variables have different ordering

    o6 = | 0 1 0 0 0 1 |
         | 1 0 1 0 0 0 |
         | 0 1 0 1 0 1 |
         | 0 0 1 0 1 1 |
         | 0 0 0 1 0 1 |
         | 1 0 1 1 1 0 |

                  6       6
    o6 : Matrix ZZ  <-- ZZ

## See also

- incidenceMatrix -- returns the incidence matrix of a hypergraph
- vertices(HyperGraph) -- gets the vertices of a (hyper)graph

## Ways to use adjacencyMatrix:

- `adjacencyMatrix(Graph)`

## For the programmer

The object adjacencyMatrix is a method function.

The source of this document is in /build/macaulay2-88fgJW/macaulay2-1.25.11+ds/M2/Macaulay2/packages/EdgeIdeals.m2:1744:0.