Reworking a large exponential function to fit within a float64

43 Views Asked by At

I'm trying to write a code for the following equation:

$x = {A e^ {b (t - t0)} \over {1 + e^ {c (t - t0)}}}.$

The problem is I end up getting values for both exponentials that are too large to fit within a float64, even though the comparison of numerator and denominator results in a reasonable value. $A$, $b$, $c$, and $t0$ are all constants. $b$ and $c$ are large while $t0$ is small, but not as small as $b$ and $c$ are large, so beyond a certain value of $t$ the exponential grows too large to calculate.

exp(709) = 8.218e+307, and exp(710) = inf

How can I go about reworking this formula so that I can get a valid output?

1

There are 1 best solutions below

1
On BEST ANSWER

Since the exponentials are getting large, it may be safe to ignore the +1 in the denominator and simplify the expression to:

$x \approx \frac{Ae^{b(t-t(0)}}{e^{c(t-t(0)}} = Ae^{(b-c)(t-t(0))}$. This should definitely give you a larger dynamic range to operate with (depends on what $b-c$ looks like). The question you have to answer is whether this approximation error is acceptable for your application.