Re: newbie: computing rational numbers and decimal
- To: mathgroup at smc.vnet.net
- Subject: [mg30726] Re: newbie: computing rational numbers and decimal
- From: "Allan Hayes" <hay at haystack.demon.co.uk>
- Date: Sat, 8 Sep 2001 02:56:09 -0400 (EDT)
- References: <9naldr$np6$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Alan,
lst= Union[{ 1/2, 1/3, 1/2, 1/5}];
N[lst]
{0.2,0.333333,0.5}
These are machine precision numbers
N[lst, 30]
{0.200000000000000000000000000000,0.333333333333333333333333333333,0.\
500000000000000000000000000000}
These are to precision 30.
Here is Carl Woll's code for removing repeats,
RemoveRepeats[x_]:=Block[{i},i[n_]:=(i[n]=Sequence[]; n); i/@x];
RemoveRepeats[{2,2,1,3,2,1,3}]
{2,1,3}
--
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565
"Alan Tu" <alantu at students.uiuc.edu> wrote in message
news:9naldr$np6$1 at smc.vnet.net...
> Thanks Bob and Allan for answering my question on summing lists. I have
> another question. Suppose I have a sorted list (using union) of rational
> numbers. Is there a function that calculates those rational numbers to a
> given decimal position, preferably a listable function so I don't have to
> operate in a loop?
>
> Also, suppose that I have done that and now have a list of (still sorted,
I
> think) decimal representations. Is there a quick way to remove any
> duplicates in this list, or do I have to use a loop and test equality each
> part of the list to the next part?
>
> Thanks again! I really appreciate it!
>
> Alan
>
>
>