Search code examples
mathmatrixwolfram-mathematicagraph-theoryadjacency-matrix

Johnson graphs in Mathematica


I have a question about defining Johnson graph in Mathematica software. I find this in Stackoverflow and It works:

johnsonmatrix[n_, k_] := 
 Module[{s = Select[Subsets[Range[n]], Length[#] == k &]}, {s, 
    MatrixForm[
    Table[If[Length[Intersection[s[[i]], s[[j]]]] == k - 1, 1, 0], {i,
       Length[s]}, {j, Length[s]}]]}]

But I can't use its matrix. How can I only have the adjacency matrix of this roll? In fact, I want to define Johnson graph in Mathematica software and then find some properties of this graph like its spectrum. I appreciate if anybody can help me.


Solution

  • Unless you know enough to understand the implications, most of the time using any of the *Form functions, like MatrixForm and DisplayForm and etc, etc, etc, are only to transform something that can be used for calculations into something pretty to look at, but which cannot be used for any further calculations.

    Try getting rid of the MatrixForm and see if this will give you some ideas where to go with this.

    johnsonmatrix[n_,k_]:=Module[{s=Select[Subsets[Range[n]],Length[#]==k&]},
     {s,
      matrix=Table[If[Length[Intersection[s[[i]],s[[j]]]]==k-1,1,0],{i,Length[s]},{j,Length[s]}],
      adjacencygraph=AdjacencyGraph[matrix],
      adjacencymatrix=AdjacencyMatrix[adjacencygraph];Normal[adjacencymatrix],
      eigenvalues=Eigenvalues[adjacencymatrix],
      spectrum=Max@@Abs[eigenvalues]
    }]
    johnsonmatrix[5,3]
    

    Please check every detail of this very carefully to try to make certain that I have made no mistakes.