Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

[Mathematica] Subnormal numbers handling

  1. Jan 25, 2012 #1
    Hello all :)

    I have a matrix which I diagonalize giving me a list of eigenvalues lambda. Those are complex numbers.
    After that, I calculate Exp[-lambda] and my code goes on.

    For some parameters in my code, some lambdas have very large magnitude so that the exponentiation leads to quantities involving subnormal numbers (for Mathematica, those are numbers which are smaller than $MinMachineNumber). At this point, the code becomes _very_ slow (in addition to inherent hardware difficulties performing floating point operations with subnormal numbers, I understand Mathematica treat them in arbitrary precision !). After a _very_ long time though, Mathematica gives me the right answer (that can be said at least :))

    To circumvent this situation, I apply the function If[Abs[#]<1.*^-50,0,#]& just after the exponentiation. So far, this seems to give me the right answer with no slowing down of the code.

    One question though : I've chosen the value 1.*^-50 quite arbitrarily and I'm afraid that what I do might be a little bit “rough”.
    Is there a rigorous and/or elegant way to avoid generation of subnormal numbers by the exponentiation?

    Thanks in advance :)
     
  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted



Similar Discussions: [Mathematica] Subnormal numbers handling
Loading...