Degree matrix

In the mathematical field of graph theory, the degree matrix is a diagonal matrix which contains information about the degree of each vertex—that is, the number of edges attached to each vertex. It is used together with the adjacency matrix to construct the Laplacian matrix of a graph.
Definition.
Given a graph formula_1 with formula_2, the degree matrix formula_3 for formula_4 is a formula_5 diagonal matrix defined as
where the degree formula_7 of a vertex counts the number of times an edge terminates at that vertex. In an undirected graph, this means that each loop increases the degree of a vertex by two. In a directed graph, the term "degree" may refer either to indegree (the number of incoming edges at each vertex) or outdegree (the number of outgoing edges at each vertex).
Example.
The following undirected graph has a 6x6 degree matrix with values:
Note than in the case of undirected graphs, an edge that starts and ends in the same node increases the corresponding degree value by 2 (i.e. it is counted twice).
Properties.
The degree matrix of a k-regular graph has a constant diagonal of formula_8.