Class: Ephem::Computation::ChebyshevPolynomial
- Inherits:
-
Object
- Object
- Ephem::Computation::ChebyshevPolynomial
- Includes:
- Ephem::Core::Constants::Time
- Defined in:
- lib/ephem/computation/chebyshev_polynomial.rb
Overview
Implements Chebyshev polynomial evaluation and differentiation for astronomical calculations.
Chebyshev polynomials are mathematical functions that can be used to approximate other functions with high accuracy. In astronomical calculations, they are used to approximate positions and velocities of celestial bodies.
The polynomial evaluation is done using the Clenshaw algorithm, which is numerically stable and efficient. For performance optimization, polynomial values are cached when they need to be used both for position and velocity calculations.
Constant Summary
Constants included from Ephem::Core::Constants::Time
Ephem::Core::Constants::Time::J2000_EPOCH, Ephem::Core::Constants::Time::SECONDS_PER_DAY
Instance Method Summary collapse
-
#evaluate ⇒ Numo::DFloat
Evaluates the Chebyshev polynomial at the normalized time point.
-
#evaluate_derivative ⇒ Numo::DFloat
Calculates the derivative of the Chebyshev polynomial.
-
#initialize(coefficients:, normalized_time:, radius: nil) ⇒ ChebyshevPolynomial
constructor
Initializes a new Chebyshev polynomial calculator.
Constructor Details
#initialize(coefficients:, normalized_time:, radius: nil) ⇒ ChebyshevPolynomial
Initializes a new Chebyshev polynomial calculator
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ephem/computation/chebyshev_polynomial.rb', line 60 def initialize(coefficients:, normalized_time:, radius: nil) validate_inputs(coefficients, normalized_time) @coefficients = coefficients @normalized_time = normalized_time @radius = radius @degree = @coefficients.shape[0] @dimension = @coefficients.shape[1] @two_times_normalized_time = 2.0 * @normalized_time @polynomials = nil # Cache for polynomial values end |
Instance Method Details
#evaluate ⇒ Numo::DFloat
Evaluates the Chebyshev polynomial at the normalized time point
Uses the Clenshaw algorithm for numerical stability. The algorithm evaluates the polynomial using a recurrence relation, which is more stable than direct power series evaluation.
80 81 82 83 |
# File 'lib/ephem/computation/chebyshev_polynomial.rb', line 80 def evaluate @polynomials ||= generate_polynomials(@degree, @dimension) combine_polynomials(@polynomials) end |
#evaluate_derivative ⇒ Numo::DFloat
Calculates the derivative of the Chebyshev polynomial
For astronomical calculations, this typically represents velocity. For polynomials of degree < 2, returns zero array since the derivative of constants and linear terms are constant or zero.
If radius is provided, scales the result to convert from normalized time units to physical units (usually km/sec in astronomical calculations)
96 97 98 99 100 101 |
# File 'lib/ephem/computation/chebyshev_polynomial.rb', line 96 def evaluate_derivative return Numo::DFloat.zeros(@dimension) if @degree < 2 derivative = calculate_derivative(@degree, @dimension) scale_derivative(derivative) end |