# Symmetric Matrices

Undirected graphs must have symmetric adjacency matrices.

 In[1]:= Xundir = {GridGraph[{8, 8}], KnightTourGraph[8, 8], WheelGraph[20], CirculantGraph[12, {2, 4}], HypercubeGraph[6], PetersenGraph[10, 8]};
 In[2]:= XGraphicsGrid[Partition[undir, 3], ImageSize -> Medium]
 Out[2]=

Verify the symmetry.

 In[3]:= XSymmetricMatrixQ /@ AdjacencyMatrix /@ undir
 Out[3]=

Directed graphs typically have non-symmetric adjacency matrices.

 In[4]:= Xdir = {CompleteGraph[3, DirectedEdges -> True], KaryTree[7, DirectedEdges -> True], GridGraph[{5, 5}, DirectedEdges -> True], StarGraph[10, DirectedEdges -> True], WheelGraph[8, DirectedEdges -> True], ButterflyGraph[2, DirectedEdges -> True]};
 In[5]:= XGraphicsGrid[ Partition[SetProperty[#, EdgeStyle -> Arrowheads[Medium]] & /@ dir, 3], ImageSize -> Medium]
 Out[5]=

In the above examples, the complete graph has a symmetric adjacency matrix, but all the other graphs have a non-symmetric adjacency matrix.

 In[6]:= XSymmetricMatrixQ /@ AdjacencyMatrix /@ dir
 Out[6]=

Visualize the adjacency matrices for both directed and undirected graphs.

 In[7]:= XGraphicsGrid[ Partition[ MatrixPlot[AdjacencyMatrix[#], FrameTicks -> None] & /@ Join[undir, dir], 4], ImageSize -> Medium]
 Out[7]=

## Mathematica

Questions? Comments? Contact a Wolfram expert »