1

I need to express and use the following equation in Python code. However, I am getting an OverflowError when I substitute X = 340.15 in:

Y = [e^(-989)] * (X^171)

I did a quick search on Google but was unable to find out how to get the equation running.

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
john li
  • 13
  • 2
  • 3
    Does this answer your question? [OverflowError: (34, 'Result too large')](https://stackoverflow.com/questions/20201706/overflowerror-34-result-too-large) – Raymond Reddington Aug 26 '20 at 11:17

2 Answers2

0

I think its because 340.15 ^ 171 is too large. Even computers have limits

elj40
  • 46
  • 3
0

You can use decimal.Decimal to get the equation running:

import math
from decimal import Decimal

X = Decimal('340.15')
e = Decimal(math.e)

Y = pow(e, -989) * pow(X, 171)
print(Y)

Prints:

2502.699307245550715093058647

Here is solution from Wolfram Alpha to compare.

Andrej Kesely
  • 168,389
  • 15
  • 48
  • 91