New in Wolfram
Mathematica
8: Graph & Network Analysis
◄
previous
|
next
►
Application Areas
Convert to Matrix Representations
Mathematica
8 supports all common matrix representations of graphs.
In[1]:=
X
g = Graph[{1 \[UndirectedEdge] 2, 1 \[UndirectedEdge] 3, 2 \[UndirectedEdge] 3, 2 \[UndirectedEdge] 4, 3 \[UndirectedEdge] 4}, ImageSize -> 100];
In[2]:=
X
h = DirectedGraph[CompleteGraph[4, ImageSize -> 100], "Acyclic"];
In[3]:=
X
k = PetersenGraph[3, 2, ImageSize -> 100];
In[4]:=
X
graphs = {g, h, k};
In[5]:=
X
mat = {AdjacencyMatrix, IncidenceMatrix, KirchhoffMatrix};
In[6]:=
X
Style[Grid[ Join[{{"Graph", "Adjacency Matrix", "Incidence Matrix", "Kirchhoff Matrix"}}, Thread[Prepend[ Outer[MatrixForm[#1[#2], TableSpacing -> {.5, .5}, TableAlignments -> Right] &, mat, graphs], graphs]] ], Background -> {None, {Hue[.25, .15, .9], GrayLevel[.9], GrayLevel[.9], GrayLevel[.9]}}, FrameStyle -> Directive[Thick, White], Dividers -> All, Spacings -> {1, 2}], FontFamily -> "Verdana"]
Out[6]=