Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: [mg23007] Chop? Programming Challenge!!
Replies: 1   Last Post: Apr 13, 2000 3:08 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View  
Russell Towle

Posts: 70
Registered: 12/3/04
RE: [mg23007] Chop? Programming Challenge!!
Posted: Apr 13, 2000 3:08 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Hi David,

>Did I miss something in your posting? If you check Help you will see that
>the tolerance for Chop is 10^-10.
>
>So why don't you use Chop[expression, 10^-6]?


Many thanks to those who promptly informed me of how to use Chop. I didn't
realize that Chop had a second argument until about one minute after I had
posted to the Group.

I routinely use Chop to look at lists of numbers and vectors. Perhaps it is
a coincidence, but only after going to version 4.01 did I see Chop return a
list with numbers in scientific notation. The very same notebooks in which
no problem arose under version 4.00 are now failing under version 4.01.

All my numbers are machine precision. Perhaps there is some setting in the
Options Inspector which allows machine precision numbers to bleed into
spurious higher precision and fool plain old Chop-with-one-argument.

As an example of a function which worked perfectly under version 4.00, but
now sometimes fails under version 4.01, I offer this, called 'vunion', for
'vector union'. It finds the Union of a list of n-dimensional vectors. I
offer as a programming challenge, to construct a faster vector union
function, which is as unfailingly accurate as this one was, and now is
again, once Chop has been given its second argument. Let the function
operate upon machine-precision n-vectors. It is important to devise lists
for testing, in which two vectors, actually the same, appear to differ,
with changes in sign for numbers which Chop to 0. Let the lists contain
1000 vectors, which after Union reduce to 350 or so.

(*****)
(* 2.2 to 4.0 version of vunion*)

vunion::usage = "vunion[v] returns the union of a list of n-vectors.";

vunion[v_]:=
Union[Chop[v],
SameTest->((Sign[#1]==Sign[#2]) &&
( Chop[#1-#2]==Table[0,{Length[ v[[1]] ]}] ) &)]


(*****)
(* 4.01 version of vunion*)

vunion::usage = "vunion[v] returns the union of a list of n-vectors.";

vunion[v_]:=
Union[Chop[v, .000001],
SameTest->((Sign[#1]==Sign[#2]) &&
( Chop[#1-#2, .000001]==Table[0,{Length[ v[[1]] ]}] ) &)]

Russell Towle
Box 141
Dutch Flat, CA 95714
(530) 389-2872







Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.