Skip to content

Documentation / @interstellar-tools/equations / solveKeplerNewtonRaphson

Function: solveKeplerNewtonRaphson() ​

ts
function solveKeplerNewtonRaphson(
  M: Radians,
  e: number,
  maxIter: number,
  tolerance: number
): number | Radians;

Defined in: kepler/solve-kepler-newton-raphson.ts:85

Solves Kepler's Equation for the Eccentric Anomaly (E) using the Newton-Raphson method with Householder acceleration for fast convergence.


Mathematical Explanation:

Kepler's equation relates the mean anomaly (M), the eccentric anomaly (E), and the orbital eccentricity (e) as:

M=E−esin⁡(E)

Since this equation cannot be solved algebraically, iterative numerical methods are required.


Solving Strategy:

  1. Handle Special Cases:

    • If eccentricity is out of range (e<0 or e≥1), a RangeError is thrown.
    • Kepler's equation is 2π-periodic (M+2πk↦E+2πk), so the equation is solved for Mmod2π and the whole turns are added back. Any finite M works, including negative values and many revolutions.
  2. Initial Approximation (Danby 1987, good for all 0≤e<1):

    E0=M+0.85esign(sin⁡M)
  3. Newton-Raphson Iteration with Householder Acceleration:

    • With f(E)=E−esin⁡(E)−M, f′(E)=1−ecos⁡(E), f″(E)=esin⁡(E) and f‴(E)=ecos⁡(E), each step refines the Newton correction to third order:δ1=−ff′,δ2=−ff′+12δ1f″,ΔE=−ff′+12δ2f″+16δ22f‴
  4. Convergence Check:

    • The iteration stops when:|En+1−En|<tolerance(default tolerance is 1e-9).
  5. Failure Handling:

    • If the method does not converge, NaN is returned, signaling that a fallback method should be used.

Performance Considerations:

  • Typically converges in 3-4 iterations, including e→1.
  • Time complexity: O(1) for Newton-Raphson.

Parameters ​

ParameterTypeDescription
MRadiansMean anomaly (M) in radians.
enumberOrbital eccentricity (0≤e<1).
maxIternumberMaximum number of iterations before failure.
tolerancenumberConvergence criterion for stopping the iteration.

Returns ​

number | Radians

The eccentric anomaly (E) in radians (or NaN if the method fails).

Throws ​

RangeError If the eccentricity (e) is invalid (e<0 or e≥1).


Example ​

ts
const M = Math.PI / 4; // 45 degrees in radians
const e = 0.1; // Orbital eccentricity
console.log(solveKeplerNewtonRaphson(M, e, 50, 1e-9)); // Output: Eccentric anomaly in radians

See ​