1 Introduction

The elliptic Kepler’s equation

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

which relates the position in an elliptic orbit with eccentricity \(e \in [0,1)\) of the two-body problem with the physical time, defines the eccentric anomaly E in terms of the mean anomaly M, and this equation has been one of the most studied transcendental equations in Celestial Mechanics along several centuries (Colwell 1993) and as remarked by R. Battin (Battin 1999, Chapter 4) is connected with the development of many mathematical topics such as Bessel functions, Fourier series, Lagrange expansion theorem and numerical approximation of functions.

Thus, the solution of (1) can be written as a sine Fourier series of M in the form

$$\begin{aligned} E = M + e \sum _{k \ge 1} \displaystyle \frac{1}{k} \; J_k (k e) \; \sin ( k M) \end{aligned}$$

where \( J_k ( \cdot )\) is the Bessel function of the first kind of order k. Also Lagrange’s approach to solving Kepler’s equation leads to the power series expansion in the eccentricity

$$\begin{aligned} E = M + e \sin M + \displaystyle \frac{e^2}{2!} \displaystyle \frac{d}{dM} ( \sin ^2 M) + \displaystyle \frac{e^3}{3!} \displaystyle \frac{d^2}{dM^2 } ( \sin ^3 M) + \ldots \end{aligned}$$

that converges for \( e < 0.66 \ldots \)

On the other hand, there are many approximations to the solution \( E= E(M;e)\) of Eq. (1) by Newton and other high-order iterative methods. In these methods for given e and M, and starting from an approximation \(E_0\) close to E(Me) a sequence \( ( E_k)_{k \ge 1}\) is defined which converges to the exact solution as fast as possible (see, e.g., Odell and Gooding (1986), Markley (1995), Fukushima (1997), Feinstein and McLaughlin (2006), Davis et al. (2010), Mortari and Elipe (2014), Calvo et al. (2013), Calvo et al. (2017), Raposo-Pulido and Peláez (2017), to mention just a few works).

In this paper we study a different approach to solve Kepler’s equation proposed in a recent paper of Philcox et al. (2021) in which they obtain an explicit formula \(E=E (M;e)\), solution of Kepler’s equation (1), following a technique used by Ullisch (2020) for solving the classical goat’s problem. This technique is based on the following theorem of Jackson (1916):

Theorem 1.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 such that

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

Note: C does not contain other zeros of f than \(z_0\).

Thus, Philcox et al. (2021) applying the above theorem shows that the solution \( E = E (M,e)\) of elliptic Kepler’s equation (1) can be given explicitly as the quotient of the two contour integrals

$$\begin{aligned} E = E(M; e) = \oint _{\mathcal {C}} \displaystyle \frac{z \; dz}{f(z)} \,\, {\Big /} \,\, \oint _{\mathcal {C}} \displaystyle \frac{dz}{f(z)} , \end{aligned}$$
(2)

where f is the analytical complex valued function of z given by

$$\begin{aligned} f(z) = f(z; M, e) = z - e \; \sin z -M, \end{aligned}$$
(3)

and \( \mathcal {C} = \mathcal {C} ( M,e) \) is a Jordan curve that encloses the unique real solution of Eq. (1), \( z= E (M,e)\) for \( (e,M) \in \mathcal {D} = (0,1) \times (0,\pi ) \), and \( f(z) \ne 0\) for all z in \( \mathcal {C}\) and its interior, except \( z = E\). Hereafter we will say that if a family of contours \( \mathcal {C} = \mathcal {C} ( M; e)\), with \( (e,M) \in \mathcal {D}\), satisfies these conditions, it is admissible for the integral solution (2).

In particular, these authors take as \( \mathcal {C}_0 = \mathcal {C} ( M,e) \) the family of circles centered at the midpoint \( \mu _0\) of M and \( M +e\) and radius \(\rho _0= e/2\), i.e.,

$$\begin{aligned} \mathcal {C}_0 = \left\{ z = \left( M + e/2 \right) + e/2 \; \exp ( i \theta ) \; ; \; \theta \in [0, 2 \pi ] \; \right\} , \end{aligned}$$
(4)

showing that this family of Jordan curves is admissible for (2). With this choice and approximating the contour integrals of Eq. (2) by some Riemann sums, it is possible to provide explicit approximate solutions of elliptic Kepler’s equation for all \( (e,M) \in \mathcal {D}\) that are faster than standard iterative methods that provide approximate solutions to the transcendental Kepler equation (1).

We already proved (Calvo et al. 2022) that for solving a similar (but simpler) formula emanating from the collapse’s radial evolution in time (Slepian and Philcox 2021), the length of the Jordan curve and the numerical quadrature formula used to compute the above line integrals have a big influence in the final result in both aspects of speed and accuracy. Thus, in this paper we study the two main issues that are relevant in the practical application of this integral solution (2), namely the choice of the Jordan curve and the numerical method to compute the line integrals in Eq. (2).

