# Tag Info

0

I found half an answer that works well except for the orientation part. As several of you have hinted at the FindCurvePath function is on the right track, but it only works in two dimensions. My options are thus projecting/rotating any polygon to some canonical plane, or, more easily, using the FindShortestTour function which solves the "traveling salesman ...

4

In version 10, you can use MeshCoordinates[ConvexHullMesh[...]] as in RunnyKine's answer, but you need to re-order them using MeshCells: pentagon=N@Table[{Cos[2 Pi k /5], Sin[2 Pi k /5]}, {k, 5}] points = N@RandomSample[Join[pentagon, {{0, 0}}]] chm=ConvexHullMesh[points]; ordering=MeshCells[chm,2][[1,1]] out=MeshCoordinates[chm][[ordering]] ...

1

The following works in your special case but can't be generalized. l = {"+", "m", "π", "[]", "2"}; SeedRandom@0; rl = RandomSample[l, 5]; g = With[{cg = CycleGraph[5]}, Graph[UndirectedEdge @@@ Thread@{rl, RotateLeft@rl}, VertexCoordinates -> (Rule @@@ Thread@{rl, VertexCoordinates /. AbsoluteOptions[cg, VertexCoordinates]}), ...

3

If you have Version 10, you could use ConvexHullMesh. pts = RandomReal[{-10, 10}, {6, 2}]; You can then order them by doing: chull = ConvexHullMesh[pts]; And here are the points: MeshCoordinates[chull] Note: This does not always order the points but one can use MeshCells which will give the ordering correctly. See @kguler's answer.

2

Could use ConvexHull in the ComputationalGeometry standard add-on package. Needs["ComputationalGeometry`"] We'll create a simple example. pts = RandomReal[{-10, 10}, {6, 2}]; ListPlot[Append[pts, First[pts]], Joined -> True] Now find and plot the (ordered) outer points. hullindices = ConvexHull[pts]; hullpts = pts[[hullindices]]; ...

0

Here is a function to show the order of a list of expressions. By using Less as in the question, I'm assuming the expressions are unequal. ClearAll[showOrder]; SetAttributes[showOrder, HoldAll]; showOrder[{e__}] := Defer /@ Hold[e][[Ordering[{e}, All, Less]]] /. Hold -> Less OP's example: Block[{k = 1, m = 1}, showOrder[{Subscript[ω, 1], ...

6

I think this does what you want: Less @@ SortBy[Defer[Subscript[ω, #]] & /@ {1, 2, 11, 22}, N @@ # &]

4

Edit: This question closely related to one asked on Stack Overflow before the existence of Mathematica.SE. Please see this link for the history and examples: Unsort: remembering a permutation and undoing it See also: Ordering@Ordering and Ranking Permutations The first Q&A references a use of the Ordering method shown below from 2007 on ...

0

Lookup is working also. l1 = {{"Australia", a1}, {"USA", a2}, {"Norway", a3}}; l2 = {{"USA", b1}, {"Norway", b2}, {"Australia", b3}}; {First@#, Lookup[Rule @@@ l2, First@#]} & /@ l1 or {#, Lookup[Rule @@@ l2, #]} & /@ l1[[;; , 1]] (*{{"Australia", b3}, {"USA", b1}, {"Norway", b2}}*)

1

While there are a number of replies with ways of ordering the two lists, let me give a different approach to comparing two sets of data of the form you gave. This applies if you are using v10 as it uses Associations. Here's the data eldo used l1 = {{"Australia", a1}, {"USA", a2}, {"Norway", a3}}; l2 = {{"USA", b1}, {"Norway", b2}, {"Australia", b3}}; ...

1

SortBy[l2, Position[l1, #1 [[1]]] [[1, 1]] &]

0

Using Mathematica 10's associations makes this simple. l1 = {{"Australia", a1}, {"USA", a2}, {"Norway", a3}, {"Russia", a4}, {"Japan", a5}}; Convert the second list to an association l2 = Association@((#[[1]] -> #[[2]]) & /@ {{"Russia", b1}, {"Norway", b2}, {"Japan", b3}, {"Australia", b4}, {"USA", b5}}); Apply the association rules l3 = ...

2

L1 = {{"Australia", a1}, {"Norway", a2}, {"USA", a3}, {"Russia", a4}, {"Japan", a5}} ; L2 = {{"Russia", b1}, {"Norway", b2}, {"Japan", b3}}; x = First /@ L1; y = Cases[L2, {#, _}] & /@ x; z = Apply[Sequence, y, {2}] /. {} -> ""; Grid[Prepend[Transpose[{L1, z}], {"L1", "L3"}], Frame -> All] Edit For speed, create y like so :-- ...

3

L1 = {{"Australia", a1}, {"USA", a2}, {"Norway", a3}}; L2 = {{"USA", b1}, {"Norway", b2}, {"Australia", b3}}; L2[[Flatten[Position[First /@ L2, #] & /@ First /@ L1]]] {{"Australia", b3}, {"USA", b1}, {"Norway", b2}} Or (revised as per Mr. Wizard's comments) Sort[L2][[Ordering @ Ordering @ L1]] {{"Australia", b3}, {"USA", b1}, {"Norway", ...

3

l1 = {{"a", a1}, {"b", a2}, {"c", a3}} l2 = {{"c", b3}, {"b", b2}, {"a", b1}} {#, # /. Rule @@@ l2} &[l1[[All, 1]]] // Transpose (* {{"a", b1}, {"b", b2}, {"c", b3}} *)

Top 50 recent answers are included