Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #7678
| From | Christopher Young <cy56@comcast.net> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Sorting coefficients |
| Date | 2012-01-09 08:18 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <jee7t9$cn6$1@smc.vnet.net> (permalink) |
| References | <201201060914.EAA26796@smc.vnet.net> <D82BC8DC-F48C-4C3A-8E54-C3451B0CAE49@mimuw.edu.pl> |
On Jan 7, 2012, at 4:04 AM, Andrzej Kozlowski wrote:
> How about this:
>
> ls = Prepend[
> Table[{Re, Im}[E^(k (2 \[Pi])/6 I)] // Through, {k, 0, 5}], {0, 0}]
>
> ls1 =
> Sort[ls, Which[#1[[2]] < #2[[2]],
> True, #1[[2]] == #2[[2]], #1[[1]] < #2[[1]], True, False] &]
>
> {{-(1/2), -(Sqrt[3]/2)}, {1/2, -(Sqrt[3]/2)}, {-1, 0}, {0,
> 0}, {1, 0}, {-(1/2), Sqrt[3]/2}, {1/2, Sqrt[3]/2}}
>
> Graphics[MapIndexed[{Text[First[#2], #1]} &, ls1]]
This certainly works in this case, and looks like a simple way to do it.
And using MapIndexed is a handy way to plot the points.
I'm still puzzled about what's being handed to Sort. If it's just a True
or False value for each pair of consecutive values as we go down the
list, how exactly does that specify ordering by numerical value? I would
think that Mathematica would revert to the default sorting for irrationals,
which seemed to be based on complexity of expression. At any rate, I'd
rather be able to pass the test function explicitly to Sort, as in
Sort[
hexPts,
#1[[2]] < #2[[2]]
\[Or]
(#1[[2]] == #2[[2]] \[And] #1[[1]] <= #2[[1]])
&
]
ls1 =
Sort[
ls,
Which[
#1[[2]] < #2[[2]], True,
#1[[2]] == #2[[2]], #1[[1]] < #2[[1]], True,
False
] &
]
{{-(1/2), -(Sqrt[3]/2)}, {1/2, -(Sqrt[3]/2)}, {-1, 0}, {0, 0}, {1,
0}, {-(1/2), Sqrt[3]/2}, {1/2, Sqrt[3]/2}}
Shouldn't the Help for Which say "_either_ True or False":
Conditions are evaluated until one is found that is neither True nor
False:
In[1]:= x = 0
Out[1]= 0
In[2]:= Which[1 < 0, a,
x == 0, b,
0 < 1, c]
Out[2]= b
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: Sorting coefficients Christopher Young <cy56@comcast.net> - 2012-01-09 08:18 +0000
csiph-web