Lagrange interpolation
This implementation computes both the Lagrange interpolation polynomial and its derivative at a specified point using Newton's divided difference method. The algorithm efficiently computes both values simultaneously through a single triangular computation scheme.
Tip
Lagrange interpolation is particularly useful for trajectory interpolation when provided distinct states with their first order derivative, e.g., position and velocity. It is less commonly used in ephemeris interpolation than the Hermite interpolation.
Foundation¶
For \(n\) points \((x_i, y_i)\), the Lagrange interpolation polynomial \(L(x)\) can be expressed using divided differences. The algorithm computes both:
and its derivative:
Algorithm¶
Initialization¶
- Input: Points \((x_i, y_i)\) and evaluation point \(x\)
- Two working arrays:
work
: stores function valuesdwork
: stores derivative values
Divided Difference Table Construction¶
For each level \(j = 1 \to n-1\):
For each index \(i = 0 \to n-j-1\):
-
Compute coefficients:
\[ x_i, x_{i+j} \text{ (interval endpoints)} \]\[ \text{denom} = x_i - x_{i+j} \] -
Update function value:
\[ \text{work}_i = \frac{(x - x_{i+j})\text{work}_i + (x_i - x)\text{work}_{i+1}}{\text{denom}} \] -
Update derivative:
\[ \text{deriv} = \frac{\text{work}_i - \text{work}_{i+1}}{\text{denom}} \]\[ \text{dwork}_i = \frac{(x - x_{i+j})\text{dwork}_i + (x_i - x)\text{dwork}_{i+1}}{\text{denom}} + \text{deriv} \]
Output¶
Returns tuple \((f, f')\) where:
- \(f = L(x)\): interpolated function value
- \(f' = L'(x)\): interpolated derivative
Error Handling¶
The implementation includes checks for:
- Array length consistency
- Non-empty input arrays
- Division by zero (minimum spacing of \(\epsilon \approx 2.22 \times 10^{-16}\))
Complexity¶
The algorithm achieves:
- Time complexity: \(\mathcal{O}(n^2)\)
- Space complexity: \(\mathcal{O}(n)\)
This implementation is particularly efficient as it computes both the interpolated value and its derivative in a single pass through the divided difference table, avoiding redundant calculations.