Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1995
*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 1995

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

Search the Archive

Re: How use the Union function (MMA v.2,2 on PC )?

  • To: mathgroup at christensen.cybernetics.net
  • Subject: [mg919] Re: How use the Union function (MMA v.2,2 on PC )?
  • From: rubin at msu.edu (Paul A. Rubin)
  • Date: Sun, 30 Apr 1995 03:53:42 -0400
  • Organization: Michigan State University

In article <3nkbi9$mq8 at news0.cybernetics.net>,
   ptaszyns at uci.agh.edu.pl (Boguslaw Ptaszynski) wrote:
->Dear Mathgroup
->
->I have wanted to use the Union function to remove repeated elements
->in the following problem :
->
->Clear[pe, pierw, llk, x, i, imax, k, u, fun];
->pe=100; fun=Tan[x]+(2/pe)*x;
->pierw=Table[FindRoot[fun==0, {x, k}], {k, 3, 10, 0.5}];
->imax=Length[pierw]; u=Flatten[pierw]; llk=Table[N[u[[i,2]],7], 
{i,1,imax}];
->pierw=Union[llk]
->
->but I was unable to get it. Why ?
->Can someone tell me how to make it ?
->
->Any help in this area would be appriciated 
->
->Boguslaw Ptaszynski
->[ e-mail : ptaszyns at galaxy.uci.agh.edu.pl ]
->
I assume your problem is with the failure to remove repeated elements.  The 
problem is that to Mathematica they are not identical, just close.  Union[] 
 has an option SameTest which you can use to specify how repeated elements 
are detected.  The default seems to be that they be identical.  The 
following change to the last line of your example tests equality only to 
the extent of machine number precision:

  pierw = Union[ llk, SameTest -> (Equal[ Chop[ #1 - #2 ], 0 ]&) ]

Paul

**************************************************************************
* Paul A. Rubin                                  Phone: (517) 432-3509   *
* Department of Management                       Fax:   (517) 432-1111   *
* Eli Broad Graduate School of Management        Net:   RUBIN at MSU.EDU    *
* Michigan State University                                              *
* East Lansing, MI  48824-1122  (USA)                                    *
**************************************************************************
Mathematicians are like Frenchmen:  whenever you say something to them,
they translate it into their own language, and at once it is something
entirely different.                                    J. W. v. GOETHE


  • Prev by Date: Re: NDSolve problem
  • Next by Date: how can I do this functionally?
  • Previous by thread: How use the Union function (MMA v.2,2 on PC )?
  • Next by thread: PlotRange Limitation?