Class Chebyshev

java.lang.Object
com.polytechnik.utils.Chebyshev
All Implemented Interfaces:
BasisFunctionsCalculatable, BasisFunctionsMultipliable, BasisPolynomials, ConfederateMatrixCalculatable, SimpleBasisPolynomials

public class Chebyshev extends Object implements BasisPolynomials
Chebyshev polynomials basis, using \( T_k=\alpha_{k-1} x*T_{k-1}-T_{k-2} \), where \( \alpha_{k}=1 \) for k=0, and 2 otherwise.
  • Constructor Details

    • Chebyshev

      public Chebyshev()
  • Method Details

    • getNext

      public double[] getNext(int n, double[] Tnm1, double[] Tnm2, boolean flag_type2, BasisFunctionsCalculatable PBASIS)
      Calculates n-th Chebyshev polynomial in PBASIS using \( T_n=\alpha_{n-1} x*T_{n-1}-T_{n-2} \), where \( \alpha_{n}=1 \) for n=0, and 2 otherwise.
      Specified by:
      getNext in interface BasisPolynomials
      Parameters:
      n - T index.
      Tnm1 - Input \( T_{n-1} \).
      Tnm2 - Input \( T_{n-2} \).
      flag_type2 - Whether to use type 2 polynomials.
      PBASIS - The basis in which to calculte.
      Returns:
      \( T_{n} \) polynomial, array dimension n+1.
    • getBasisFunctionsOnPolynomialArgument

      public double[][] getBasisFunctionsOnPolynomialArgument(int numQl, double[] pol, BasisFunctionsCalculatable PBASIS)
      Description copied from interface: SimpleBasisPolynomials
      This method calculates \( Q_l(pol(x))\), where pol(x) is a given polynomial and \( Q_l \) is basis finction of this (not PBASIS!) basis. This method may not be stable for a large dimensions of pol.length. Equivalent to numQl applications of SimpleBasisPolynomials.getNext(int, double[], double[], com.polytechnik.utils.BasisFunctionsCalculatable) to pol array. The method can be used to calculate e.g. \( T_n(P_k(x)) \) or \( T_n(P_k(L_m(x^j))) \). For example
      
      new Legendre().getBasisFunctionsOnPolynomialArgument(4,new double []{0,0,0,0,1},new Chebyshev())
      ={
      { 1.0 },
      { 0.0, 0.0, 0.0, 0.0, 1.0 },
      { 0.25, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.75 },
      { 0.0, 0.0, 0.0, 0.0, 0.375, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.625 }
      }
      
      means
      \( P_0(T_4(x))=T_0 \)
      \( P_1(T_4(x))=T_4(x) \)
      \( P_2(T_4(x))=0.25*T_0+0.75*T_8(x) \)
      \( P_3(T_4(x))=0.375*T_4(x)+0.625*T_{12}(x) \).
      Specified by:
      getBasisFunctionsOnPolynomialArgument in interface SimpleBasisPolynomials
      Parameters:
      numQl - The number of basis functions to calculate.
      pol - The polynomial to use in \( Q_l(pol(x))\), it is given in the PBASIS basis.
      PBASIS - the basis in which pol is given and the result is returned.
      Returns:
      An array of numQl dimension, elements: \( Q_0(pol(x)) \), \( Q_1(pol(x)) \), ... \( Q_{numQl-1}(pol(x)) \) in the basis PBASIS.
    • calculate

      public double calculate(int n, double x)
      Calculation of the value of n-th Chebyshev polynomial at given x.
      Specified by:
      calculate in interface BasisFunctionsCalculatable
      Parameters:
      n - T index.
      x - Argument.
      Returns:
      The value of the Chebyshev polynomial Tn at x.
    • getMomentsFromSample

      public double[] getMomentsFromSample(int nmoments, double[] x, double[] w, int nelsinsample)
      Description copied from interface: BasisFunctionsCalculatable
      Given observations x and weights w calculate the 0..nmoms-1 moments in the basis.
      Specified by:
      getMomentsFromSample in interface BasisFunctionsCalculatable
      Parameters:
      nmoments - The number of moments to calculate.
      x - observation samples.
      w - weights.
      nelsinsample - How many elements to sample.
      Returns:
      nelsinsample generalzied moments, \( k=0\dots nmoms-1 \): \( \sum_{j=0}^{nelsinsample-1} Q_k(x[j])*w[j] \).
    • getD0

      public double getD0(double[] Tcoefs, double x)
      Calculates \( \sum_k T_k(x) Tcoefs[k] \). Two versions: original and the one copied from http://www.alglib.net/.
      Specified by:
      getD0 in interface BasisFunctionsCalculatable
      Parameters:
      Tcoefs - Coefficients.
      x - Point to estimate the sum.
      Returns:
      The sum.
    • getD1

      public double getD1(double[] Tcoefs, double x)
      Calculates \( d/dx \sum_k T_k(x) Tcoefs[k] \).
      Specified by:
      getD1 in interface BasisFunctionsCalculatable
      Parameters:
      Tcoefs - Coefficients.
      x - Pont to estimate the sum.
      Returns:
      The derivative.
    • getD2

      public double getD2(double[] Tcoefs, double x)
      Calculates \( d^2/dx^2 \sum_k T_k(x) Tcoefs[k] \).
      Specified by:
      getD2 in interface BasisFunctionsCalculatable
      Parameters:
      Tcoefs - Coefficients.
      x - Pont to estimate the sum.
      Returns:
      The second derivative.
    • getDifferentiated

      public double[] getDifferentiated(double[] Tcoefs)
      Differentiate a function in Chebyshev basis, F(x) - a polynomial of n-th order. То calculate use the formulae Prudnikov, Brychkov, Marichev, volume 2, 2003, page 651 \( T_k(x)'=kU_{k-1}(x) \) and then express \( U_{k-1}(x) \) through \(T_k(x) \) using http://en.wikipedia.org/wiki/Chebyshev_polynomials#Relation_between_Chebyshev_polynomials_of_the_first_and_second_kinds (recurrently apply formulae 22.5.8 Abramowitz and Stegun 1972, p. 778).
      Specified by:
      getDifferentiated in interface BasisFunctionsCalculatable
      Parameters:
      Tcoefs - Input: \( F(x)=\sum_k T_k(x)*Tcoefs[k] \).
      Returns:
      \( dF/dx=\sum_k T'_k(x)*Tcoefs[k] \).
    • getIntegrated

      public double[] getIntegrated(double[] Tcoefs)
      Integrate a function in Chebyshev basis, То calculate use the formulae Prudnikov, Brychkov, Marichev, volume 2, 2003, formulae 1.14.2.1 page 46.
      Specified by:
      getIntegrated in interface BasisFunctionsCalculatable
      Parameters:
      Tcoefs - Input: \( F(x)=\sum_k T_k(x)*Tcoefs[k] \).
      Returns:
      \( \int_0^x F(x)dx=\int_0^x T_k(x)dx*Tcoefs[k] \).
    • setQlQmExpansionCoefs

      public void setQlQmExpansionCoefs(int l, int m, double[] s)
      Expand \( T_l(z)T_m(z)=\sum_{k=0}^{l+m} s_k T_k(z) \), formulae 22.7.24 Abramowitz and Stegun 1972, p. 872.
      Specified by:
      setQlQmExpansionCoefs in interface BasisFunctionsMultipliable
      Parameters:
      l - l.
      m - m.
      s - coefs.
    • getaxbP

      public double[] getaxbP(double[] p, double ma, double mb)
      Multiply p by ma*x+mb. Calculations in Chebyshev. Do not mistake with a and b recurrence coefficiemts of getAB().
      Specified by:
      getaxbP in interface BasisFunctionsCalculatable
      Parameters:
      p - Input polynomial.
      Returns:
      p*(ma*x+mb), an array of the length 1+p.length.
    • sdiv1

      public SDivRes sdiv1(double[] p, double x0)
      Divide p by (x-x0), returns quotient and remainder. Calculations in Chebyshev basis.
      Specified by:
      sdiv1 in interface BasisFunctionsCalculatable
      Parameters:
      p - Input polynomial.
      x0 - To divide on (x-x0)
      Returns:
      The q and r.
    • setNewtonBinomialLikeCoefs

      public void setNewtonBinomialLikeCoefs(int n, double[] b, double[] q, double a, double x0)
      Calculates T_n(a(x+x0)) using 3 term recurrence. Calculations in Chebyshev basis. The \( b_k^{n} \) are defined as: \( T_n(a(x+x0))=\sum_{k=0}^{k=n}b_k^{n} T_k(x) \) The method should be applied consequently to get \( b_k^{n} \) for n=0,1,2,3,...
      Specified by:
      setNewtonBinomialLikeCoefs in interface BasisPolynomials
      Parameters:
      n - The max dimension of b.
      b - On input: \( b_k^{n-1} \), on output \( b_k^{n} \).
      q - On input: \( b_k^{n-2} \), on output: \( b_k^{n-1} \).
    • getXQkMomentsFromQkMoments

      public double[] getXQkMomentsFromQkMoments(double[] moments)
      Calculate <F|xTk> moments from <F|Tk>.
      Specified by:
      getXQkMomentsFromQkMoments in interface BasisFunctionsCalculatable
      Parameters:
      moments - <F|Tk>
      Returns:
      <F|xTk>
    • getConfederateMatrix

      public double[] getConfederateMatrix(double[] coefs)
      Calculates confederate matrix to solve polynomial equations in Chebyshev basis directly. We use the three term recurrence: \[ T_k=\alpha_{k-1} x*T_{k-1}-T_{k-2} \], where \( \alpha_{k}=1 \) for k=0, and 2 otherwise. Use ABASISCHEBYSHEV to calculate roots.
      Specified by:
      getConfederateMatrix in interface ConfederateMatrixCalculatable
    • main

      public static void main(String[] args)
      A unit test.