Chebyshev interpolation
This implementation efficiently evaluates a Chebyshev polynomial and its derivative using Clenshaw's recurrence formula. The algorithm is optimized for numerical stability and computational efficiency.
Tip
Chebyshev interpolation requires building the Chebyshev polynominal coefficients for each spline of each coordinate of a trajectory. Chebyshev interpolations poorly handle accelerations and as such are not suitable for ephemerides with any kind of eccentricity. They are most commonly used in the interpolation of planetary motion.
Foundation¶
For Chebyshev polynomials \(T_n(x)\) with coefficients \(c_n\), the polynomial is:
where \(T_n(x)\) satisfies the recurrence relation:
Algorithm¶
Initialization¶
- Input:
- Normalized time \(x \in [-1,1]\)
- Coefficients \(c_n\)
- Spline radius \(r_s\)
- Polynomial degree \(N\)
- Two three-element working arrays:
w
: for function valuesdw
: for derivative values
Clenshaw Recurrence¶
For \(j = N \to 2\):
-
Function value recurrence:
- \(w_2 = w_1\)
- \(w_1 = w_0\)
- \(w_0 = c_j + 2xw_1 - w_2\)
-
Derivative recurrence:
- \(w_2 = w_1\)
- \(w_1 = w_0\)
- \(dw_0 = 2w_1 + 2xdw_1 - dw_2\)
Final Computation¶
-
Function value:
\[ f(x) = c_0 + xw_0 - w_1 \] -
Derivative (scaled by spline radius):
\[ f'(x) = \frac{w_0 + xdw_0 - dw_1}{r_s} \]
Output¶
The algorithm returns a tuple \((f, f')\) where:
- \(f\) is the interpolated function value at \(x\)
- \(f'\) is the interpolated derivative at \(x\)
Note
A variation of this algorithm is used for Type 3 SPK/BSP SPICE files where the time derivative is not computed.
Error Handling¶
The implementation checks for:
- Non-zero spline radius
- Availability of coefficients at requested indices
- Valid evaluation epoch
Complexity¶
- Time complexity: \(\mathcal{O}(N)\)
- Space complexity: \(\mathcal{O}(1)\) (fixed-size working arrays)
Key Features¶
- Numerical Stability: Uses Clenshaw's algorithm instead of direct polynomial evaluation
- Memory Efficiency: Uses fixed-size arrays of length 3
- Simultaneous Computation: Evaluates both polynomial and derivative in a single pass
- Scale Handling: Accounts for spline radius in derivative computation
This implementation is particularly efficient for high-degree polynomials while maintaining numerical stability through the use of Clenshaw recursion.