Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm using Mathematica 9 and want to delete a single vertex and all associated edges on a graph but can't seem to get the function VertexDelete function to work. My code is below. I declare a graph "newgraph" and GraphPlot works fine but when I call VertexDelete I get the following error:

VertexDelete::graph: A graph object is expected at position 1 in VertexDelete[{0->1,0->3,0->6,0->11,0->12,0->14,0->30,0->56,0->75,0->76,0->78,0->86,0->94,0->112,0->120,0->222,0->232,0->248,0->504,0->960,1->7,1->12,1->14,1->15,1->31,1->57,1->62,1->75,1->76,1->78,1->79,1->86,1->94,1->95,1->112,1->116,1->120,1->121,1->124},79]. >>

My code is:

newgraph = {0 -> 1, 0 -> 3, 0 -> 6, 0 -> 11, 0 -> 12, 0 -> 14, 
  0 -> 30, 0 -> 56, 0 -> 75, 0 -> 76, 0 -> 78, 0 -> 86, 0 -> 94, 
  0 -> 112, 0 -> 120, 0 -> 222, 0 -> 232, 0 -> 248, 0 -> 504, 
  0 -> 960, 1 -> 7, 1 -> 12, 1 -> 14, 1 -> 15, 1 -> 31, 1 -> 57, 
  1 -> 62, 1 -> 75, 1 -> 76, 1 -> 78, 1 -> 79, 1 -> 86, 1 -> 94, 
  1 -> 95, 1 -> 112, 1 -> 116, 1 -> 120, 1 -> 121, 1 -> 124}

GraphPlot[newgraph, VertexLabeling -> True]

VertexDelete[newgraph, 79]

As far as I am aware, I am indeed passing a graph as an argument! Someone please help me!

Many thanks.

share|improve this question
1  
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) Read the FAQs! 3) When you see good Q&A, 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, remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign` –  Vitaliy Kaurov Feb 21 '13 at 15:03

1 Answer 1

VertexDelete works on Graph objects, not on List. So build graph and delete vertex from there:

g = Graph[newgraph];
VertexDelete[g, 79]

I recommend putting vertex labels on to see it really works - like here:

cg = CompleteGraph[5, VertexLabels -> "Name"]
VertexDelete[cg, 2]

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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