A first point is the choice of the Jordan contour \(\mathcal {C} = \mathcal {C}_{M,e}\) that is admissible for the integrals of (2). To make clear this point in Sect. 2, we study the complex zeros of \( f(z; M, e)=0\) for \( M \in (0, \pi )\) and \( e \in [0,1)\). It turns out that (2) is independent on the choice of the contour provided that it satisfies the above suitability condition but in the numerical approximation of these integrals their accuracy is much better for curves with small length. Then in Sect. 3 we focus our attention in the construction of suitable contours that minimize the length of their boundary. Several families are proposed with circular and elliptic contours.

In Sect. 4 we deal with the numerical quadrature method to compute the line integrals of Eq. (2). We study the application of the composite trapezoidal rule to approximate the integrals of (2) along suitable circular and elliptic contours. The choice of this quadrature rule is motivated because in spite of the lower order of the trapezoidal rule (second order), it is very reliable when it is used in the fast Fourier transform (FFT) and even more important, it exhibits spectral convergence with the number N of nodes, i.e., the error in the approximation of the integral of a periodic function (here the numerator or the denominator of (2)) by this quadrature rule with N nodes behaves as \( \mathcal {O} ( \exp ( - \alpha N))\) with some positive constant \( \alpha \), as we prove in Appendix A. In our case, the quadratures in (2) depend on the parameters \((e,M) \in \mathcal {D}\) and therefore \( \alpha = \alpha (M; e)\) also depends on these parameters. This spectral behavior of the numerator and denominator of (2) is inherited by the approximation \( E_N\) to E. Observe that with a standard quadrature rule with order p the error behaves as \( \mathcal {O}( N^{-p} )\) and therefore spectral convergence is much stronger than any potential convergence. We will show also that the factor \( \alpha (M; e) \rightarrow 0\) when \( (M,e) \rightarrow (1,0)\) that is the singular point of the solution \( E= E(M;e)\) of Kepler’s equation and consequently spectral convergence fails for values of (Me) close to (1, 0).

In Sect. 5 we examine several points with the purpose to make the implementation of the quadrature rules as efficient as possible. Observe that the integrals of numerator and denominator of Eq. (2) could be obtained by a FFT by using a standard routine, but this is not the most efficient way because we only need two Fourier coefficients and the remaining are not necessary. Hence, we have made a direct approach to calculate these coefficients. Finally, we present the results of some numerical experiments showing that very high accuracy can be attained with a moderate computational cost.

2 The complex zeroes of f(zMe)

Here we consider Kepler’s equation (KE): \( f(z; M,e)=0\) with complex \( z = x+ i y\), where x and y are reals and we study their solutions for the values of the parameters \( (e,M) \in \mathcal {D}\).

It is worth to remark that as shown in Wintner (page 216) the solution of KE can be considered as the determination of the inverse function \( z = z(M;e)\) of the meromorphic function \( M = z - e \sin z\), for \((e,M) \in \mathcal {D}\), and taking into account that z(Me) is a multi-valued analytic function for each \(M \in (0, \pi )\) there is an infinite set of solutions. In this section, our aim is to describe this set of solutions in order to find suitable Jordan curves for the integral solution (2).

First of all, the complex KE can be written in the form

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

therefore, \( z = x + i \; y\) is a zero of f if and only if their real and imaginary parts satisfy

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

Clearly, for \( e=0\) the equations (6) have the unique solution \( y=0\), \( x=M\); then we will consider \( e \in (0,1)\). On the other hand if \( y=0\), equations (6) reduce to the real KE \( M = x - e \sin x \) that has also a unique solution \( x \in [0, \pi ]\) for all \( e \in (0,1)\), \( M \in [0, \pi ]\). Moreover, if (xy) is a solution of (6), \( (x,-y)\) is also a solution of these equations, i.e., in the complex plane the solutions are symmetric with respect to the real axis, and if \( z \in \mathbb {C}\) is a solution then its conjugate \( \overline{z} \) is also solution. Because of this, hereafter we will consider only the case \( y>0\). Under this assumption, the first equation of (6) can be written in the equivalent form

$$\begin{aligned} \cos x = \dfrac{y}{e \; \sinh y}, \end{aligned}$$
(7)

and introducing the notation

$$\begin{aligned} g(y) \equiv \dfrac{y}{\sinh y}, \end{aligned}$$
(8)

the equation (7) can be written as

$$\begin{aligned} \cos x = \dfrac{g(y)}{e }, \end{aligned}$$
(9)

Clearly, for all \( e = e_0 \in (0,1)\), the function \( \cos x \) will be defined only for the values of y such that \( \vert g(y) \vert \le e_0\), and taking into account that when \( y>0\), the function g(y) is strict monotonic decreasing with \( g(0)=1\) and \( g (+ \infty ) = 0\), for all \( e_0 \in (0,1)\) there is a unique \( y_0 >0\) such that \( g ( y_0 ) = e_0 \) and Eq. (9) is defined only for \( y \ge y_0\). Moreover, inasmuch \( \cos x \) is an even and \( 2 \pi \)–periodic function, (9) defines x as a function of y by the multivalued function

$$\begin{aligned} x = \varphi _k^{\pm } ( y ; e_0) \equiv \pm \; \arccos \Big ( \dfrac{g(y)}{e_0} \Big ) + 2 k \pi , \quad y \ge y_0, \quad k \in \mathbb {Z}. \end{aligned}$$
(10)

