Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I understand that I can use Chop to force a very small number to be treated as 0 and can use PossibleZeroQ to as a way to test whether such a number might effectively be 0, but applying Chop every time a small number is close to zero in order to "make it be" zero is tedious and error prone; while PossibleZeroQ seems to have its own ideas about what constitutes 0.

Are there global settings that will let me

  • treat every number smaller than some specified value as 0, effectively applying Chop automatically to all results; and
  • specify how large a number PossibleZeroQ should recognize as 0?
share|improve this question
    
There is a system option controlling the maximum difference when treating close inexact numbers as equal. But I can't find it now ... should be somewhere in SystemOptions –  Szabolcs Nov 13 '12 at 18:59
    
@Szabolcs and raxa: you're probably looking for Internal`$EqualTolerance. –  rm -rf Nov 13 '12 at 19:11
    
@rm-rf: That looks interesting. There's no help on it though, and its value (2.10721) is cryptic. –  raxacoricofallapatorius Nov 13 '12 at 19:16
4  
Regarding the first point: What about $Post=Chop? –  sebhofer Nov 13 '12 at 19:30
2  
And note that Chop can tale a second argument specifying the tolerance. So you might want to use something like $Post = Chop[#, 10^-13]&. –  murray Nov 13 '12 at 22:04
show 1 more comment

1 Answer

up vote 5 down vote accepted

As was pointed out in the comments, $Post is a way to go here. Take as an example:

FourierDCT[FourierDCT[{0, 0, 1, 0, 0}, 2], 3]

(*{0., -5.55112*10^-17, 1., 1.38778*10^-17, 1.38778*10^-17}*)

Now lets set $Post to Chop with tolerance 10^-13.

$Post = Chop[#, 10^-13] &;

This will apply the Chop function to every output thereafter.

FourierDCT[FourierDCT[{0, 0, 1, 0, 0}, 2], 3]

(*{0, 0, 1., 0, 0}*)

If you want to make this behavior semi-permanent, you can set $Post in any one of your init.m files. A good choice might be the one located at

$InstallationDirectory <> "\\SystemFiles\\Kernel\\Packages\\init.m"

If you do this and want to not Chop for a particular output you can always clear $Post or remove this from init.m and restart the kernel.

share|improve this answer
    
Andy Ross ,Does $Post = Chop[#, 10^-13] &; really take away the digits smaller than 10^-13? I find that those digits still exist by Print[MatrixForm[FourierDCT[FourierDCT[{0, 0, 1, 0, 0}, 2], 3]]]; –  novice May 7 '13 at 5:33
    
@novice this is a very good question that I don't immediately know the answer to. I suggest posting it as a question. –  Andy Ross May 7 '13 at 14:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.