driver.ted.utilities
Class T_Interpolate

java.lang.Object
  extended by driver.ted.utilities.T_Interpolate

public class T_Interpolate
extends java.lang.Object

Title: T_Interpolate
Description: This class provides interpolation functions used within T_Algorithms. These algorithms are based upon Jean Meeus' Astronomical Algorithms book, Chapter 3, pages 23-34.
Copyright: (c) 2001 - 2006
Change History:

Version:
1.1
Author:
Ted Driver

Constructor Summary
T_Interpolate()
          Constructor initializes all values to zero (0) , and INTERPOLATION_DEFINED to false.
 
Method Summary
 void defineInterpolation(T_Vector X, T_Vector Y)
          Sets the X and Y values to interpolate over.
 double get_n()
          Provides the interpolating factor, n.
 double get_nmax()
          Provides the maximum interpolating factor, n_max.
 double getFirstDiffA()
          Returns the first difference (A) equal to y2 - y1
 double getFirstDiffB()
          Returns the first difference (B) equal to y3 - y2
 double getMaxPercentDiff()
          The getMaxPercentDiff method.
 double getSecondDiffC()
          Returns the second difference (C) equal to B - A (y1 + y3 - 2*y2)
 double getYmax()
          Provides the maximum Y value defined from the three or 5 input Y values.
 double interpolate(double x)
          The interpolation method.
 double interpolate(double x, double N)
          The interpolation method.
static void main(java.lang.String[] args)
          An executable program used to test the interpolation algorithm.
 java.lang.String toString()
          Provides statistics for the current Interpolation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

T_Interpolate

public T_Interpolate()
Constructor initializes all values to zero (0) , and INTERPOLATION_DEFINED to false.

Method Detail

toString

public java.lang.String toString()
Provides statistics for the current Interpolation. Including, Percent differences and the A, B and C values.

Overrides:
toString in class java.lang.Object
Returns:
A Sting listing Interpolation statistics.

defineInterpolation

public void defineInterpolation(T_Vector X,
                                T_Vector Y)
Sets the X and Y values to interpolate over. Also calculates differences (A,B & C) and sets the INTERPOLATION_DEFINED flag to true.

Parameters:
X - The array of X values to interpolate between. Must be either 3 or 5 in length.
Y - The array of Y values to interpolate over. Must be either 3 or 5 in length.

get_n

public double get_n()
Provides the interpolating factor, n.

Returns:
n, the double interpolating factor

getYmax

public double getYmax()
Provides the maximum Y value defined from the three or 5 input Y values.

Returns:
the maximum Y value, Y as a double.

get_nmax

public double get_nmax()
Provides the maximum interpolating factor, n_max.

Returns:
the double n_max, the maximum interpolating factor.

interpolate

public double interpolate(double x)
The interpolation method. Call this method with a value of x between the X values defined in defineInterpolation above. The interpolating factor n will be calculated as n = (x-xMid)/interval where xMid is the middle value of the X values passed into the defineInterpolation method above and interval is the difference between successive X values in the X array passed into the defineInterpolation method above.

Parameters:
x - An double value between the X values defined in the X array supplied in defineInterpolation
Returns:
An interpolated Y value corresponding to the the input X value.

interpolate

public double interpolate(double x,
                          double N)
The interpolation method. Call this method with a value of x between the X values defined in defineInterpolation above and a predefined interpolating factor N.

Parameters:
x - An double value between the X values defined in the X array supplied in defineInterpolation
N - The predefined interpolating factor.
Returns:
An interpolated Y value corresponding to the the input X value.

getMaxPercentDiff

public double getMaxPercentDiff()
The getMaxPercentDiff method. Call this method to see the maximum percent difference of C compared to all input Y values.

Returns:
The maximum percent (between 0 and 1) of the ABC of the third difference over all input Y values.

getFirstDiffA

public double getFirstDiffA()
Returns the first difference (A) equal to y2 - y1

Returns:
The value of y2 - y1

getFirstDiffB

public double getFirstDiffB()
Returns the first difference (B) equal to y3 - y2

Returns:
The value of y3 - y2

getSecondDiffC

public double getSecondDiffC()
Returns the second difference (C) equal to B - A (y1 + y3 - 2*y2)

Returns:
The value of B - A

main

public static void main(java.lang.String[] args)
An executable program used to test the interpolation algorithm. Example program:
 T_Interpolate I = new T_Interpolate();
 T_Vector X = new T_Vector(3);
 T_Vector Y = new T_Vector(3);

 date.setJulianDate(11,7,1992,0,0,0);
 X.setElement(0,date.getJulianDate());
 Y.setElement(0,0.884226);

 date.setJulianDate(11,8,1992,0,0,0);
 X.setElement(1,date.getJulianDate());
 Y.setElement(1,0.877366);

 date.setJulianDate(11,9,1992,0,0,0);
 X.setElement(2,date.getJulianDate());
 Y.setElement(2,0.870531);

 I.defineInterpolation(X,Y);
 // Be Sure the units you are interpolating between are the same
 date.setJulianDate(11,8,1992,4,21,0);
 System.out.println("Interpolation at 4:21 on the 8th is: ");
 System.out.println(I.interpolate(date.getJulianDate()));
 System.out.println(I.toString());
 System.exit(0);
Output:
 Interpolation at 4:21 on the 8th is: 
 0.8761253012701685
 Statistics of current interpolation:
 Percent Difference = 0.0028273314740861226%
 Differences:
 A = -0.006859999999999977
  C = 2.5000000000052758E-5
 B = -0.0068349999999999245

Parameters:
args - String parameter, not used in this test application.