MathGroup Archive 2012

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: SortBy won't order irrationals


It's normal, since Mathematica sorts by structure.

This could be a simple solution:
In[]:= Sort[ptsIrr, #1[[2]] < #2[[2]] &]
Out[]:= {{-1, 0}, {7, 0}, {Sqrt[3], 1}, {6, 1}, {Sqrt[5], 1}, {4, 1}, {1, Sqrt[2]}, {2, 2}, {0, 2}}

This sorts by structure:
In[]:= Sort[{Pi, E, 2, 3, 1, Sqrt[2]}]
Out[]:= {1, 2, 3, Sqrt[2], E, \[Pi]}

This sorts by numerical values:
In[]:= Sort[{Pi, E, 2, 3, 1, Sqrt[2]}, Less]
Out[]:= {1, Sqrt[2], 2, E, 3, \[Pi]}

With SortBy[], simply you have to N[] as you did.



  • Prev by Date: Mantaining the same form
  • Next by Date: data proccess
  • Previous by thread: Re: SortBy won't order irrationals
  • Next by thread: Re: SortBy won't order irrationals