I have a problem with subgraph in Mathematica 9. In Ver10 the below code works :

dist = 1.1;(*when the distance is grather then dist edge is deleted*) 
a = {0, 1, 2 I}; 
coordReal = {Re@#, Im@#} & /@ a;
planar = DelaunayMesh[coordReal]["AdjacencyMatrix"]; 
   Do[If ABS{[a[[j]]-a[[i]]] > dist, 
      planar[[j, i]] = 0],
GraphPlot[planar, VertexLabeling -> False,   VertexCoordinateRules -> coord]

Is a way to use this method in Mathematica Ver9?


1 Answer 1


It helps to use proper syntax. For example, N is a built-in symbol and cannot be overwritten. Moreover, it is Abs not ABS and all kinds of bracketing have to match. The following seems to work.

dist = 1.1;
a = {0, 1, 2 I};
coordReal = {Re@#, Im@#} & /@ a;
n = Length[a];
planar = DelaunayMesh[coordReal]["AdjacencyMatrix"];
  If[Abs[a[[j]] - a[[i]]] > dist, planar[[j, i]] = 0],
  {i, 1, n}, {j, 1, n}];
GraphPlot[planar, VertexLabeling -> False, VertexCoordinateRules -> coordReal]


In version 9, the issue is that MeshRegion and DelaunayMesh are absent because they were only introduced in version 10.0. The now superseded package "ComputationalGeometry" provides a functionDelaunayTriangulation` that returns the vertex adjacency list of the Delaunay triangulation. From this, the adjacency matrix can be built as follows.

planar = SparseArray[Join @@ Thread /@ DelaunayTriangulation[coordReal] -> 1];

The rest should work. Notice however that GraphPlot has also been updated with version 10; since I am running version 11.3, I cannot test it.

  • $\begingroup$ Thank you for quick answer! $\endgroup$
    – Olaf
    Jan 11, 2019 at 9:58
  • $\begingroup$ You're welcome. $\endgroup$ Jan 11, 2019 at 10:00
  • $\begingroup$ Did you use Normal for output ony or did it make any deeper sense?. Without it works good too. Regards, Olaf. $\endgroup$
    – Olaf
    Jan 11, 2019 at 10:24
  • $\begingroup$ No special purpose. I was expecting that you are more familiar with conventional matrices than with SparseArrays. Whenever you have a graph with $n$ vertices and $m$ edges with $m \ll n^2$, then using a SparseArray for the adjacency matrix is actually preferable because it uses only $n + 2 m$ instead of $n^2$ memory. $\endgroup$ Jan 11, 2019 at 10:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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