Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1997
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1997

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

Search the Archive

Union & precision <<take 2>>

  • To: mathgroup at smc.vnet.net
  • Subject: [mg8627] Union & precision <<take 2>>
  • From: Gadi Oron <oron at manet.pmmh.espci.fr>
  • Date: Fri, 12 Sep 1997 04:10:41 -0400
  • Organization: Acces regional Ile-de-France (Univ. Paris VI/VII) - France
  • Sender: owner-wri-mathgroup at wolfram.com

Hello again,

This is the second chapter im my adventure of trying to use Union taking
into account the precision.

As suggested by the replies to my last message (thanx) the use of
SameTest-> testfunc should do the thing.

Since my sets contain only one of the two structures
"eline[{x1,y1},{x2,y2}]" and "Circle[{x,y},r]" I wrote the following:

pre=10^(-4);
norm[v_List]:=Sqrt[v.v];

Clear[test];

test[lhs_Circle,rhs_Circle]:=
	(norm[lhs[[1]]-rhs[[1]]]<pre && Abs[lhs[[2]]-rhs[[2]]]<pre );

test[lhs_eline , rhs_eline]:=
	(norm[lhs[[1]]-rhs[[1]]]<pre && norm[lhs[[2]]-rhs[[2]]]<pre);

test[lhs_,rhs_]:=TrueQ[(lhs==rhs)];

Now, it seems to work all right: Check :

test[Circle[{0.192450089729875202`,0.277777777777777767`},
    0.0555555555555555535`], 
  Circle[{0.192450089729875308`,0.277777777777777901`},
    0.0555555555555555802`]]

Gives : True.

Also :

Union[{Circle[{0.192450089729875202`,0.277777777777777767`},
      0.0555555555555555535`], 
    Circle[{0.192450089729875308`,0.277777777777777901`},
      0.0555555555555555802`]},SameTest->test]

Gives (right):

{Circle[{0.19245,0.277778},0.0555556]}

But (surprise):

Union[{Circle[{0.192450089729875202`,0.277777777777777767`},
      0.0555555555555555535`],
    Circle[{0.192450089729875202`,0.722222222222222232`},
      0.0555555555555555535`],
    Circle[{0.192450089729875308`,0.277777777777777901`},
      0.0555555555555555802`]},SameTest->test]

Gives (!!) :

{Circle[{0.19245,0.277778},0.0555556],Circle[{0.19245,0.722222},0.0555556],
  Circle[{0.19245,0.277778},0.0555556]}

Notice that the set is not well ordered and that we have 2 of the
element equal by the SameTest.

What is going wrong??

Thank you.

P.S. Sorry for the illisibility, I have put in the full form of the
numbers in order to show the precision.

/\/\/\/\/\/\/\/\/\/\/\/>> Gadi ORON <<\/\/\/\/\/\/\/\/\/\/\/\/\
| EMAIL :  oron at pmmh.espci.fr   ::::     oron at clipper.ens.fr  |
| Homepage : http://pmmh.espci.fr/~oron/personal.html         |
| fido : 2:325/302.8                                          |
| 		  Soyez braves - be brave.                    |
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/




  • Prev by Date: Maximizing notebook windows in Mma 3.0.1 for Windows 95
  • Next by Date: Question on Mathematica Signal Processing Packages 2.9.5
  • Previous by thread: RE: Maximizing notebook windows in Mma 3.0.1 for Windows 95
  • Next by thread: Re: Union & precision <<take 2>>