Next we will substitute the function (10) into the second equation of (6) to determine the values of y that satisfy this equation. The right-hand side of this equation along the functions (10) will be denoted by

$$\begin{aligned} \psi _k^{\pm } ( y ; e_0) \equiv \varphi _k^{\pm } ( y ; e_0) - e_0 \; \sin \Big ( \varphi _k^{\pm } ( y ; e_0) \Big ) \; \cosh y, \quad y \ge y_0, \quad k \in \mathbb {Z}. \end{aligned}$$
(11)

We study firstly the function \( \psi _k^{+} (y; e_0)\). It can be seen that it is a monotonic function of y for \( y \ge y_0\). Moreover, for \( y= y_0\), \( g(y_0)=e_0\) and \( \varphi _k^{+} (y_0; k) = 2 k \pi \), which implies that

$$\begin{aligned} \psi _k^{+} ( y_0; e_0) = 2 k \pi , \,\, k \in \mathbb {Z}, \quad \textrm{and} \quad \lim _{y \rightarrow + \infty }\psi _k^{+} ( y; e_0) \rightarrow - \infty . \end{aligned}$$

Consequently, by the mean value theorem, for all \( M \in (0, \pi ]\) the equation

$$\begin{aligned} \psi _k^{+} ( y ; e_0) = M, \quad \hbox {for} \; k \in \mathbb {Z} , \end{aligned}$$
(12)

has no solution for \( k \le 0\), whereas for each \( k >0\) there exists a unique solution of (12) depending on M that will be denoted by \( y_{0,k}^{+} = y_{0,k}^{+} ( M; e_0)\), and these solutions satisfy

$$\begin{aligned} y_0< y_{0,1}^{+}< y_{0,2}^{+} < \ldots , \end{aligned}$$

i.e., \( \left( y_{0,k}^{+} \right) _{k \ge 1}\) is a monotonic increasing sequence. Hence, for each \( e_0 \in (0,1)\), \( M \in (0, \pi ]\), the complex equation (5) possesses the complex roots

$$\begin{aligned} z_k^{+} = \varphi _k^{+} ( y_{0,k}^{+} ; e_0) + i \; y_{0,k}^{+}, \quad k=1,2, \ldots \end{aligned}$$
(13)

Secondly, we consider the equations

$$\begin{aligned} \psi _k^{-} ( y ; e_0) = M, \quad y \ge y_0, \quad \hbox {for} \; k \in \mathbb {Z}. \end{aligned}$$
(14)

Now \( \psi _k^{-} ( y; e_0)\) are monotonic increasing functions of y for \( y \ge y_0\) with \( \psi _k^{-} ( y_0; e_0) = 2 \, k \ \pi \) and \( \psi _k^{-} ( y; e_0) \rightarrow + \infty \) when \( y \rightarrow + \infty \). Therefore, for \( k \ge 1\), Eq. (14) does not have solutions and for all \( k \le 0\), there is a unique solution \( y = y_{0,k}^{-} > y_0\) depending on \( M \in (0, \pi ]\) such that \(y_0< y_{0,0}^{-}< y_{0,1}^{-} < \ldots \)

Consequently, the complex equation (5) has also the complex roots

$$\begin{aligned} z_k^{-} = \varphi _k^{-} ( y_{0,k}^{-} ; e_0) + i \; y_{0,k}^{-}, \quad k=0, -1, -2, \ldots \end{aligned}$$
(15)

From this analysis we conclude

Proposition 2.1

The complex roots of complex Kepler’s Equation for \( e \in [0,1)\), \( M \in (0, \pi ]\) satisfy

  • For \( e=0\) there is a unique solution \( z=M\).

  • For all \( e \in [0,1)\), \( M \in (0, \pi ]\) there is a unique real equation.

  • If \( z \in \mathbb {C}\) is a solution of Eq. (5), then \( \overline{z}\) is also solution.

  • For \(z = x + i \; y \), with \( y>0\) and \( e \in (0,1)\), \( M \in (0, \pi ]\), there is an infinite numerable set of solutions

    $$\begin{aligned} z_0^{-} \quad \hbox {and} \quad z_k^{+}, \quad k=1, 2, \ldots , \quad \hbox {and} \quad z_k^{-}, \quad k=-1, -2, \ldots , \end{aligned}$$

    defined by (13) and (15).

Remark 1

Note that for all \( (e_0, M) \in \mathcal {D}\) we have

$$\begin{aligned} \begin{array}{ll} \hbox {Re} \; z_k^{+} = \varphi _k^{+} ( y_{0,k}^{+}; e_0) \ge 2 k \pi , &{} k=1,2, \ldots \\ \hbox {Re} \; z_k^{-} = \varphi _k^{-} ( y_{0,k}^{-}; e_0) < 0, &{} k=0,-1,-2, \ldots , \end{array} \end{aligned}$$

