Math 455  •  1 May 2009

Adjacency matrix & walks

Copyright © 2009 by Murray Eisenberg.  All rights reserved.

Needs["Combinatorica`"]

g=FromOrderedPairs[{{1,3},{1,4},{2,3},{3,4}},Type->Undirected]

ShowGraph[g,VertexLabel->Characters["abcd"],BaseStyle->18]

a=ToAdjacencyMatrix[g];
MatrixForm[a]

(({{0, 0, 1, 1}, {0, 0, 1, 0}, {1, 1, 0, 1}, {1, 0, 1, 0}})).(({{0, 0, 1, 1}, {0, 0, 1, 0}, {1, 1, 0, 1}, {1, 0, 1, 0}}))

a2=a.a; (* or: MatrixPower[a,2] *)
a2//MatrixForm

a3=a2.a;(* or: MatrixPower[a,3] *)
a3//MatrixForm

a4=a3.a;(* or: MatrixPower[a,4] *)
                      (* or: MatrixPower[a2,2] *)
a4//MatrixForm