1 Introduction

The hyperbolic Kepler’s equation (HKE)

$$\begin{aligned} e \; \sinh F - F = M, \end{aligned}$$
(1)

defines the hyperbolic eccentric anomaly F of a hyperbolic Keplerian orbit with eccentricity \( e>1\) as a function of the hyperbolic mean anomaly \( M \in \mathbb {R}\). Here the eccentricity will be assumed \( e \in (1, + \infty )\), and because \(M(F) = -M(-F)\), we consider the hyperbolic mean anomaly \( M \ge 0\).

It is worth remarking that there are several alternative formulations of (1). Thus, putting \( \gamma = 1/e\) and \( L = M/e\), Eq. (1) can be written in the equivalent form

$$\begin{aligned} \sinh F - \gamma \; F = L, \quad \hbox {with} \; \gamma \in (0,1), \quad \hbox {and} \; L \ge 0, \end{aligned}$$
(2)

which has been used for computational reasons by several authors, see, e.g., Gooding and Odell (1988), Fukushima (1997), Raposo-Pulido and Peláez (2018). On the other hand, introducing the new variable \( U = \sinh F\) the equation (1) can be written as

$$\begin{aligned} e \; U - \text {arcsinh} \;{U}= M. \end{aligned}$$
(3)

Now if \( U_0 = U(M_0,e_0)\) is the solution of (3) corresponding to the values \( e= e_0\) and \( M = M_0\), in view of (1) we have that

$$\begin{aligned} F_0 = F(M_0, e_0) = - M_0 + e_0 \; \sinh F_0 = - M_0 + e_0 \; U_0 \end{aligned}$$
(4)

is the solution of (1) corresponding to the same values \( M= M_0\) and \( e= e_0\). This alternative form (3) of HKE has been used by some authors (Gooding and Odell 1988) in some iterative methods for solving the HKE obtaining better results than when using the form (1) because, as it is known, the convergence of the iterations generally depends on the choice of the variables.

Usually, the solution of (1) is carried out by an iterative method so that for an accurate starting value of \( F = F^{[0]} = F^{[0]} (M,e) \) and an iteration function \( \Phi \), a sequence \( \{ F^{[j]}\}_{j \ge 0}\) with \( F^{[j+1]}= \Phi ( F^{[j]})\) is defined that converges to the unique exact solution of (1) for the corresponding parameters M and e. In particular, for the well-known Newton’s method the iteration function is

$$\begin{aligned} \Phi (U) = U - \displaystyle \frac{( e \; \sinh {U} - U -M )}{( e \cosh {U} -1)}, \end{aligned}$$

which has quadratic convergence. An extensive study of starting values and iterative methods for the HKE has been carried out in the references (Gooding and Odell 1988; Fukushima 1997; Farnocchia et al. 2013; Avendaño et al. 2015; Raposo-Pulido and Peláez 2018; Calvo et al. 2019).

Moreover, several analytical solutions of HKE have been proposed. Thus, (Ebaid et al. 2017) gives a solution of HKE (3) written in the form

$$\begin{aligned} U = L + \gamma \; \text {arcsinh} \; U, \end{aligned}$$
(5)

as a power series in \( \gamma = 1/e \in (0,1)\)

$$\begin{aligned} U ( L; \gamma ) = L + \sum _{k \ge 1} \gamma ^k \; U_k (L), \end{aligned}$$
(6)

where the coefficients \( U_k\) are computed recursively by substitution of (6) in (5). Then truncating the series (6) at a certain term, one gets an approximate solution of HKE in the form (5). Clearly, this solution provides good accuracy when \( \gamma \) is small but for \( \gamma \) close to one, i.e., for almost rectilinear hyperbolic orbits the accuracy is not good even with many terms. The radius of convergence of (6) is not well-understood, and we note that the same approach for the elliptic Kepler equation provides a power series in terms of elliptic eccentricity that is not convergent for all \( e \in (0,1)\); see, e.g., Battin (1999).

Recently, following a technique used by Ullisch (2020) for solving the classical geometric goat problem, the solution of an analytic complex-valued equation \( f(z) = 0 \) that possess an isolated zero \( z_0\) can be written as the quotient of two contour integrals in the form

$$\begin{aligned} z_0 = \displaystyle \frac{\displaystyle \oint \displaystyle \frac{z \; \text {d} z}{f(z)}}{\displaystyle \oint \displaystyle \frac{\text {d} z}{f(z)}}, \end{aligned}$$
(7)

along a Jordan curve \( \mathcal {C} \) enclosing \( z_0\), and such that \( z_0\) is the only zero in the interior of \( \mathcal {C} \).

