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.

Values like a +0. I are really annoying. Answers from

How to reduce expressions with complex coefficients in the form of a+0.*I? Is there a way to globally set when to treat a very small number as zero?

give me some clue, but I find $Post = Chop[#, 10^-16] &; doesn't work, for example :

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

gives (0. -5.55112*10^-17 1. 1.38778*10^-17 1.38778*10^-17 ), which means the small digits still exist.

share|improve this question
    
What's wrong with Print[MatrixForm[FourierDCT[FourierDCT[{0, 0, 1, 0, 0}, 2], 3] // Chop]]? You can't use Chop outside the MatrixForm if that's the problem you've been having. –  Jonathan Shock May 7 '13 at 5:55
2  
But you know, it's probably a mistake to try to always hide small numbers --- someday you may need to know that they are not really zero. Just choose Chop whenever you want to display things. –  bill s May 7 '13 at 5:57
    
Jonathan Shock: I don't know Chop fails outside the MatrixForm. But doesn't $Post = Chop[#, 10^-16] &; tells Mathematica to neglect digits smaller than 10^-16 automatically? –  novice May 7 '13 at 6:12
    
@bills But isn't $Post (or $PrePrint) just the right thing to use whenever one wants to display things? The problem here is that it won't apply to Printed output (try it without the Print statement). –  István Zachar May 7 '13 at 6:12
1  
The default for all numbers is Complex. But if you use only rationals (and don't do stuff like Sqrt[-rational] then everything will remain rational. But if you do operations that generate complex numbers (like Sqrt or roots of polynmials, there are lots!) then you need to deal with it explicitly. You can always apply Re to take only the real part or Chop to remove small imaginary values. –  bill s May 7 '13 at 8:35
show 4 more comments

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.