Class RecurrenceAB

java.lang.Object
com.polytechnik.utils.RecurrenceAB
All Implemented Interfaces:
BasisFunctionsCalculatable, BasisFunctionsMultipliable, BasisPolynomials, ConfederateMatrixCalculatable, SimpleBasisPolynomials, ThreeTermRecurrenceCalculatable
Direct Known Subclasses:
RecurrenceABWithMultiplicationCached

public class RecurrenceAB extends Object implements BasisPolynomials, ThreeTermRecurrenceCalculatable
A normalized basis constructed from given three--term recurrence coefficients. The basis uses three--term recurrence coefficients obtained analytically or from sampled data by e.g getAB() method. A typical usage: given three--term recurrence coefficients obtain corresponding orthogonal polynomial in other polynomials basis, see convertBasisToPBASIS as an example
 
 var ab=new RecurrenceAB(a,b);
 double [][] polynomials_in_PBASIS=ab.convertBasisToPBASIS(ab.numAk(),PBASIS);
 // now polynomials_in_PBASIS[k] is k-th orthogobal polynomial with (a,b) recurrence.
 
 
A common case of PBASIS is Monomials(), Chebyshev(), etc. Another example: assume we have two polynomial bases known only through their three--term recurrence coefficients (a1,b1) and (a2,b2), then we can transform corresponding orthogonal polynomials through each other. See such an example in the unit test TestOrthogonalPolynomialsBasisFunctionsCalculatable.test_AB_conversion_PBASIS() method.
 
 // create random recurrence coefficients a1 b1, a2 b2 from random measures.
 var r=new java.util.Random(1234);
 var n=10;
 var MC=new OrthogonalPolynomialsLegendreBasis();
 var tmp1=MC.getAB(MC.getOrthogonalPolynomialsFirstKind(n,MC.B.getMomentsFromSample(2*n-1,IntStream.range(0,1000).mapToDouble(o-> -1+2*r.nextDouble()).toArray())));
 var a1=tmp1.getAllAk();
 var b1=tmp1.getAllBk();
 var tmp2=MC.getAB(MC.getOrthogonalPolynomialsFirstKind(n,MC.B.getMomentsFromSample(2*n-1,IntStream.range(0,1000).mapToDouble(o-> -1+2*r.nextDouble()).toArray())));
 var a2=tmp2.getAllAk();
 var b2=tmp2.getAllBk();
 
Then run the code:
 
 RecurrenceAB ab1=new RecurrenceAB(a1,b1),ab2=new RecurrenceAB(a2,b2);
 // the pols2_in_pols1Basis_direct[k] is the k-th orthogonal polynomial of ab2 in the basis of ab1.
 double [][] pols2_in_pols1Basis_direct=ab2.convertBasisToPBASIS(ab2.numAk(),ab1);

 // same polynomial can be obtained via an intermediate, e.g. the basis
 var M=new OrthogonalPolynomialsChebyshevBasis();
 double [][] pols1=M.getOrthogonalPolynomialsFirstKindFromAB(ab1), // ab1 polynomials in Chebyshev basis
             pols2=M.getOrthogonalPolynomialsFirstKindFromAB(ab2); // ab2 polynomials in Chebyshev basis

 for(int k=0;k<pols2.length;k++){
 // this is the k-th orthogonal polynomial of ab2 in the basis of ab1.
 double [] pols2k_in_pols1_via_intermediate=TMatr.expandOverLowerDiagBasis(pols2[k],pols1);
 // it matches exactly the pols2_in_pols1Basis_direct[k].
  System.err.println("direct="+java.util.Arrays.toString(pols2_in_pols1Basis_direct[k]));
  System.err.println("via intermediate="+java.util.Arrays.toString(pols2k_in_pols1_via_intermediate));
 }