This formula is derived directly from a theorem of Jackson (1916):

Theorem 1

Let \(U \subseteq \mathbb {C}\) be an open simply connected subset and \(f: U \longrightarrow \mathbb {C}\) a nonzero analytic function. For every simple zero \(z_{0} \in U\) of f, there is a closed curve C in U that does not contain other zeros of f than \(z_0\), such that

$$\begin{aligned} \oint _{C}\displaystyle \frac{(z - z_0)\, \text {d} z}{f(z)} = 0. \end{aligned}$$

The proof of this theorem is easy, based on Cauchy’s integral theorem, and can be found in Ullisch (2020).

As for the elliptic Kepler equation (KE), based on the solution proposed by Slepian and Philcox (2023) in an earlier paper on spherical homologous collapse (\(u + \sin u = \tau \)), Philcox et al. (2021) give an explicit solution of it by taking as function f the analytic function \( f(z)= z - e \; \sin z -M\), where \( e \in (0,1)\) is the eccentricity of the elliptic orbit and \( M \in (0, \pi )\) is the mean anomaly, with suitable circular contours \( \mathcal {C} = \mathcal {C} (M,e)\) around the unique real solution. It is found that Eq. (7) not only is a beautiful mathematical expression of the solution of KE, but also by using a suitable quadrature rule related to the fast Fourier transform (FFT), provides an accurate and efficient procedure for solving the elliptic KE. A detailed study of the complex zeroes of the elliptic KE and the suitable contours in Eq. (7) as well as the efficient implementation of Eq. (7) has been considered by the authors by Calvo et al. (2023) who give an algorithm even more accurate and faster than the method in Philcox et al. (2021). We obtained in Calvo et al. (2022) similar results in using formula (7) for solving a similar equation to the KE, emanating from the collapse’s radial evolution in time (Slepian and Philcox 2023). We proved that the shorter the length of the Jordan curve the better accuracy is attained, and that the speed in the computations depends on the numerical quadrature formula used.

Motivated by the advantages of the algorithm given in Calvo et al. (2023) for the elliptic Kepler’s equation, we propose to study the solution of the hyperbolic Kepler’s equation by using the same approach. Now the corresponding function f with the formulation (1) is

$$\begin{aligned} f(z; M, e ) \equiv e \; \sinh z - z - M, \quad \text{ with } (M,e) \in \mathcal {D} = (0, + \infty ) \times (1, + \infty ). \end{aligned}$$
(8)

It is well known, see, e.g., Battin (1999), that for all \( (M,e) \in \mathcal {D} \) the HKE \( f(z; M, e )=0\) has a unique real zero, but for the application of Eq. (7) it is necessary to define appropriate contours \( \mathcal {C} = \mathcal {C} (M,e) \) that do not include other complex zeros in their interior. Thus, we will study in Sect. 2 the complex zeros of the HKE for \((M,e) \in \mathcal {D}\).

Next we will see (Sect. 3) that elliptic contours

$$\begin{aligned} \mathcal {C}_{\varepsilon } = \mathcal {C}_{\varepsilon } (M,e) = \Big \{ z = \mu + \rho \; \left( \cos \theta + i \; \varepsilon \sin \theta \right) \;; \; \theta \in [ 0, 2\pi ] \Big \}, \end{aligned}$$
(9)

with center \( \mu = \mu (M,e)\) and semi-axes \( \rho \) and \( \rho \, \varepsilon \) with (\( \rho = \rho (M,e)\) and \( 0 < \varepsilon \le 1\)) are suitable for formula (7) for all \( (M,e) \in \mathcal {D} \) by taking the ellipticity parameter \( \varepsilon \) in Eq. (9) sufficiently small.

The numerical approximation of the contour integrals of Eq. (7) for the function f of Eq. (8) and the contours (9) is considered. Taking into account the symmetries of the integrand, an efficient integration with the composite trapezoidal rule is proposed. Such a rule has the additional advantage that it exhibits spectral convergence behavior as a function of the number of nodes of the quadrature rule. Finally, some numerical experiments are presented to show the accuracy and efficiency of this numerical approximation of the integral expression of the solution of the HKE.

2 The complex zeroes of HKE

In order to apply Eq. (7) to have the solution \(z_0\) of the HKE (8) with \( (M,e) \in \mathcal {D} \), it is necessary to define a closed contour \(\mathcal {C}\) that contains no other zero of Eq. (8) except the sought \(z_0\). Let us recall that Theorem 1 works on the complex plane; hence, before defining a contour, we should know where the possible complex zeroes of Eq. (8) are located so that the chosen contour satisfies the conditions of Theorem 1.

