Lots of positive exponentials leading to huge exponents

  • Thread starter ewant
  • Start date
  • #1
8
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.
 

Answers and Replies

  • #2
Ben Niehoff
Science Advisor
Gold Member
1,879
162
What does the equation look like?
 
  • #3
8
0
Have not had much experience with Latex typesetting but here goes:

[tex]
\begin{multline*}
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) ) }
\}
\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:
  • #4
8
0
Ha harr, got it to work after all! :)
 
  • #5
Ben Niehoff
Science Advisor
Gold Member
1,879
162
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.
 
  • #6
8
0
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.
 
  • #7
CRGreathouse
Science Advisor
Homework Helper
2,820
0
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]
 
  • #8
8
0
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!
 

Related Threads on Lots of positive exponentials leading to huge exponents

Replies
3
Views
831
Replies
7
Views
670
Replies
3
Views
2K
Replies
9
Views
1K
Replies
3
Views
2K
Replies
6
Views
501
  • Last Post
Replies
6
Views
3K
  • Last Post
Replies
3
Views
535
  • Last Post
Replies
4
Views
536
  • Last Post
Replies
7
Views
8K
Top