consequently, there are no complex roots of Kepler’s Equation in the complex band \( \left\{ z \in \mathbb {C} \,;\, 0 \le \hbox {Re}\; z \le \pi \right\} \) and any Jordan curve contained in this band is suitable for the application of the integral formula Eq. (2).

Fig. 1
figure 1

Locus of the complex zero \( z_{0}^{-}\) of KE for \( e = 0.5 \) and \( M \in (0, \pi )\)

In Fig. 1 we display the locus of the complex zeros \( z_{0}^{-}\) of KE for eccentricity \( e = 0.5\) and \( M \in (0, \pi )\). Observe that in general, for all \( e_0 \in (0,1) \) and \( M \in (0, \pi ) \), the two branches of \( z_{0}^{-}\) of non-real solutions remain in \(\hbox {Re} \; (z) < 0\) (as shown in Philcox et al. (2021)), but when \( e_0 \rightarrow 1\) and \( M \rightarrow 0\), since \( y \rightarrow 0\), they become arbitrarily close to the origin.

Remark 2

The above study can be repeated for the limit Kepler’s equation \(E - \sin E = M\). Now, putting \(E = x + i\, y\), its real part is

$$\begin{aligned} x = \varphi _k (y) = \pm \arccos (y/ \sinh y) + 2 k \pi , \end{aligned}$$

that is defined for all \(y > 0\). Then, for all \(M \in (0,\pi )\) there exists an infinite set of complex solutions \(z_k = \varphi _k(y) + i \, y_k\), where \(y = y_k\) is the unique real solution of \(M = y - \sin (\varphi _k(y)) \cosh y\). Moreover, for \(M \rightarrow 0\), \(z_0 \rightarrow 0\) with \(\text{ Re } z_0 < 0\), and for all \(k = 0, 1, 2, \ldots \) the complex solutions \(z_k\) are not contained in the complex strip \(\text{ Re } z \in (0,\pi ]\) for all \(M \in (0,\pi )\).

3 The Jordan contours \( \mathcal {C} = \mathcal {C} ( M,e) \)

In theory, the exact solution \( E = E(M;e)\) of Eq. (2) is independent of the Jordan contour \( \mathcal {C} = \mathcal {C} ( M,e) \) of the integrals provided that for each \( e \in [0,1)\) and \( M \in (0, \pi )\) it contains the exact solution E(Me) and \( f(z) \ne 0\) for all z in the interior, except \( z = E(M;e)\). However, the practical approximation of these integrals depends on the curve \( \mathcal {C}\) and, as we will see next, curves with smaller lengths lead to essential improvements in the accuracy when the integrals are approximated by quadrature rules. In this section we will consider several Jordan contours \( \mathcal {C}\) that are designed with the purpose to minimize their length.

First of all, we consider admissible circular contours in which each \( \mathcal {C}\) is a circle of radius \( \rho = \rho (M,e)\) and center \( \mu = \mu (M,e)\)

$$\begin{aligned} \mathcal {C} = \mathcal {C} (\mu , \rho ) = \Big \{ z = z_{ \mathcal {C}} = \mu + \rho \; \exp ( i \theta ) \; ; \; \theta \in [- \pi , \pi ] \Big \}, \end{aligned}$$
(16)

so that for all \((e, M ) \in \mathcal {D}\), the curve \( \mathcal {C} (\mu , \rho )\) contains the exact solution of Kepler equation: \( E = E(M;e)\) and, moreover, are admissible for (2).

For this Jordan curve (16) the integral solution (2) becomes

$$\begin{aligned} E(M; e) = \mu + \rho \; \displaystyle \frac{ \displaystyle \int _{- \pi }^{\pi } \exp ( 2 i \theta ) \; G( \theta ) \; d \theta }{ \displaystyle \int _{- \pi }^{\pi } \exp ( i \theta ) \; G( \theta ) \; d \theta }, \end{aligned}$$
(17)

with

$$\begin{aligned} G (\theta ) = G( \theta ; M, e) = f ( z_{ \mathcal {C}})^{-1} = \left[ z_{ \mathcal {C}} - e \sin ( z_{ \mathcal {C}}) - M \right] ^{-1}. \end{aligned}$$
(18)

A crucial point for the choice of the contours (16) is that as follows from

$$\begin{aligned} \displaystyle \frac{\partial E }{\partial M} >0, \quad \hbox {and} \quad \displaystyle \frac{\partial ^2 E }{\partial M^2 } <0, \quad \forall (e,M)\in \mathcal {D}, \end{aligned}$$

the exact solution of KE: \( E = E (M; e)\) is a monotonic increasing function of M and also is convex downwards. Then, by choosing appropriate upper and lower bounds of \( E = E(M;e)\) in \( M \in (0, \pi )\) we may derive admissible circular contours (16). Thus, taking as a lower bound \( E^{-}= E^{-}(M;e) \) of \( E = E(M;e)\), \( E^{-} =M\) and as upper bound \( E^{+} = E^{+}(M;e) = M+e\) we have

$$\begin{aligned} M = E^{-}< E(M; e) < E^{+} = M+e, \end{aligned}$$
(19)

that leads to the contour \( \mathcal {C}_0 = \mathcal {C} (\mu _0, \rho _0)\) with