Proceeding similarly as in Philcox et al. (2021), we put \( z = x + i \; y\) with \( x,y \in \mathbb {R}\) and \( i \in \mathbb {C}\); hence,

$$\begin{aligned} f(z;M,e) = ( e \sinh x \cos y - x- M)+ i \; ( e \cosh x \sin y -y), \end{aligned}$$

then \(z= x + i \; y\) is a zero of the HKE (10) if and only if the real numbers x and y satisfy

$$\begin{aligned} e \sinh x \cos y - x- M= 0, \quad e \cosh x \sin y -y = 0. \end{aligned}$$
(10)

First of all, observe that if (xy) is a solution of Eq. (10), \((x,-y)\) is also a solution of these equations, i.e., the complex solutions appear in conjugate pairs and then we may consider only \( y>0\). Moreover, if (xy) is a solution corresponding to some M and e, \((-x,y)\) is also solution corresponding to \(-M\) and e, then we may assume \( x>0\).

Furthermore, note that for all \( (M,e) \in \mathcal {D}\) there is a unique real \( x^* = x^*(M,e)\) such that \( f(x^*;M,e)=0\). Also \(x^*\) is a monotonically increasing function of M and also is a monotonically decreasing function of e.

From the first equation of (10), it follows that

$$\begin{aligned} \cos y = g(x; M,e) \equiv \displaystyle \frac{x+M}{e \; \sinh x}. \end{aligned}$$
(11)

Note that for all \( (M,e) \in \mathcal {D}\) and \( x >0\), the real function \( g(x; M,e) > 0\); it is a monotonically decreasing function of x; and

$$\begin{aligned} \lim _{x \rightarrow 0} g(x;M,e)= + \infty , \quad \lim _{x \rightarrow + \infty } g(x;M,e)=0; \end{aligned}$$

hence, there exists a unique value \(x^*\) such that \(g(x^*; M,e)=1\), and therefore, \( 0< g(x;M,e) \le 1\) if and only if \( x \ge x^* = x^*(M,e)\). Consequently, formula (11) defines \( y>0\) as a multivalued function of x by

$$\begin{aligned} y = y_k(x;M,e) = \arccos \left[ g(x; M,e) \right] + 2 k \pi , \,\, \forall \, x \ge x^* \hbox {and} \,\, k=0,1, \ldots \end{aligned}$$

Hence, for all \( (M,e) \in \mathcal {D}\), the solutions of the first equation of (10) are

$$\begin{aligned} (x, y_k(x;M,e)) \quad \hbox {with } x \ge x^* \hbox { and } \,\, k=0,1, \ldots \end{aligned}$$
(12)

