0

Edit: So, while trying to figure out a minimal exmaple, I found out that my main problem was actually unrelated to this and it just happened to be that giant pile of warnings and error messages coming from this were hiding the real problem (which was just an index mismatch). Interestingly as you can see by running the following :

\[Omega]stepsize = 10/1000;
\[Omega]offset = -\[Omega]stepsize * 10^(-5) ;
\[Omega]max = 2
astep = 0.1;
aoffset = 0.0999;
maxa = 0.999;
maxj = Ceiling[(ArcTanh[maxa] + aoffset)/astep];
af[j_] = Tanh[astep j - aoffset];
\[Omega]p[i_, j_, k_] := \[Omega]stepsize i + \[Omega]offset + (
  k af[j])/(2 (1 + Sqrt[1 - af[j]^2]))
\[Kappa][j_] := 
 2 Pi (Sqrt[1 - af[j]^2]/(af[j]^2 + (1 + Sqrt[1 - af[j]^2])^2))^(-1)
testExponent[i_, j_, k_] := \[Omega]p[i, j, k] \[Kappa][j]
k = 10;
j = 29; testF[\[Omega]_] = 
 Interpolation[
   Table[{(i)*\[Omega]stepsize + \[Omega]offset, 
     1/(2 Pi) Sign[\[Omega]p[i, j, k]] 1/
      Internal`Expm1[testExponent[i, j, k]]}, {i, 1, 
     Ceiling[\[Omega]max/\[Omega]stepsize]}]][\[Omega]]
Plot[testF[\[Omega]], {\[Omega], \[Omega]stepsize + \[Omega]offset, 
  0.1}]
NIntegrate[
 testF[\[Omega]], {\[Omega], \[Omega]stepsize + \[Omega]offset, 2}]

for some reason it no longer likes the endpoint (despite finding an interpolating function up to w=2, the NIntegrate returns InterpolatingFunction::dmvali: The integration endpoint 2 in dimension 1 lies outside the range of data in the interpolating function. Extrapolation will be used.. I was doing a lot of integrals in parallel kernels and I hadn't yet turned that warning off, so I missed the real issue. I am very confused as to why this warning is firing though, it also seems to fire for some other endpoints in the range [0.01,2], though I couldn't find any that happen to work for the above example.

So I have a table of values, T, let's say we parmetrize it by a,b and c. I'm trying to make an interpolating function, F, in a. Schematically:

F[a_]=Table[
Interpolation[
Table[
{a,T[[a,b,c]]/(Exp[exponent[a,b,c]]-1)}
,{a,{avalues}]
,{b,{bvalues}},{c,{cvalues}}]

The exponent, exponent, goes through a large range of values from very negative to very positive, and T and E both go to 0 at the same point (in a way with a double sided limit for F). The problem I'm having though is not to do with any numerical instability of this point but when the denominator is very large. I am getting the error General::munfl when F is very close to 0 (with some examples below). I've looked at some other answers:

Underflow error General::munfl from E^x instead of Exp[x]

Asymmetric precision warnings with Plot[]. Cannot be fixed with Rationalize[] or WorkingPrecision

Underflow error General::munfl from E^x instead of Exp[x]

but I've not been able to successfully implement any of the suggested fixes. All I want to do is set these things to 0.

General::munfl: 3.79545*10^-308 0.31831 is too small to represent as a normalized machine number; precision may be lost.

General::munfl: 1/1.19906*10^308 is too small to represent as a normalized machine number; precision may be lost.

General::munfl: 1.00001 9.162856558197*10^-310 is too small to represent as a normalized machine number; precision may be lost.

General::stop: Further output of General::munfl will be suppressed during this calculation.
user70153
  • 21
  • 4
  • What happens if you compute T[[a,b,c]]/Internal`Expm1[E[a,b,c]] instead? – J. M.'s missing motivation Apr 20 '20 at 12:14
  • Exactly the same errors – user70153 Apr 20 '20 at 12:27
  • Then perhaps you could mention what T[[a,b,c]] is supposed to be. (I also forgot to say this, but E is that famous constant in Mathematica, so you aren't supposed to use it as a name of a function.) – J. M.'s missing motivation Apr 20 '20 at 12:35
  • Ok, I changed it in the question from E to exponent. This is just meant to be a schematic thing, it isn't the exact code I'm using which involves importing a bunch of pre calculated data into T.

    The issue is not T. T is a pre calculated numerical value which has been exported and reimported with no problems like this, it is in the range 0 to 1 and is always a representable (and represented) number. The issue is the 1/(Exp[exponent[a,b,c]]-1) I just need to know how to set that to 0 when it is too small to represent

    – user70153 Apr 20 '20 at 12:42
  • "All I want to do is set these things to 0." -- This happens already. Quiet[code, General::munfl] or Off[General::munfl] will suppress the warnings. – Michael E2 Apr 20 '20 at 12:45
  • @MichaelE2 It doesn't seem to be the case. If I try to NIntegrate F, as I want to do, the response comes back Null when this error has appeared – user70153 Apr 20 '20 at 12:46
  • 1
    Then I think setting "these things" to zero is not what you want to do, OR, "these things" are not what I think they are. What are they? (Can't really help with NIntegrate without code to reproduce the problem.) – Michael E2 Apr 20 '20 at 12:47
  • This goes back to what I said earlier: without anything other people can evaluate in their own copies of Mathematica, it's hard to say anything more helpful. – J. M.'s missing motivation Apr 20 '20 at 12:48
  • I want to interpolate a function in a, so I make a table like; {{a1,val1},{a2,val2}...}. Sometimes the vals are such that General::munflappears. I want to set those specific vals to 0, that should still give me a perfectly integrable function that I then want to integrate – user70153 Apr 20 '20 at 12:50
  • @J.M. I will try to get a minimal working example – user70153 Apr 20 '20 at 12:50
  • If T is an array of numbers (constants), then Exp[] almost certainly is what is underflowing to 0.: Exp[-800.], 7/(Exp[-800.] - 1), but 7/(1/Exp[800.] - 1). The first two show what happens when Exp[..] underflows to zero: T[[a,b,c]]/(Exp[exponent[a,b,c]]-1) should evaluate to -T[[a,b,c]]. But you want it to evaluate to zero, right? – Michael E2 Apr 20 '20 at 12:58
  • 1
    "while trying to figure out a minimal example, I found out that my main problem was actually unrelated to this" - at least you (hopefully) now understand why people should always try to find a minimal example before asking questions. ;) – J. M.'s missing motivation Apr 20 '20 at 14:17

0 Answers0