Re: Position and Real Numbers
- To: mathgroup at smc.vnet.net
- Subject: [mg18907] Re: Position and Real Numbers
- From: Paul Abbott <paul at physics.uwa.edu.au>
- Date: Mon, 26 Jul 1999 14:27:47 -0400
- Organization: University of Western Australia
- References: <7n694d$h5o@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Jason Gill wrote:
> Is there an easy way to make Position work as expected for real numbers, or more
> accurately make Range work as
> expected ???
Both work "as expected". With
In[1]:= x=Range[-3,2,.05];
since the elements are distinct, to locate -0.05 you could use a test such as
In[2]:= Position[x,_?(-0.06<#<-0.04&)]
Out[2]= {{60}}
or you could Rationalize the entries
In[3]:= Position[Rationalize[x],Rationalize[-1/20]]
Out[3]= {{60}}
You can make Range give a set of exact values if you give it exact input:
In[4]:= x=Range[-3,2,Rationalize[0.05]];
In[5]:= Position[x,Rationalize[-1/20]]
Out[5]= {{60}}
Moral: If you give Mathematica exact input and it will generally give you exact
ouput. With approximate input you generally get approximate output.
____________________________________________________________________
Paul Abbott Phone: +61-8-9380-2734
Department of Physics Fax: +61-8-9380-1014
The University of Western Australia
Nedlands WA 6907 mailto:paul at physics.uwa.edu.au
AUSTRALIA http://physics.uwa.edu.au/~paul
God IS a weakly left-handed dice player
____________________________________________________________________