Next, we study whether or not Eq. (12) satisfies the second equation of (10). We make the analysis separately for \( k=0\) and for \( k > 0\).

  1. a)

    For \( k=0\) the solution of Eq. (11), \( y_0= \arccos \left[ g(x;M,e) \right] \) when substituted in the second equation of (10) gives the function

    $$\begin{aligned} h(x) = e \cosh x \,\sin \big (\arccos \left[ g(x;M,e) \right] \big ) - \arccos \left[ g(x;M,e) \right] . \end{aligned}$$

    Let us put the function h(x) in the form

    $$\begin{aligned} h(x) = e \cosh x \, \sqrt{1 - g(x)^2} - \arccos g(x). \end{aligned}$$

    Its derivative is

    $$\begin{aligned} h'(x) = e \sinh x \, \sqrt{1 - g(x)^2} + (1 - e \cosh x ) \displaystyle \frac{g'(x)}{\sqrt{1 - g(x)^2}}, \end{aligned}$$

    and since

    $$\begin{aligned} g(x) = \displaystyle \frac{(M + x)}{e \sinh (x)}, \quad g'(x) = \displaystyle \frac{1}{e \sinh (x)}(1 - (M + x)\coth x), \end{aligned}$$

    we find that

    $$\begin{aligned} h'(x) = e \sinh x \, \sqrt{1 - g(x)^2} + \displaystyle \frac{(-1 + (M + x)\coth x)^2)}{e \sinh (x) \sqrt{1 - g(x)^2}} > 0. \end{aligned}$$

    Thus, this function h(x) is monotonically increasing and vanishes at \(x = x^*\) (recall that for \(x = x^*\), \(y_0 = 0\)). In consequence, if \(k=0\) for all \((M,e) \in \mathcal {D}\) there exists only one solution of the system (10), namely \(x = x^*(M,e)\), \(y = y_0 = \arccos g(x^*; M,e) =0\), and it is real.

  2. b)

    For \( k >0\), \( y_k(x;M,e)>0\), and the second equation of (10) can be written in the equivalent form

    $$\begin{aligned} e \cosh x = \displaystyle \frac{y_k(x;M,e)}{\sin \left[ y_k(x;M,e)\right] } \equiv G_k(x;M,e), \quad \text{ with } x > x^* \end{aligned}$$
    (13)

    and

    $$\begin{aligned} G_k(x;M,e) = \displaystyle \frac{\arccos \left[ g(x;M,e) \right] + 2 k \pi }{\sin \big (\arccos \left[ g(x;M,e) \right] \big )}. \end{aligned}$$

    Now the left-hand side, \( e \cosh (x)\), of (13) is a monotonically increasing function of x for all \(x > x^*\) with

    $$\begin{aligned} \lim _{x \rightarrow x^*} e \cosh x = e \cos x^*, \quad \lim _{x \rightarrow + \infty } e \cosh x = + \infty . \end{aligned}$$

    On the other hand, the function \( G_k(x;M,e) \) of (13) is a monotonically decreasing function of x for all \(x > x^*\) with

    $$\begin{aligned} \lim _{ x \rightarrow x^*} G_k(x; M,e) = + \infty , \quad \lim _{ x \rightarrow +\infty } G_k(x; M,e) = \displaystyle \frac{\pi }{2} + 2 k \pi . \end{aligned}$$

    Hence, for all \( (M,e) \in \mathcal {D}\) and \( k=1,2, \ldots \) the equation (13) has a unique solution \( x = x_k (M,e) > x^*(M,e)\), namely the intersection of two functions, one (\(e \cosh x\)) that is increasing and the other that decreases (\( G_k(x; M,e)\)). In conclusion for all \( (M,e) \in \mathcal {D}\) and \( k=1,2, \ldots \), the equations (10) have a unique solution

    $$\begin{aligned} z_k = x_k + i \; y_k \quad \hbox {with} \quad y_k = \arccos \left[ g (x_k; M,e) \right] + 2 k \pi . \end{aligned}$$
    (14)

    Finally, observe that all these complex solutions have

    $$\begin{aligned} \hbox {Im } z_k = y_k > 2 k \pi , \quad \hbox {for all} \; k=1,2, \ldots \end{aligned}$$

In Fig. 1 we display the real (for \(k=0\)) and complex solutions of the HKE for \(e=1.1\) and the values of \(M= j/2\), with \(j=1, \ldots ,100 \) and \( k=1,2,3,4\). As can be seen for \(k=1,2,3,4\) the imaginary parts \(y_k\) of the solutions \( z_k\) exceed \( 2 k \pi \).

As a conclusion of the above study, we may state the following:

Proposition 1

The complex solutions of the HKE have the properties:

  1. 1.

    If \( z= x+ i y\) is a solution, then its conjugate \( \overline{z}= x - i y\) is also a solution.

  2. 2.

    For all \( (M,e) \in \mathcal {D}\), there is a countable infinite set of zeroes given by (14).

  3. 3.

    For all \( (M,e) \in \mathcal {D}\), the complex zero with smallest positive imaginary part is \( z_1\) and Im \(z_1 > 2 \pi \).

Remark

The complex zeroes \(w_k= w_k(M,e)\) of the equivalent form (3) of HKE \( \widetilde{f}= (w;M,e)= e w - \sinh ^{-1}(w)-M = 0 \) can be derived from the transformation \( z \rightarrow w \) given by \( w= \sinh z\), i.e., \(w_k = \cos y_k \sinh x_k + i \; \sin y_k \; \cosh x_k\).

Fig. 1
figure 1

Complex zeroes \(z_k = x_k + i\, y_k\) (for \(k=0,\ldots ,4\)) of the HKE given in Eq. (14) for \(e= 1.1\), and several values of \(M = j/2\) (\(j=1,\ldots \), 100). For \(k = 0\) all zeroes \(z_0\) are real numbers, whereas for \(k > 0\) all the zeroes have imaginary part. Note that the complex zero with smallest positive imaginary part is \( z_1\), with Im \(z_1 > 2 \pi \); hence, it is a sufficient condition that the Jordan curve \(\mathcal {C}\) does not cross this horizontal line to guarantee that there is no other complex zero on its interior

3 The Jordan contours for the integral solution of HKE

In a recent work (Calvo et al. 2023), we proved that the use of elliptical contours instead of circles as Jordan curves was more convenient, because as its length is smaller, it provides more accuracy and the numerical computation is faster. Then, here we will consider elliptical contours

