/* chebyshev.c two ways to get coefficients for e^x */ /* compute x(i) and w(i)=2/Pi i=1,n ordinates and weights */ /* on interval -1.0 to 1.0 (length is 2.0) */ /* use ordinates and weights for Gauss Chebyshev integration */ #include #include #undef abs #define abs(x) ((x)<0.0?(-(x)):(x)) static double Pi=3.141592653589793; static double TP[18][18]; /* TP[n][i] */ static double Texp[18][18]; /* for evaluating exp(x) in -1 to 1 */ static double TTexp[18][18]; /* for evaluating exp(x) in -1 to 1 */ static double expp[18]; static double P[18]; /* temp polynomial */ static double T(int n, double x) /* recursive evaluation of Tn(x) */ { if(n<=0) return 1.0; if(n==1) return x; return 2.0*T(n-1,x) - T(n-2,x); } /* end T */ static double eval(int n, double P[], double x) { /* evaluate polynomial P at point x */ int i; double y = P[n]*x; for(i=n-1; i>0; i--) y = (y+P[i])*x; return y+P[0]; } /* end eval */ static double nfct(int n) { /* compute n factorial as a double */ if(n<=1) return 1.0; return (double)n*nfct(n-1); } /* end nfct */ static void make_expp(int n) { /* generate Taylor series polynomial for exp(x) */ int i; for(i=0; i