---
title: "Matrices and Vector Spaces Associated with a Graph or Digraph"
canonical: "https://docs.magma-maths.org/v2.30-1/Combinatorics/Graphs/matrix-vector-space.html"
source: "https://docs.magma-maths.org/v2.30-1/Combinatorics/Graphs/matrix-vector-space.md"
part: "Combinatorics"
chapter: "Graphs"
breadcrumbs:
  - {"title": "Magma Handbook", "source": "https://docs.magma-maths.org/v2.30-1/index.md"}
  - {"title": "Combinatorics", "source": "https://docs.magma-maths.org/v2.30-1/Combinatorics/index-combinatorics.md"}
  - {"title": "Graphs", "source": "https://docs.magma-maths.org/v2.30-1/Combinatorics/Graphs/index-graphs.md"}
prev: {"title": "Maximum Flow, Minimum Cut, and Shortest Paths", "source": "https://docs.magma-maths.org/v2.30-1/Combinatorics/Graphs/flow.md"}
next: {"title": "Spanning Trees of a Graph or Digraph", "source": "https://docs.magma-maths.org/v2.30-1/Combinatorics/Graphs/spanning-tree.md"}
intrinsics:
  - {"name": "AdjacencyMatrix", "signature": "AdjacencyMatrix(G): Grph -> AlgMatElt"}
  - {"name": "DistanceMatrix", "signature": "DistanceMatrix(G): Grph -> AlgMatElt"}
  - {"name": "IncidenceMatrix", "signature": "IncidenceMatrix(G): Grph -> ModHomElt"}
  - {"name": "IntersectionMatrix", "signature": "IntersectionMatrix(G, P): GrphUnd, { { GrphVert}} -> AlgMatElt"}
  - {"name": "IntersectionMatrix", "signature": "IntersectionMatrix(G, P): GrphUnd, { { RngIntElt}} -> AlgMatElt"}
---

<a id="matrix-vector-space"></a>
<a id="graph-sec-matrix"></a>
# Matrices and Vector Spaces Associated with a Graph or Digraph

<a id="function-adjacencymatrix-grph"></a>
## `AdjacencyMatrix(G): Grph -> AlgMatElt`

Returns the adjacency matrix for the $(p, q)$ graph $G$ as an element of the matrix ring $M_p(Z)$.

<a id="function-distancematrix-grph"></a>
## `DistanceMatrix(G): Grph -> AlgMatElt`

Returns the distance matrix $A$ for the $(p, q)$ graph $G$ as an element of the matrix ring $M_p(Z)$. The $(i, j)$-th entry of $A$ gives the distance between vertices $v_i$ and $v_j$ of $G$.

<a id="function-incidencematrix-grph"></a>
## `IncidenceMatrix(G): Grph -> ModHomElt`

Returns the incidence matrix $M$ for the $(p, q)$ graph $G$ as an element of the matrix bimodule $M^{p \times q}(Z)$.

If $G$ is a graph, then entry $(i, j)$ of M is $1$ if the vertex $v_i$ of $G$ lies on the edge $e_j$ of $G$. Otherwise entry $(i, j)$ is zero.

If $G$ is a digraph, entry $(i, j)$ of M is $1$ if vertex $v_i$ is the initial vertex of the edge $e_j$, and $-1$ if $v_i$ is the final vertex of the edge $e_j$. Otherwise entry $(i, j)$ is zero. If $e_j$ is a loop, then entry $(i, j)$ may be either $1$ or $-1$.

<a id="function-intersectionmatrix-grphund-grphvert"></a>
## `IntersectionMatrix(G, P): GrphUnd, { { GrphVert}} -> AlgMatElt`

<a id="function-intersectionmatrix-grphund-rngintelt"></a>
## `IntersectionMatrix(G, P): GrphUnd, { { RngIntElt}} -> AlgMatElt`

Given an ordered equitable partition $P = P_1 \cup P_2 \cup \ldots \cup P_r$ of the vertex-set of the graph $G$, return the intersection matrix $T$ for the partition. Thus, entry $T[i, j]$ is the number of vertices of the set $P_j$ that are adjacent to a vertex of the set $P_i$.
