MathGroup Archive 1999

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

Search the Archive

Re: Position and Real Numbers


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
____________________________________________________________________




  • Prev by Date: Re: TeXSave and User Defined Style Sheets
  • Next by Date: Re: New book on Mathematica Graphics is needed
  • Previous by thread: Re: Position and Real Numbers
  • Next by thread: blah::usage and BeginPackage