Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to avoid overflow or underflow in mathematica?

1,655 views
Skip to first unread message

quantumfang

unread,
May 11, 2008, 3:18:43 PM5/11/08
to
It's well known that Mathematica can do evaluation to arbitrary precision. But I don't know how to avoid the following trouble in computing:

Ef = 0.;
mu=0.;
KBT = 1.*10^-10;
FL[omega_Real] := 1./(1. + E^((omega - mu - Ef)/KBT));

the error message shows

General::ovfl: Overflow occurred in computation. >>
General::unfl: Underflow occurred in computation. >>

W_Craig Carter

unread,
May 12, 2008, 4:47:07 AM5/12/08
to
Hello Quantum Fang,

You could use arbitrary precision and do something like this (although
I don't advise this approach):

fermiseries =
Normal[Series[1/(1 + E^((muShift) beta)), {beta, 0, 14}]];

colist = Simplify[CoefficientList[fermiseries, beta]]

and then write a function that calls N[beta, bigNumber] and N[mushift,
bigNumber] on the product of the two list until you have the accuracy
that you want.... This is a bad idea.

However your function, except for ((omega - mu - Ef)/KBT)
approximately 1, is the unit step function (0 if x<0, 1/2 x=0, 1 if
x>0). If you are interested in the physical aspects of this problem
then expand (omega - mu - ef) near 1/(kb T). In other words, scale
your energies with the thermal energy.

WCC

--
W. Craig Carter

Szabolcs Horvát

unread,
May 12, 2008, 4:47:28 AM5/12/08
to

You've practically written E^(10^10.) here. I hope that you do realize
how great the magnitude of this double exponential is.

Mathematica has its limits too: the biggest number it can handle is
$MaxNumber, which is 1.920224672692357*10^646456887 on my computer. The
magnitude of your expression is greater than this.

Carl Woll

unread,
May 12, 2008, 4:48:34 AM5/12/08
to
quantumfang wrote:

>It's well known that Mathematica can do evaluation to arbitrary precision. But I don't know how to avoid the following trouble in computing:
>
>Ef = 0.;
>mu=0.;
>KBT = 1.*10^-10;
>FL[omega_Real] := 1./(1. + E^((omega - mu - Ef)/KBT));
>
>the error message shows
>
>General::ovfl: Overflow occurred in computation. >>
>General::unfl: Underflow occurred in computation. >>
>
>

You don't tell us what value of omega you used. However, keep in mind
that there is a maximum number in Mathematica. On my computer this
number is:

In[34]:= $MaxNumber

Out[34]= 1.920224672692357*10^646456887

The log of this number is:

In[35]:= Log[$MaxNumber]

Out[35]= 1.488521991921978478647057*10^9

So, if (omega-mu-Ef)/KBT is larger than the above number you will get
overflow/underflow problem. With your parameters, this means that an
order 1 value of omega will cause overflow/underflow problems.

Carl Woll
Wolfram Research

0 new messages