Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1998
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1998

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

Search the Archive

RE: Strange behavior of Sort

  • To: mathgroup at smc.vnet.net
  • Subject: [mg12968] RE: [mg12941] Strange behavior of Sort
  • From: Ersek_Ted%PAX1A at mr.nawcad.navy.mil
  • Date: Sun, 28 Jun 1998 02:51:56 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

Edward Neuman  wrote:
|
|
|In Mathematica 3.0:
|
|In[5]:=
|li={1/Sqrt[2], 1, -Sqrt[2]};
|
|In[7]:=
|Sort[li]//InputForm
|
|Out[7]//InputForm=
|{1, 1/Sqrt[2], -Sqrt[2]}
|
|Sort doesn't work properly on this list. |
|

Lets look at that some more.

In[1]:=
lst={-1,0,1,-2,2,Sqrt[2],-Sqrt[2],1/Sqrt[2],-1/Sqrt[2]};


As you pointed out simple application of Sort will not sort them in 
increasing order.
In[2]:=
Sort[lst]//N

Out[2]=
{-2.,  -1.,  0,  1.,  2.,  -0.707107,  0.707107,  -1.41421,  1.41421}

If you want them sorted numerically you can specify an appropriate
ordering  function.
In[3]:=
Sort[lst,  Less]//N

Out[3]=
{-2.,  -1.41421,  -1.,  -0.707107,  0,  0.707107,  1.,  1.41421,  2.}


Now what is the default ordering function? Dave Withoff posted it once,
but I didn't understand what he was saying.

Ted Ersek



  • Prev by Date: Re: Find Max of "Concave" List
  • Next by Date: Re: Fw: greek symbols in eps files
  • Previous by thread: Re: Strange behavior of Sort
  • Next by thread: Re: Strange behavior of Sort