$$\begin{aligned} \mathcal {C}_{\varepsilon } = \Big \{ z = z_{\varepsilon } = \mu + \rho \, \left( \cos \theta + i \, \varepsilon \, \sin \theta \right) \;; \; \theta \in [ 0, 2\pi ] \Big \}, \end{aligned}$$
(15)

of center \( \mu \) and semi-axes \( \rho \) and \( \rho \, \varepsilon \) where \( \varepsilon \in (0,1]\) is a parameter to be chosen sufficiently small so that for each \( ( M,e) \in \mathcal {D} \), the ellipse \( \mathcal {C}_{\varepsilon }\) contains the unique real solution of HKE corresponding to these parameters.

To define the center \( \mu \) and the semimajor axis \( \rho \), we need to give some upper \(( x^{+})\) and lower \(( x^{-})\) bounds for the exact real solution of HKE for \( (M,e) \in \mathcal {D} \).

By expanding \(e \sinh x - x\) in a power series in x, we have

$$\begin{aligned} M = e \sinh x - x = e \left( x + \displaystyle \frac{x^3}{3!} + \displaystyle \frac{x^5}{5!} + \ldots \right) -x > \max \left\{ (e-1) x, e \; \displaystyle \frac{x^3}{3!}, e \; \displaystyle \frac{x^5}{5!}, \ldots \right\} , \end{aligned}$$

leading to the upper bound

$$\begin{aligned} x < x^{+} = \min \left\{ M/ (e-1), \, \left( 3! M / e \right) ^{1/3}, \, \left( 5! M /e \right) ^{1/5}, \ldots \right\} . \end{aligned}$$
(16)

Taking into account that on a logarithmic scale the functions of \(\overline{M} = (M/e) \) in the right-hand side of (23), \( (3! M/e)^{1/3}, (5! M/e)^{1/5}, \ldots \) are straight lines with slopes \(1/(2k-1),\) \(k=2, 3, \ldots \) that cut each other, by putting

$$\begin{aligned} f_k( \overline{M} ) = \left[ ( 2 k-1)! \, \overline{M}\right] ^{1/(2k-1)}, \quad k=2,3, \ldots \end{aligned}$$

it is easy to check that the unique \(\overline{M}\) such that \( f_k (\overline{M}) = f_{k+1} ( \overline{M})\) is

$$\begin{aligned} \overline{M} = \displaystyle \frac{\left[ 2k ( 2 k+1)\right] ^{k-1/2}}{(2k-1)!} \equiv \eta _k, \quad k=2,3, \ldots \end{aligned}$$

Moreover, since

$$\begin{aligned} \eta _{k+1} = \eta _k \left[ \displaystyle \frac{(2k+2)(2k+3)}{2k ( 2k+1)} \right] ^{k+ 1/2}, \end{aligned}$$

the real sequence \( \{\eta _k\}_{k \ge 2}\) is monotonically increasing with \( \lim _{k \rightarrow + \infty } \eta _{k+1}/ \eta _k = \exp [2] \). The first few values of this sequence are

$$\begin{aligned} \eta _2 = 14.9071\ldots ,\; \eta _3 = 95.2669\ldots ,\; \eta _4 = 628.3960\ldots ,\; \eta _5 = 4231.5946\ldots \end{aligned}$$

Therefore, we can bound \(x^+\) by the piecewise function:

