00001 #include "chebyshevpoly_expansion1d.h"
00002 #include <cmath>
00003
00004
00005 double CChebyshevPolynomialExpansion1d::basisFunction(double x, int i, int jderiv) const{
00006 if ( ( x < getLeftSupport(i) ) || (x > getRightSupport(i) ) ) return 0.0;
00007 double xx = rangeRemap(x);
00008 if (jderiv==0) return sqrt( 1.0/normalization(i)/xScale() )*orthogFunctionValue(xx, i);
00009 if (jderiv==1) return sqrt( 1.0/normalization(i)/xScale() )/xScale()*orthogFunctionValue(xx, i, 1);
00010 MESSAGE << "Did not implement CChebyshevPolynomialExpansion1d::basisFunction for jderiv != 0 or 1"<<ENDM_WARN;
00011 return 0.0;
00012 }
00013
00014 double CChebyshevPolynomialExpansion1d::basisFunctionInverse(double x, int i) const{
00015 if ( ( x < getLeftSupport(i) ) || (x > getRightSupport(i) ) ) return 0.0;
00016 double xx = rangeRemap(x);
00017 return sqrt( 1.0/normalization(i)/xScale() )*weightFunction(xx)*orthogFunctionValue(xx, i);
00018 MESSAGE << "Did not implement CChebyshevPolynomialExpansion1d::basisFunction for jderiv != 0 or 1"<<ENDM_WARN;
00019 return 0.0;
00020 }
00021
00022
00026 double CChebyshevPolynomialExpansion1d::orthogFunctionValue(double x, int i, int jderiv) const{
00027 if (jderiv==0) return chebyshev_polynomial(i,x);
00028 if (jderiv==1) {
00029 if (i==0) return 0.0;
00030 if ( x < 1e-10 ) x=1e-10;
00031 return ( (double)i/(1-x*x) )*( x*chebyshev_polynomial(i,x) - chebyshev_polynomial(i+1,x) );
00032 }
00033 MESSAGE << "Did not implement CChebyshevPolynomialExpansion1d::orthogFunctionValue for jderiv != 0 or 1"<<ENDM_WARN;
00034 return 0.0;
00035 }
00036 double CChebyshevPolynomialExpansion1d::weightFunction(double x, int jderiv) const{
00037 if (jderiv==0) return 1.0/sqrt( 1.0-x*x );
00038 if (jderiv==1) return x/pow( 1.0-x*x, 1.5 );
00039 MESSAGE << "Did not implement CChebyshevPolynomialExpansion1d::weightFunction for jderiv != 0 or 1"<<ENDM_WARN;
00040 return 0.0;
00041 }
00042
00043
00044 double CChebyshevPolynomialExpansion1d::getLeftSupport(int i) const{return xmin;}
00045 double CChebyshevPolynomialExpansion1d::getRightSupport(int i) const{return xmax;}
00046
00047
00048 double chebyshev_polynomial( int i, double x ){
00049 if (i < 0) return 0.0;
00050 double xx=x*x;
00051 switch (i) {
00052 case 0: return 1.0;
00053 case 1: return x;
00054 case 2: return 2.0*xx-1.0;
00055 case 3: return (4.0*xx-3.0)*x;
00056 case 4: return (xx-1.0)*8.0*xx+1.0;
00057 case 5: return ((16.0*xx-20.0)*xx+5.0)*x;
00058 case 6: return ((32.0*xx-48.0)*xx+18.0)*xx-1.0;
00059 case 7: return (((64.0*xx-112.0)*xx+56.0)*xx-7.0)*x;
00060
00061 default: return 2.0*x*chebyshev_polynomial(i-1,x)-chebyshev_polynomial(i-2,x);
00062 }
00063 return 0.0;
00064
00065 }