$$\begin{aligned} \rho _0 = \displaystyle \frac{1}{2} (E^{+} - E^{-}) = \displaystyle \frac{e}{2} \quad \hbox {and} \quad \mu _0 = \displaystyle \frac{1}{2} (E^{+} + E^{-}) = M + \displaystyle \frac{e}{2}, \end{aligned}$$
(20)

that is the contour used by Philcox et al. (2021). It contains the exact solution E(Me) of (1) and by Proposition (2.1) is admissible for (2). Note that in (19) the lower bound \( E^{-}=M \) is in the (ME) plane the chord joining the end points of the arc \( E = E(M;e)\) with \( M \in (0,\pi )\), i.e., the points (0, 0) and \( (\pi , \pi )\). Also the upper bound \( E^{+}= M+e\) is the tangent to the curve \( E = E(M;e)\) at the point \( (M,E)= ( \pi /2- e, \pi /2)\) that is parallel to the chord. Since both \( E^{+} = E^{+}(M;e)\) and \( E^{-} = E^{-}(M;e)\) are affine functions of M with the same slope, it follows from the first equation of (20) that \( \rho _0= e/2\) is in fact independent of the mean anomaly M and, as we will see next, this fact has some computational advantages because it remains constant along the solution of the same elliptic orbit.

Clearly, \(\mathcal {C}_0\) is a good choice for small eccentricities because the length of all contours is \( \pi e\), but when e is close to 1 the length of the contours becomes close to \( \pi \). Furthermore, when \( M \rightarrow 0\) and \( e \rightarrow 1\), the contour \(\mathcal {C}_0\) tends to the circle of center \( \mu _0=1/2\) and radius \( \rho _0=1/2\) that is tangent to the imaginary axis at the origin, and recall that \( E=M=0 \) with \( e=1\) is a singular point of Kepler’s equation, and this fact introduces additional difficulties in the numerical calculations.

Now with the purpose to have admissible circular contours with radius \( \rho ( e) < e/2\), we first note that we may split the interval of mean anomaly \( (0, \pi )\) into two (or more) subintervals and then to obtain admissible circular contours in each subinterval such that the corresponding radius in each subinterval is smaller than the above \( \rho _0=e/2\).

Consider an interval \( (M_L, M_R)\) with \( (0 \le M_L < M_R \le \pi )\) and let \( E_L\), \(E_R\) be their corresponding eccentric anomalies. We take as lower bound \( E^{-}\) of \( E= E(M;e)\) in the interval \( (M_L, M_R)\) the chord between the two end points of it,

$$\begin{aligned} E^{-} = E_L + \displaystyle \frac{E_R - E_L}{M_R - M_L} \; ( M - M_L), \end{aligned}$$
(21)

and as upper bound \( E^+\), the tangent at some point \( (M^*, E^*)\) of \( E = E(M; e)\) that is parallel to (21). Since

$$\begin{aligned} \displaystyle \frac{d E }{d M} = \displaystyle \frac{1}{ 1 - e \; \cos E }, \end{aligned}$$

we have

$$\begin{aligned} \displaystyle \frac{1}{ 1 - e \; \cos E^* } = \displaystyle \frac{E_R - E_L}{M_R - M_L}, \end{aligned}$$

that defines \( E^*\) and \( M^*\) by

$$\begin{aligned} E^* = \arccos \left( \displaystyle \frac{\sin E_R -\sin E_L}{E_R - E_L} \right) , \quad M^* = E^* - e \sin E^*, \end{aligned}$$

and then the upper bound is

$$\begin{aligned} E^+ = E^* + \displaystyle \frac{E_R - E_L}{M_R - M_L} \; ( M - M^*). \end{aligned}$$
(22)

Now, we take as radius \(\rho \),

$$\begin{aligned} \rho = \displaystyle \frac{1}{2} (E^{+} - E^{-}) = \displaystyle \frac{\alpha \; e }{1 - e \; \cos E^*}, \end{aligned}$$

with

$$\begin{aligned} \alpha = \displaystyle \frac{1}{2} (\sin E^* - \sin E_L - ( E^* - E_L) \cos E^*). \end{aligned}$$
(23)

Note that \( \alpha \) and \( \rho \) are independent of M. For the center \(\mu \), there results

$$\begin{aligned} \mu = \displaystyle \frac{1}{2} (E^{+} - E^{-}) = \rho + E^{-} = \displaystyle \frac{\alpha \; e }{1 - e \; \cos E^*} + E_L + \displaystyle \frac{M- M_L}{1- e \; \cos E^*}, \end{aligned}$$
(24)

that is an affine function of M.

As an example, suppose that we split the interval \( (0, \pi ) = I_1 \cup I_2\) in the two subintervals

$$\begin{aligned} I_1 = (M_L, M_R) = (0, \pi /2 -e), \quad I_2 = (\pi /2 -e, \pi ). \end{aligned}$$

\(I_1\) corresponds to \( E_L =0\) and \( E_R = \pi /2\). Then from (22) and (23) we get \(E^* = 0.880689\ldots \), \(\alpha = 0.105257\ldots \), and now \( \rho (e)\) is a monotonic increasing function such that \(0< \rho < 0.28966\ldots \).

