1

First post, please be gentle!

I am trying to do root finding on an exponential function 1/(np.exp((j-w)/x)-1), and I find I keep getting the RuntimeWarning: overflow encountered in exp.

I understand this comes from the limitations on float64, but I can't seem to insert code to help understand where this is coming from. I have tried to include some try...except OverflowError blocks to give me a peek inside where this keeps happening, but it never seems to catch this.

I have ideas on how to handle it, as long as I can get my code to do something different when it encounters overflows.

Thanks in advance!

  • Welcome to Stack! What IDE are you using? My approach is to hook into the library code and debug from there instead of `try/except` on the user side. Before I answer, is that an acceptable solution path for you? – zerecees Apr 23 '20 at 06:04
  • Thanks for the quick reply! Im using vim to write code and run it with my python on my terminal. I would tell you that is acceptable if I know what that meant! Sorry, I have a very ad hoc understanding of coding based mostly on trial and error, rather than a formal education of computer systems! – Window Licker Apr 23 '20 at 06:28
  • 1
    Hi ! Could you post a minimal example of code, we can run, so we can give a precise answer? – Guilhem L. Apr 23 '20 at 09:16
  • Welcome to SO! This is also helpful: https://stackoverflow.com/help/how-to-ask – zabop Apr 23 '20 at 12:13
  • Hi @WindowLicker! No worries on understanding, we all start somewhere. Unfortunately, I would need to research more to get you proper code that hooks into runtime procedures. However, if you can download an IDE, say [PyCharm Community Edition](https://www.jetbrains.com/pycharm/), I can help you work through a debugger. Let me know! – zerecees Apr 23 '20 at 16:25
  • Thank you guys so much for your help. You have no idea how frustrating all this was. I really appreciate the responsiveness! – Window Licker Apr 23 '20 at 17:58

1 Answers1

1

I'm guessing the problem is that you cannot figure out when warning happens. To do that use try/except but in slightly modified way:

import warnings
warnings.filterwarnings("error")
...
try:
    1/(np.exp((j-w)/x)-1)
except RuntimeWarning:
    print(j)
    print(w)
    print(x)
    print((j-w)/x)

This should give a hint, there the problem lies

rpoleski
  • 988
  • 5
  • 12
  • THIS! Thank you so much. I couldnt figure out how to get my code to tell me when it was encountering errors. Why do all my problems have simple solutions that I can never see? Thanks, rpoleski – Window Licker Apr 23 '20 at 17:54