Lots of positive exponentials leading to huge exponents

Click For Summary

Discussion Overview

The discussion revolves around the challenges of implementing a scattering rate equation in Fortran 95, particularly due to issues with handling large positive exponents that lead to numerical overflow. Participants explore potential solutions and approximations to manage the calculations effectively.

Discussion Character

  • Technical explanation, Debate/contested, Mathematical reasoning

Main Points Raised

  • The original poster describes an equation for a scattering rate that involves positive and negative exponentials, leading to exponents exceeding 1000, causing overflow in Fortran 95.
  • Some participants inquire about the specific form of the equation to better understand the problem.
  • The original poster provides the equation using LaTeX, detailing the components and their dimensions, but expresses difficulties with LaTeX formatting.
  • One participant questions the term "deca-nanometer," seeking clarification on its meaning and suggesting it may refer to a range of tens of nanometers.
  • Another participant proposes an approximation for large exponentials, suggesting that for very large x, (e^x - 1) can be approximated by e^x, and recommends determining a cutoff point for applying this approximation.
  • Further discussion includes the suggestion to use a specific cutoff for x based on IEEE double-precision limits, indicating that e^x - 1 can be simplified for x greater than approximately 36.7.
  • The original poster acknowledges the suggestion and expresses intent to try the approximation method.
  • In a later post, the original poster confirms that the proposed method has resolved the overflow and underflow issues in their calculations.

Areas of Agreement / Disagreement

Participants generally agree on the potential effectiveness of approximating large exponentials, but there is no consensus on the best approach to define the dimensions mentioned or the exact implications of the approximations.

Contextual Notes

The discussion includes various assumptions about the behavior of exponential functions and numerical limits in programming, which may not be universally applicable without further context.

ewant
Messages
8
Reaction score
0
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.
 
Physics news on Phys.org
What does the equation look like?
 
Have not had much experience with Latex typesetting but here goes:

[tex] \begin{multline*}<br /> f_{dbl}(\Theta)= \frac{ \exp^{-2(L_c+Z_i)A_Q(\Theta)} } { (\exp^{ 2L_c A_Q(\Theta) } - 1)^2 } \\<br /> \{<br /> E_C(\Theta)^2 + E_D(\Theta)^2 +E_S(\Theta)^2 \\<br /> + 2 E_C(\Theta) ( E_D(\Theta) \cos{ (Q_Z(\Theta) L_c) } - E_S(\Theta) \cos{ (Q_Z(\Theta) Z_i) } ) \\<br /> - 2 E_D(\Theta) E_S(\Theta) \cos{ ( Q_Z(\Theta) (L_c - Z_i) ) }<br /> \}<br /> \end{multline*}[/tex]

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

- 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:
Ha harr, got it to work after all! :)
 
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.
 
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.
 
Ben Niehoff said:
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.

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]
 
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!
 

Similar threads

  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 3 ·
Replies
3
Views
11K
Replies
2
Views
1K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
10
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K