4
$\begingroup$

how can i make adjacency matrix of sierprinski graphs? enter image description here

$\endgroup$
  • $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, [by clicking the checkmark sign](tinyurl.com/4srwe26 $\endgroup$ – Dunlop Jan 7 at 5:38
9
$\begingroup$
ClearAll[meshF, edgesF, verticesF, coordsF, meshGraph]

meshF = DiscretizeGraphics @ Show[CantorMesh[#, 2], 
     RegionBoundary[RegionDifference[Rectangle[], 
        CantorMesh[#, 2]]] & /@ Range[#]] &;

verticesF = MeshCells[meshF[#], 0][[All, 1]] &;

edgesF = UndirectedEdge @@@ MeshCells[meshF[#], 1][[All, 1]] &;

coordsF = MeshCoordinates[meshF[#]] &;

meshGraph = Graph[verticesF@#, edgesF@#, VertexCoordinates -> coordsF[#], ##2] &;

Examples:

Row[meshGraph[#, ImageSize -> Small] & /@ Range[0, 2], Spacer[20]]

enter image description here

Row[meshGraph[#, ImageSize -> 1 -> (# + 1) 100, 
    VertexLabels -> Placed["Name", Center], 
    VertexSize -> (1 + #)/5] & /@ Range[0, 2], Spacer[20]]

enter image description here

Adjacency matrices:

Row[ArrayPlot[AdjacencyMatrix[meshGraph@#], Mesh -> All, 
    ImageSize -> 300] & /@ Range[0, 2], Spacer[10]]

enter image description here

Update: An alternative approach successively re-scaling a Rectangle using TransformedRegion and ScalingTransform:

ClearAll[subDivide]
subDivide = # /. c_Polygon :> {c, 
      TransformedRegion[c, ScalingTransform[{1, 1}/3, #]] & /@ First[c]} &;

Examples:

Graphics[{FaceForm[], EdgeForm[{Thin, Black}], 
  Nest[subDivide, Polygon[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}], 4]}]

enter image description here

polygons = Cases[
  Graphics[{FaceForm[], EdgeForm[{Thin, Black}], 
    Nest[subDivide, Polygon[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}], 5]}],
  _Polygon, All]; 

Graphics[{RandomColor[], #} & /@ polygons,  ImageSize -> Large]

enter image description here

$\endgroup$
  • $\begingroup$ if graph is given, how can i find adjacency matrix? $\endgroup$ – MohitJames Jan 7 at 7:12
  • 3
    $\begingroup$ @MohitJames, you can use AdjacencyMatrix[g] if g is a Graph object. $\endgroup$ – kglr Jan 7 at 7:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.