Re: Sort
- To: mathgroup at smc.vnet.net
- Subject: [mg19176] Re: [mg19152] Sort
- From: "Wolf, Hartmut" <hwolf at debis.com>
- Date: Tue, 10 Aug 1999 02:52:40 -0400
- Organization: debis Systemhaus
- References: <199908060358.XAA08207@smc.vnet.net.>
- Sender: owner-wri-mathgroup at wolfram.com
Hermann Meier schrieb: > > Sort is not reliable. Try the following (Mathematica Version 4): > > In[1]:= > Sort[{0, -Sqrt[2], 5}] > > Out[1]= > {0, 5, -Sqrt[2]} > > In[2]:= > Sort[{0., -Sqrt[2], 5}] > > Out[2]= > {0., 5, -Sqrt[2]} > > One has to apply N to the list to get the correct result: > > In[3]:= > Sort[N[{0., -Sqrt[2], 5}]] > > Out[3]= > {-1.414213562, 0., 5.} > > HM Hermann, of course Sort is reliable, but without applying N it doesn't know anything of the value of Sqrt[2]. But you can make Sort to know that if you just do In[1]:= exactnumbers = {0, -Sqrt[2], 5}; In[4]:= Last /@ Sort[Transpose[{N[exactnumbers], exactnumbers}]] Out[4]= {-Sqrt[2], 0, 5} Sometimes perhaps, you have to be cautious with the numerical precision you are using. kind regards, hw
- References:
- Sort
- From: "Hermann Meier" <hmeier@webshuttle.ch>
- Sort