Class: Ephem::Computation::ChebyshevPolynomial

Inherits:
Object
  • Object
show all
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.

Examples:

Calculating position in 3D space

# coefficients is a 2D array where:
# - First dimension is the polynomial degree (n terms)
# - Second dimension is the spatial dimension (3 for x,y,z)
coefficients = Numo::DFloat.cast([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])

# normalized_time must be between -1 and 1
polynomial = ChebyshevPolynomial.new(
  coefficients: coefficients,
  normalized_time: 0.5
)

position = polynomial.evaluate

Calculating velocity with time scaling

# radius is the time span in days
polynomial = ChebyshevPolynomial.new(
  coefficients: coefficients,
  normalized_time: 0.5,
  radius: 32.0  # 32-day time span
)

velocity = polynomial.evaluate_derivative

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

Constructor Details

#initialize(coefficients:, normalized_time:, radius: nil) ⇒ ChebyshevPolynomial

Initializes a new Chebyshev polynomial calculator

Parameters:

  • coefficients (Numo::NArray)

    2D array of Chebyshev polynomial coefficients. First dimension represents polynomial terms (degree + 1). Second dimension represents spatial components (usually 3 for x,y,z)

  • normalized_time (Float)

    Time parameter normalized to [-1, 1] interval

  • radius (Float, nil) (defaults to: nil)

    Optional scaling factor for derivative calculations, usually represents the time span of the interval in days

Raises:



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

#evaluateNumo::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.

Returns:

  • (Numo::DFloat)

    Evaluation result, array of size dimension (usually 3)



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_derivativeNumo::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)

Returns:

  • (Numo::DFloat)

    Derivative values, array of size dimension (usually 3)



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