5

I'm interested in computing pointwise values of the function $u(x) = \sinh(k-kx)/\sinh(k)$ for $x \in (0,1)$, where $k = 10^{4}$. A direct computation of course results in overflow issues due to the $\exp(k)$ factor. However, $u(x)$ only takes on values between 0 and 1, so I'm wondering if there is a clever way that this quantity can be computed. We can also write $u$ as $$ u(x) = \frac{e^{k-kx}}{e^{k}-e^{-k}} - \frac{e^{kx-k}}{e^{k}-e^{-k}}. $$

I thought to try taking logarithms first and seeing if anything simplifies, but I wasn't able to make progress. Does anyone have suggestions for how I can get numerical pointwise values of this function? I'm aware that the function is essentially 1 at $x=0$ and 0 elsewhere, but I'm curious about the original problem.

Richard Zhang
  • 2,485
  • 15
  • 26
Justin Dong
  • 937
  • 6
  • 14

2 Answers2

6

My idea is the approximation $\exp(k)-\exp(-k)\approx \exp(k)$ for large positive values of $k$. But instead, we can just divide the numerator and denominator by $\exp(k)$ and get an exact expression $$\frac{\exp(k-kx)-\exp(kx-k)}{\exp(k)-\exp(-k)} = \frac{\exp(-kx)-\exp(k(x-2))}{1-\exp(-2k)} $$ which should be okay to evaluate without overflow. (Note this is exactly the same technique used to evaluate the log-sum-exp function without overflow.)

Richard Zhang
  • 2,485
  • 15
  • 26
2

Under assumptions you give for $x$ and I assume $k$ to be positive as well, you can calculate an asymptotic expansion for this function for $k\to\infty$: $$u(x) \sim e^{-kx} - e^{-k(2-x)} + e^{-k(2+x)} -e^{-k(4-x)} +e^{-k(4+x)} + \ldots $$ from which you can see that if $k$ is large enough (and $10^{4}$ certainly is), only the first term is significant.

GertVdE
  • 6,179
  • 1
  • 21
  • 36