$$\begin{aligned} {x}^+(M,e)=\left\{ \begin{array}{lll} \displaystyle \frac{M}{e-1} &{} \text {if} &{} M \le \displaystyle \frac{\sqrt{6} (e-1)^{3/2}}{\sqrt{e}}, \\ \left( {3! \, M / e} \right) ^{1/3} &{} \text {if} &{} \displaystyle \frac{\sqrt{6} (e-1)^{3/2}}{\sqrt{e}}< M \le \eta _2\, e,\\ \left( {5! \, M / e} \right) ^{1/5} &{} \text {if} &{} \eta _2 \,e< M \le \eta _3 \,e,\\ \left( {7! \, M / e} \right) ^{1/7} &{} \text {if} &{} \eta _3 \, e < M \le \eta _4 \,e, \quad \ldots \\ \end{array} \right. \end{aligned}$$
(17)

Thus, depending on the values of M and e we can take \( x^+\) to be the smallest value on the right-hand side of (17). See Fig. 2 as an illustration of the interval limits.

Fig. 2
figure 2

Functions \(M/(e-1)\) (blue) \(f_2(M/e)\) (orange), and \(f_3(M/e)\) (green) for \(e=1.5\). Hence, there will be different Jordan ellipses for \(0\le M < {\sqrt{0.5}}\) (intersection of blue and orange lines), and for \(\sqrt{0.5} \le M < \sqrt{500}\) (intersection of orange and green lines), and so on. The center and semi-major axis of the ellipses are given by Eq. (19)

On the other hand, \(M = e \sinh x - x < e \sinh x\), recalling that \(x >0\), which implies

$$\begin{aligned} x > \sinh ^{-1} \left( M /e \right) = x^{-} (M,e). \end{aligned}$$
(18)

From (16) and (18), it follows that \(x^+> x > x^{-}\) for all \( (M,e) \in \mathcal {D} \) and then

$$\begin{aligned} \mu = \displaystyle \frac{x^+ + x^{-}}{2}, \quad \rho = \displaystyle \frac{x^+ - x^{-}}{2}, \end{aligned}$$
(19)

and the contour will be admissible for the integral expression (7) if \( \varepsilon \,\rho < 2 \pi ; \) just as follows from Proposition 1, this guarantees that no complex zero is inside the contour \( \mathcal {C} _{\varepsilon }\).

For the contour (15) the integral solution (7) becomes

$$\begin{aligned} F= & {} \mu + \rho \; \displaystyle \frac{\displaystyle \int _{0}^{2\pi } ( \varepsilon \cos \theta + i \sin \theta ) ( \cos \theta + i \,\varepsilon \sin \theta ) G( \theta ) \;\text {d} \theta }{\displaystyle \int _{0}^{2\pi } ( \cos \theta + i \,\varepsilon \sin \theta ) G( \theta ) \;\text {d} \theta } \nonumber \\= & {} \mu + \rho \; \displaystyle \frac{\displaystyle \int _{0}^{2\pi } ( \varepsilon \cos 2 \theta + i \; ( ( 1 + \varepsilon ^2)/2) \sin 2 \theta )\, G( \theta ) \;\text {d} \theta }{\displaystyle \int _{0}^{2\pi } ( \cos \theta + i \, \varepsilon \sin \theta ) \, G( \theta ) \;\text {d} \theta }, \end{aligned}$$
(20)

where

$$\begin{aligned} G( \theta ) = \left[ f( z_{\varepsilon } ) \right] ^{-1} = \left[ e \sinh ( z_{\varepsilon }) - z_{\varepsilon } - M \right] ^{-1}, \end{aligned}$$
(21)

with \( z_{\varepsilon } = \mu + \rho ( \cos \theta + i \; \varepsilon \sin \theta )\).

Observe that \( G( \theta )\) is a complex \( 2 \pi \)-periodic function of \( \theta \) that depends also on \( e >1\), \( M >0\), and \(\varepsilon \in (0,1]\); these last can be considered as real parameters independent of \( \theta \). A straightforward calculation shows that the real and imaginary parts of \( G( \theta )\) satisfy

$$\begin{aligned} \hbox {Re} [ G ( \theta )] = \hbox {Re} [ G ( -\theta )], \quad \hbox {Im} [ G ( \theta )] = - \hbox {Im} [ G (- \theta )], \end{aligned}$$
(22)

and therefore, the integrals in the numerator and denominator of (20) are real and this integral expression can be written in the equivalent form

$$\begin{aligned} F =\mu + \rho \; \displaystyle \frac{\displaystyle \int _{0}^{2\pi } \hbox {Re} \Big [( \varepsilon \cos 2 \theta + i \; ( ( 1 + \varepsilon ^2)/2) \sin 2 \theta )\, G( \theta )\Big ] \;\text {d} \theta }{\displaystyle \int _{0}^{2\pi } \hbox {Re} \Big [( \cos \theta + i \, \varepsilon \sin \theta ) \, G( \theta )\Big ] \;\text {d} \theta }. \end{aligned}$$
(23)

Another important remark is that the integral expression (23) can be written in terms of the Fourier coefficients of the function \( G = G(\theta )\) defined by

$$\begin{aligned} \widehat{G}(k) = \displaystyle \frac{1}{2 \pi } \int _{0}^{2\pi } \exp ( - i \, k \, \theta ) \; G( \theta ) \;\text {d} \theta . \end{aligned}$$
(24)

As a matter of fact, from \( \widehat{G}(-1)\) and \(\widehat{G}(1)\) we get

$$\begin{aligned} \widehat{G}(-1) + \widehat{G}(1) = \displaystyle \frac{1}{\pi } \displaystyle \int _{0}^{2\pi } \cos ( \theta ) \; G( \theta ) \;\text {d} \theta , \quad \widehat{G}(-1) - \widehat{G}(1) = \displaystyle \frac{i}{\pi } \displaystyle \int _{0}^{2\pi } \sin ( \theta ) \; G( \theta ) \;\text {d} \theta , \end{aligned}$$

and from both, it follows that the denominator of (20) is

$$\begin{aligned} (1 + \varepsilon ) \widehat{G}(-1) - ( 1 - \varepsilon ) \widehat{G}(1), \end{aligned}$$

and similarly the numerator

$$\begin{aligned} \displaystyle \frac{1}{2}(1 + \varepsilon )^2 \; \widehat{G}(-2) - \displaystyle \frac{1}{2} (1 - \varepsilon )^2\; \widehat{G}(2), \end{aligned}$$

which gives the alternative integral expression

$$\begin{aligned} F =\mu + \displaystyle \frac{\rho }{2} \; \displaystyle \frac{ {(1 + \varepsilon )^2} \; \widehat{G}(-2) -{(1 - \varepsilon )^2} \; \widehat{G}(2) }{(1 + \varepsilon ) \widehat{G}(-1) - ( 1 - \varepsilon ) \widehat{G}(1)}. \end{aligned}$$
(25)

This is the exact solution of the HKE in terms of the Fourier coefficients \(\widehat{G}(k)\), \(k=\pm 1, \pm 2 \), of the function G. In particular, for the circular contour (\(\varepsilon = 1\)) Eq. (25) reduces to

$$\begin{aligned} F =\mu + \rho \; \displaystyle \frac{ \widehat{G}(-2) }{ \widehat{G}(-1) }, \end{aligned}$$

that only involves the Fourier coefficients for \(k = -2,-1\).

An obvious approximation of F is to substitute in its expression (25) the Fourier coefficients \( \widehat{G}(k)\) by their discrete counterparts \( \widehat{G}_h(k)\) computed by an standard solver of the FFT. This solution is simple in the sense that uses well-known solvers but they compute not only the \( \widehat{G}_h(k)\) for \( k = \{\pm 2, \pm 1\}\) but all coefficients \( \widehat{G}_h(k)\) for \( \vert k \vert \le N\) with some N, which will result in extra computing time. To overcome this inconvenience, we propose a specific calculation of \( \widehat{G}_h(k)\) for \( k=\{\pm 2,\pm 1 \}\) with some additional simplifications that take into account the symmetries of \( G ( \theta )\).

To approximate the integrals in (23), we use the composite trapezoidal rule because it is well known (Trefethen 2000; Johnson 2021) that for such a rule, the errors in the approximations of numerator and denominator of (23) with \( N= 2 K\) nodes behave as \( \exp \left[ - \alpha N \right] \), \( N \rightarrow + \infty \) with some positive constant \( \alpha = \alpha (M,e)\). Recall that in the composite trapezoidal rule given an (even) positive integer K the integral

$$\begin{aligned} I[ g] = \int _0^{\pi } g(\theta ) \; \;\text {d} \theta , \end{aligned}$$

is approximated by

$$\begin{aligned} I_K [g] = \left( \displaystyle \frac{\pi }{ 2 K } \right) \left[ g ( \theta _0) + 2 \sum _{j=1}^{K-1} g ( \theta _j) + g( \theta _K) \right] , \end{aligned}$$
(26)

with \( \theta _j = j \,\pi / K, \quad j=0,1, \ldots ,K. \)

Note that Eq. (26) is equivalent to the approximation provided by the FFT with \( N = 2 K\) and the symmetry of g reduces the computational cost by a factor of 1/2.

Remark

For the sake of completeness, we also consider another alternative method to numerically compute the quadratures, namely the mid-point quadrature formula, given by

$$\begin{aligned} I_{\small {\text{ MP }}}[g] = \frac{\pi }{K-1} \sum _{j=0}^{K-1} g\left( \theta _j+ \pi /(2K-2) \right) , \end{aligned}$$
(27)

which is also easy to program, with similar results as the composite trapezoidal formula and that also has spectral convergence.

Fig. 3
figure 3

CPU time (in sec) for the Jordan curve \({{\mathcal {C}}}_1\) for \(2\le K \le 64\) and the different methods considered. For each K we compute ten times the solution for a vector with 10 000 components, and then, we plot the arithmetic mean of the computing time used

To compare the computational cost of the different procedures, in Fig. 3 we present a comparison of the computing time between the FFT, the trapezoidal rule in the interval \([0,2\pi ]\), and the optimized trapezoidal rule in \([0,\pi ]\) using the symmetry of the integrand. For each K we compute ten times the solution for a vector with 10000 components, and then, we plot the arithmetic mean of the computing time used. We can observe that although the four considered methods are very fast, the optimized trapezoidal and midpoint rules are faster than the other two, and that the FFT has the worst behavior, especially when K is a prime integer, the fact that is well known for the FFT algorithm. Computations have been carried out in double-precision arithmetic on a single 2.4 GHz PC Intel i7-5500U running on Linux.

We just see that the method is very fast, but still we know little on the accuracy and how the eccentricity of the Jordan ellipses affects it. Next, we present the results of some numerical experiments to show the accuracy of the numerical solution given by the Trapezoidal rule (26) for several integer values of K and the Jordan curves \({{\mathcal {C}}}_{\epsilon }\), for \(\epsilon = \{1,1/2, 1/4, 1/8, 1/128\}\). For the sake of illustrating the shape of the Jordan curves used, we plot them in Fig. 4 for these values of \(\varepsilon \). Note that \(\varepsilon =1\) corresponds to a circle, whereas the last used value, \(\varepsilon = 1/128\), is almost a rectilinear segment.

Let us note that using elliptical contours instead of circular ones does not speed up the computation, but it improves the accuracy.

Fig. 4
figure 4

Plots of the Jordan curves \({{\mathcal {C}}}_\varepsilon \) for \(\epsilon = \{1,1/2, 1/4, 1/8, 1/128\}\), the values used in the numerical experiments. Note that for \(\varepsilon =1\) the curve is a circle, whereas for the smallest used value, \(\varepsilon = 1/128\), is a very eccentric ellipse, almost a rectilinear segment

In Figs. 5 and 6 we present the numerical results of the absolute error near the singularity located at \((M,e) = (0,1)\) taking \(K = 4\) and \(K = 8\) points for a fixed value \(e=1.1\) and \(0< M < 0.2\). Due to the proximity to the singularity \((M,e) = (0,1)\) of the HKE, one expects that the results will be no good; however, we see that even for only \(K=4\) points, we always reach more than 6 digits of precision, which improves in the case of \(K = 8\).

Fig. 5
figure 5

Absolute errors of the approximate solution with \(K = 4\) for the elliptical contours \({\mathcal {C}}_{\varepsilon }\) near the singularity \((M,e) = (0,1)\). Note that the value \(\varepsilon = 1\) corresponds to a circle and that \(\varepsilon = 1/128\) gives a very eccentric Jordan contour

Fig. 6
figure 6

Absolute errors of the approximate solution with \(K = 8\) for the elliptical contours \({\mathcal {C}}_{\epsilon }\) near the singularity \((M,e) = (0,1)\)

Besides, in Figs. 7 and 8 we present absolute errors obtained in the interval (0, 10] for the hyperbolic mean anomaly \(0< M \le 10\), and eccentricity \(e=1.1\) for the same Jordan ellipses and for same number of points used in the trapezoidal rule (\(K = 4\) and \(K = 8\)). In this case, because M is far from the singularity the obtained precision dramatically increases; we reach 10 significant digits with only \(K = 4\) points and 20 digits with \(K = 8\). Even more, as expected, the precision increases with the eccentricity of the Jordan curves with a gain of 5 digits, and the same computational cost.

Fig. 7
figure 7

Absolute errors of the approximate solution for \(e = 1.1\) and \(M \in (0,10]\) for five Jordan contours \({\mathcal {C}}_{\epsilon }\), by using only four points (\(K = 4\)) in the trapezoidal rule

Fig. 8
figure 8

Absolute errors of the approximate solution for \(e = 1.1\) and \(M \in (0,10]\) for five Jordan contours \({\mathcal {C}}_{\epsilon }\), but using now eight points (\(K = 8\)) in the trapezoidal rule

4 Conclusions

The numerical implementation of an integral solution of the HKE is considered. First of all, we give a complete study of the location of the complex zeroes of this equation in order to define appropriate contours in the integrals of this solution. Next, we define elliptic contours that are computationally much more efficient than the circular contours.

We show that with these elliptic contours the integral solution can be approximated in function of the wavenumbers \(k=\pm 1, \pm 2\) of a \(2 \pi \)–periodic function and therefore an elegant form of the approximate solution is presented. In addition, we show that a direct approach by the trapezoidal rule allows us to introduce some simplifications in this particular problem and leads to a faster implementation and retains the spectral convergence with the number of nodes.

Finally, the results of some numerical tests are presented to show the above properties. These examples show that this integral form of the solution of HKE is not only a theoretical beautiful expression but also can be used to get high accuracy solutions with a reasonable computational cost.