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

Lots of positive exponentials leading to huge exponents

  1. Jul 31, 2008 #1
    Hello there,

    This is my first post on this forum so bear with me if I don't know the rules or I am posting in the wrong area.

    I am coding up an of equation for a scattering rate which involve quite a few positive (and a couple of negative) exponentials which often have terms that go into hundreds leading to results that have huge exponents. I originally wrote up this scattering rate in Mathematica and it didn't complain, but when I looked in detail at the equation some terms were reaching exponents of over a 1000!

    I am writing the scattering rate in Fortran 95 for a simulator and this is where my problems occur. In Fortan95 I can use double precision numbers which have a max. exponent range of 10^+/-308 and I am overflowing. I am currently using the atomic unit system which should help as it normalizes a lot of the units to 1. The equation itself should produce a value between 0 and 1.

    I have tried splitting up the equation into components, then taking the natural logarithm to try and simplify the problem but this has not helped. I started to think about trying to scale the numbers I am using in a manner similar to changing unit system, but I don't have any notes/references on where to start.

    Any help/ideas on this would be a great help, thanks.
  2. jcsd
  3. Jul 31, 2008 #2

    Ben Niehoff

    User Avatar
    Science Advisor
    Gold Member

    What does the equation look like?
  4. Aug 1, 2008 #3
    Have not had much experience with Latex typesetting but here goes:

    f_{dbl}(\Theta)= \frac{ \exp^{-2(L_c+Z_i)A_Q(\Theta)} } { (\exp^{ 2L_c A_Q(\Theta) } - 1)^2 } \\
    E_C(\Theta)^2 + E_D(\Theta)^2 +E_S(\Theta)^2 \\
    + 2 E_C(\Theta) ( E_D(\Theta) \cos{ (Q_Z(\Theta) L_c) } - E_S(\Theta) \cos{ (Q_Z(\Theta) Z_i) } ) \\
    - 2 E_D(\Theta) E_S(\Theta) \cos{ ( Q_Z(\Theta) (L_c - Z_i) ) }

    E_C(\Theta)= \exp^{(L_c + 2Z_i) A_Q(\Theta)} ( \exp^{2(L_c - Z_i) A_Q(\Theta)} - 1)
    E_D(\Theta)= \exp^{2 L_c A_Q(\Theta)} ( \exp^{2 Z_i A_Q(\Theta)} - 1)
    E_S(\Theta)= \exp^{(L_c + Z_i) A_Q(\Theta)} ( \exp^{2 L_c A_Q(\Theta)} - 1)
    A_Q(\Theta)= \sqrt{k^2 \sin^2(\theta) + k_c^2}
    Q_Z(\Theta)= k(1-\cos(\Theta))

    - The function [itex]f_{dbl}[/itex] should return a value between 0 and 1.
    - [itex]Z_i[/itex] and [itex]L_c[/itex] are in metres and roughly within deca-nanometre dimension.
    - [itex]k , k_c[/itex] are in inverse metre dimensions and can vary from [itex]10^6[/itex] to [itex]10^9[/itex]

    I am guessing that whoever asked me to give this equation may be regretting it now! Still I have a had a thorough crash course in latex! I seem to be having a problem with getting the linebreaks to work, but I guess you can copy the code from the pop-up window!

    edit:: I have tried to fix the latex src for the main equation, but I can't seem to find the error. Worked OK in the preview message window, so I am at a loss.
    Last edited: Aug 1, 2008
  5. Aug 1, 2008 #4
    Ha harr, got it to work after all! :)
  6. Aug 1, 2008 #5

    Ben Niehoff

    User Avatar
    Science Advisor
    Gold Member

    What's a deca-nanometer? Do you mean they vary in range from decameters to nanometers (i.e., 10^1 down to 10^-9)? Or did you mean decimeters (10^-1 to 10^-9)? Or did you mean tens of nanometers (10^-8 to 10^-9)?

    One thing that might help is this: For very large x,

    [tex](e^x - 1) \approx e^x[/tex]

    So, first find some x that that puts this approximation within the acceptable bounds of error. For example,

    [tex]\frac{e^{10} - (e^{10} - 1)}{e^{10} - 1} = 0.0000454[/tex]

    So that's already quite accurate. If you chose x = 100, the error is less than 10^-43. It seems some cutoff between 10 and 100 is good.

    Once you choose a cutoff, do this: For all values of x less than the cutoff, calculate the formula as written. For x greater, simplify the formula by substituting e^x for (e^x - 1). Then you can simplify the exponents in the numerator and denominator to get them within an acceptable range, before actually calculating exp(*).

    That ought to do it.
  7. Aug 1, 2008 #6
    Yeah, I am not surprised you haven't heard of the 'deca-nanometre' term, it is one of these fancy buzz words used to make a particular dimension sound more interesting than it actually is! It is used to denote dimensions of tens of nanometres, so the 10^-8 to 10^-9 range.

    Thanks for the suggestion of approximating the (e^x - 1) terms, that might really do the trick. I will give it a try and get back to you.
  8. Aug 1, 2008 #7


    User Avatar
    Science Advisor
    Homework Helper

    If you're working in IEEE double-precision (as evidenced by the "10^+/-308" in the original post), e^x - 1 = e^x for x greater than roughly [itex]53\ln2\approx36.7.[/itex]
  9. Aug 5, 2008 #8
    Thanks for the help, that has solved the problem. I am now able to calculate the function without it overflowing and under-flowing all over the place!
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?

Similar Discussions: Lots of positive exponentials leading to huge exponents
  1. Nested Exponents (Replies: 2)

  2. Exponential or not? (Replies: 4)

  3. Exponent confusion. (Replies: 2)