Similarly, in the subinterval \( I_2\) we have \( E_L = \pi /2\) and \( E_R = \pi \) and \( E^* = 2.2609\ldots \), \(\alpha = 0.105257\ldots \), and now \( \rho (e)\) is a monotonic increasing function with \(0< \rho < 0.0643136\ldots \), and hence, in both subintervals, \(I_1\) and \(I_2\), there results that the radii \(\rho _1(e), \rho _2(e) < e/2\), which was the radius of the Jordan circle \( \mathcal {C}_0 \) given in Eq. (20).

In Fig. 2  we present for this value of the eccentricity (\(e=0.5\)) the upper (\(E^+\)) and lower bounds (\(E^-\)) of the eccentric anomaly in the above two subintervals. Besides, on the right part of this figure, we plot the respective radii (\(\rho _1, \rho _2\)) of the Jordan circles and we can see that both are smaller than the radius \(\rho _0=0.5\) of the circle \(\mathcal {C}_0\); hence, the length of each new circle is smaller than the length of \(\mathcal {C}_0\).

Fig. 2
figure 2

Left) Lower bounds \(E^{-}\) (in blue) and upper bounds \(E^{+}\) (in orange) of the eccentric anomaly \(E=E(M;e)\) (in red) when M is in the subintervals \(I_1= (0,\pi /2- e)\) and \(I_2= (\pi /2- e,\pi )\) for \(e=0.5\), as given in Eqs. (21) and (22). Right The radius \(\rho \) of the Jordan circle in the interval \(I_1\) (in red), in the interval \(I_2\) (in blue), and \(\rho _0 =e\) for the circle \(\mathcal {C}_0\) is given in Eq. (20)

Another possibility to construct contours for integrals (2) with small lengths is to replace the circular contours of center \( \mu \) and radius \( \rho \) by elliptic contours with the same center, semi-major axis \( \rho \), and semi-minor axis \( \varepsilon \, \rho \) with some \( 0< \varepsilon < 1\). It follows from Proposition (2.1) that if a circular contour is suitable for (2) the corresponding elliptic contour defined in this way will be also suitable. This contour can be written in the parametric form as

$$\begin{aligned} \mathcal {C}_{\mathcal {E}} = \Big \{ z = z_{\mathcal {E}} = \mu + \rho ( \cos \theta + i \; \varepsilon \; \sin \theta ), \; \theta \; \in [- \pi , \pi ] \Big \}, \end{aligned}$$
(25)

and now the integral expression (2) becomes

$$\begin{aligned} E_{\mathcal {E}}(M; e) = \mu + \rho \; \displaystyle \frac{\displaystyle \int _{-\pi }^{\pi } \left[ \varepsilon \; \cos 2 \theta + i \; (( 1+ \varepsilon ^2)/2) \sin 2 \theta \right] G_{\mathcal {E}} ( \theta ) \; d \theta }{\displaystyle \int _{-\pi }^{\pi } \left[ \varepsilon \cos \theta + i \; \sin \theta \right] G_{\mathcal {E}} ( \theta ) \; d \theta }, \end{aligned}$$
(26)

with \( G_{\mathcal {E}} ( \theta ) = \left[ f( z_{\mathcal {E}} ) \right] ^{-1} \).

4 Approximation of the line integrals along circular and elliptic contours

For circular contours, the solution \( E = E(M;e)\) is given by Eqs. (17), (18) and \( G( \theta )\) is a \(2 \pi \)-periodic function of \( \theta \) that has a Fourier expansion

$$\begin{aligned} G( \theta ) = \sum _{n =- \infty }^{+ \infty } \widehat{G} (n) \; \exp ( i \, n \theta ) \end{aligned}$$
(27)

with coefficients \( \widehat{G} (n)\) given by

$$\begin{aligned} \widehat{G} (n) = \displaystyle \frac{1}{2 \pi } \int _{- \pi }^{ \pi } G( \theta ) \; \exp (- i \, n \theta ) \; d \theta ; \end{aligned}$$
(28)

therefore, the exact solution (17) can be written also in the form

$$\begin{aligned} E(M;e) = \mu + \rho \; \displaystyle \frac{ \widehat{G} (-2) }{\widehat{G} (-1) } . \end{aligned}$$
(29)

A straightforward approach (used by Philcox et al. (2021)) to approximate (29) is to compute the FFT of \( G( \theta )\) by using a standard FFT solver in which, for a given number \( N (\gg 1)\) of points, we get approximations \( \widehat{G}_N (k) \) to \( \widehat{G} (k) \) for \( \vert k \vert \le N/2\). With these approximations we have the approximate solution \( E_N(M;e)\) of (29)

$$\begin{aligned} E_N(M;e) = \mu + \rho \; \displaystyle \frac{ \widehat{G}_N (-2) }{\widehat{G}_N (-1) }. \end{aligned}$$
(30)

