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've unsuccessfully tried many ways of converting polygon points into a graph using Mathematica 7, and I am frustrated. I looked at this post, but it doesn't work:

Needs["Combinatorica`"];
crds = {{1, 10}, {2, 4}, {10, 5}, {20, 10}};
vertices = Range[Length[crds]];
edges = Thread[vertices \[DirectedEdge] RotateLeft[vertices]];

Graph[vertices, edges]

produces errors:

Syntax::sntxf: "\!\(\*StyleBox[\"\\\"\\\\\\\"\\\"\", \"MT\"]\)\!\(\*StyleBox[\!
\(vertices\), \"MT\"]\)\!\(\*StyleBox[\"\\\"\\\\\\\" cannot be followed by \\\\\\\"
\\\"\", \"MT\"]\)\!\(\*StyleBox[\!\(\(\(\\[ DirectedEdge]\)\) \(\(RotateLeft[vertices]
\)\)\), \"MT\"]\)\!\(\*StyleBox[\"\\\"\\\\\\\".\\\"\", \"MT\"]\)\!\(\*StyleBox[\!
\(\"\"\), \"MT\"]\)"

Syntax::tsntxi: "\!\(\*StyleBox[\"\\\"\\\\\\\"\\\"\", \"MT\"]\)\!\(\*StyleBox[\!\(\\[ 
DirectedEdge]\), \"MT\"]\)\!\(\*StyleBox[\"\\\"\\\\\\\" is incomplete; more input is 
needed.\\\"\", \"MT\"]\)\!\(\*StyleBox[\!\(\"\"\), \"MT\"]\)"

Syntax::sntxi: Incomplete expression; more input is needed.

Any ideas?

share|improve this question
    
The syntax of Graph in Combinatorica is Graph[e, v, opts], not Graph[v, e] as with the new built-in Graph. –  billisphere May 22 '13 at 20:09
add comment

2 Answers

up vote 5 down vote accepted

With Combinatorica, you should usually use MakeGraph rather than Graph directly. Here are some expressions that create the graph you want and which can be easily adapted for use with any graph that you've defined appropriate vertices and edges symbols for:

Needs["Combinatorica`"]
crds = {{1, 10}, {2, 4}, {10, 5}, {20, 10}};
vertices = Range[Length[crds]];
edges = Thread[vertices -> RotateLeft[vertices]];
g = MakeGraph[vertices, MemberQ[edges, #1 -> #2] &]
ShowGraph@g
share|improve this answer
    
same errors as above –  jnthn May 22 '13 at 20:36
    
I changed [DirectedEdges] to -> and now it works! ty. I'll edit your answer and accept. Thanks much. –  jnthn May 22 '13 at 20:47
    
@jnthn: Interesting, I think I missed the errors because I was working in 9.0.1. My apologies, as I did have access to 7.0 for testing. Glad that I was able to help. –  billisphere May 23 '13 at 1:21
add comment
Needs["Combinatorica`"];
crds = {{1, 10}, {2, 4}, {10, 5}, {20, 10}}
vertices = Range[Length[crds]]; edges = 
Thread[vertices -> RotateLeft[vertices]];
GraphPlot[edges]
share|improve this answer
1  
In[]:= Head[GraphPlot[e] Out[]:= Graphics, so it is not a graph. I cant use Degrees[] on it. –  jnthn May 22 '13 at 20:42
add comment

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.