The main advantage of this approach is its simplicity and reliability because it is enough to use well-established FFT solvers and N sufficiently big to get accurate approximations. However, FFT solvers provide all coefficients \( \widehat{G}_N (k)\) with \( \vert k \vert \le N/2\), but for Eq. (30) we only need the corresponding to \(k = -2\) and \(k =-1\). Because of this, we focus on the approximations to \( \widehat{G} (-2)\) and \(\widehat{G} (-1)\) and we will use the same quadrature rule as the one used in the FFT, namely the composite trapezoidal rule that, in spite of its second order, is a reliable quadrature rule and, more important, the discrete approximations \( \widehat{G}_N (k)\) have a spectral convergence to \( \widehat{G} (k) \). In fact, it will be seen in the Appendix 1 that for all \( \vert k \vert \le N/2\) there exist \( \alpha = \alpha ( e)\) so that

$$\begin{aligned} \vert \widehat{G}_N (k) - \widehat{G} (k) \vert \simeq C_k \; \Big ( \exp ( - ( \alpha /2) N ) \Big ), \qquad (N \rightarrow \infty ) \end{aligned}$$
(31)

with some constant \( C_k\). In other words, the discrete Fourier coefficients \( \widehat{G}_N (k)\) converge exponentially to their corresponding exact values \( \widehat{G}(k)\). Note that in a standard quadrature rule with order p this convergence behaves asymptotically as \( 1/ (N^p)\), \( (N \rightarrow \infty )\). Furthermore, \( E_N (M; e)\) also exponentially converges with N to E(Me)

$$\begin{aligned} \log \vert E(M; e) - E_N (M;e) \vert \simeq - \displaystyle \frac{\alpha }{2} \; N \end{aligned}$$
(32)

and this implies that the logarithm of the error behaves linearly with N, whereas in the standard case, the logarithm of the error behaves as \( \log N \).

To simplify the calculation of \( \widehat{G}(k)\), \( k=\{-2,-1\}\), we observe that for the particular function \( G( \theta )\) given by (18) there are some symmetries that allow us to reduce the computational cost. In fact, taking into account that for \( k=\{-2,-1\}\)

$$\begin{aligned} \begin{array}{l} \hbox {Re} \Big [ \exp ( i\ k \theta ) G ( \theta ) \Big ] = \hbox {Re} \Big [ \exp ( -i\ k \theta ) G ( - \theta ) \Big ], \\ \hbox {Im} \Big [ \exp ( i\ k \theta ) G ( \theta ) \Big ] = - \hbox {Im} \Big [ \exp ( -i\ k \theta ) G ( - \theta ) \Big ], \end{array} \end{aligned}$$

the integration intervals of (29) can be reduced to \( [0, \pi ]\) and we have

$$\begin{aligned} E(M;e) = \mu + \rho \; \displaystyle \frac{ \displaystyle \int _0^{\pi } \hbox {Re} \left[ \exp ( 2 i\ \theta ) G( \theta ) \right] \; d \theta }{\displaystyle \int _0^{\pi } \hbox {Re} \left[ \exp ( i \ \theta ) G( \theta ) \right] \; d \theta }. \end{aligned}$$
(33)

In the composite trapezoidal rule, given an (even) positive integer K the integral

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

is approximated by

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

with \( \theta _j = j \; \pi / K, \;\; (j=0,1, \ldots ,K)\) and then (33) is approximated by

$$\begin{aligned} E_K ( M, e) = \mu + \rho \displaystyle \frac{I_K [ \hbox {Re} ( \exp ( 2 i \; \theta ) \; G( \theta )) ]}{I_K [ \hbox {Re} ( \exp ( i \; \theta ) \; G( \theta )) ]}. \end{aligned}$$
(36)

Note that (36) 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.

A second remark is that in the computation of

$$\begin{aligned} G( \theta )^{-1} = z_{\mathcal {C}} - e \; \sin ( z_{\mathcal {C}}) - M = \mu + \rho \exp ( i \theta ) - e \sin \left( \mu + \rho \exp ( i \theta ) \right) -M, \end{aligned}$$

if \( \rho \) is independent of the mean anomaly and \( \mu = \beta _0 + \beta _1 M\) is an affine function of M (here \( \beta _0\) and \( \beta _1\) may depend on e), the evaluations of \( \rho \, \exp ( i \ \theta _j)\), \( j=0, 1, \ldots ,K\), can be stored and used for all evaluations of the mean anomaly along the orbit, and then, the calculation of \( G(\theta )^{-1}\) only requires the computation of \( \sin \mu \) and \( \cos \mu \).

5 Numerical experiments

We will compute for circular and elliptic contours the absolute errors in the numerical solution denoted by \(\texttt {AErr}(K) = \vert E(M;e) - E_K (M; e) \vert \), for \( (e,M) \in \mathcal {D}\). Moreover, in the case of elliptic contours we will denote by \( \texttt {AErr}(K,\varepsilon )\) the corresponding errors for \( \varepsilon \in (0,1)\).

We made many experiments to show the accuracy of our method, but here we present only a few of them, although the approach performs properly in all examples chosen. In all samples we take values of \(M\in (0,\pi )\) and a fixed value of the eccentricity \(e = 0.9\), a higher value that may lead to convergence problems in some iterative methods for M close to zero. In the grid to apply the composite trapezoidal rule, we use three different values of K, namely, \(K=8\) (Fig. 3, top), \(K=16\) (Fig. 3, center), and \(K=32\) (Fig. 3, bottom).

For each value of K, we present the \(\log _{10} \texttt {AErr}(K)\) corresponding to the seven contour Jordan used, from top to bottom on each plot, the circle \(\mathcal {C}_0\), and ellipses with \(\varepsilon = 1/2, 1/4, 1/8, 1/16, 1/32\) and a very eccentric ellipse with \(\varepsilon = 10^{-3})\), close to a straight segment.

We can see in Fig. 3 that the smaller the length of the Jordan curve is the more accuracy we get. This pattern is the same for every number K of points in the grid. However, the accuracy dramatically increases with K; thus, for \(K=32\), we reach from 20 significant digits for \(M\approx 0\) to 40 digits at the end of the interval (\(M \approx \pi \)). Anyway, results for \(K=8\) are also very good; we reach from 10 to 20 significant digits.

We also note that there are several discontinuities in the plots. These are due to the fact that the numerical solution \( E_K(M; e)\) oscillates around the exact solution E(Me), and then, the discontinuities of \(\log _{10} \texttt {AErr}(K)\) appear at the crossing points. Observe that the number of discontinuities increases with K, showing a similar behavior to the best approximation of continuous functions.

Another important issue is how fast is our method when compared with the one of Philcox et al. (2021). The answer can be found in Figure 4, where we represent the CPU time for three cases depending on the number of nodes taken in the grid. We consider three different methods, all of them sharing the same Jordan circle \(\mathcal {C_0}\) used by Philcox et al. (2021), but we make the numerical computation of the line integrals (17) in three different ways: first (in gray), by using the FFT as in (Philcox et al. 2021); second (in red), by means of the composite trapezoidal rule; and finally (in red), with the optimized trapezoidal rule, that is, taking into consideration the symmetry and periodicity properties of the involved functions. We can see that the composite trapezoidal rule gives for even number of nodes a similar result in speed to the FFT method, the latter is slower for odd nodes. Clearly, optimized trapezoidal rule is the fastest, and the slope of its growing is more smooth than in the former cases.

Fig. 3
figure 3

In \( \log _{10}\) scale, the absolute errors for eccentricity \( e =0.9\) and \( M\in (0,\pi )\) with \( K=8,16, 32 \) (from top to bottom), and for each one computed using seven elliptical contour \( \mathcal {C}_0\), ranging from a circle (\(\varepsilon = 1\)) to an almost straight segment (\(\varepsilon = 10^{-3}\))

Fig. 4
figure 4

Comparison of the CPU time depending on the number of points in the grid, and for three used methods: in gray, the corresponding to the FFT, in red for the composite trapezoidal rule, and in green for the optimized trapezoidal rule, which is much faster than the other two

6 Conclusions

The integral expression of the transcendental elliptic Kepler’s Equation (KE) as quotient of two contours integrals around an appropriate Jordan curve is not only a mathematically beautiful explicit expression of the solution but also can be used for practical purposes. The aim of this paper is to examine the main issues (accuracy and computational cost) that determines their practical application. Since the definition of the contour integrals depends on a Jordan curve that contains inside only the unique real zero of the KE, a complete study of the complex zeroes of this equation is carried out in Sect. 2.

Moreover, as Jordan contours with smaller lengths improve the accuracy of the numerical approximation of integrals along them, several circular and elliptic Jordan contours have been proposed. Such contours allow us to express the integrals as the Fourier coefficients of a \(2 \pi \)–periodic function for the frequencies \( k=-2\) and \(k=-1\). In this context, taking into account that the composite trapezoidal rule is used in the well-experimented FFT, we use this rule with some additional simplifications due to the symmetries of the integrals proposed to approximate these Fourier coefficients with great accuracy. The spectral accuracy with the number of nodes is obtained in Appendix A, and the results of a number of numerical experiments are presented to show the accuracy as a function of the number of nodes in the quadrature rule. Special attention has been paid to the accuracy for values near the singularity \(M=0, \ e=1\) of KE.

Besides, it is worth to remark that as shown in Fig. 3, the use of ellipses as Jordan contours with parameter \(\varepsilon \) close to zero leads to a great improvement in the accuracy of the numerical approximation of the curvilinear integrals with the same computational cost as in the case of circular contours. Then, elliptical contours are highly recommended in computing the integrals of KE, particularly in the case of orbits with high eccentricities and for values of M close to zero.

Finally, the above study on the explicit integral solutions of elliptic Kepler’s equation can be extended to other similar transcendental equations. In particular, for the limit Kepler’s equation with \(e=1\), as noted in Remark 2, the study of its complex zeroes allows us to consider also elliptic Jordan contours for the efficient solution of the corresponding integrals. Moreover, the case of the hyperbolic Kepler’s equation \(e \sinh F - F =M\) \((e>1,\, M>0)\) in the unknown F will be subject of a forthcoming paper.