C+ C NAME: C Chebyshev_exp C PURPOSE: C Given the coefficients of its expansion in Chebyshev polynomials, C evaluate the value of a polynomial in point X C CATEGORY: C Math: orthogonal polynomials C CALLING SEQUENCE: function Chebyshev_exp(A,B,X,N,CN) C INPUTS: C A,B real definition interval (see PROCEDURE) C X real X-value where function is evaluated C N integer # terms in Chebyshev expansion C CN(N) real expansion coefficients C OUTPUTS: C Chebyshev_exp real value of polynomial in point X C RESTRICTIONS: C > The number of terms in the expansion, N, must be larger then zero C > A and B must be unequal C PROCEDURE: C > The Chebyshev expansion is C VALUE(X) = SUM(i=1,N) { CN(I)*T_i-1(XS) }, i.e. CN(I) is the C coefficient of the Tchebyshev polynomial of degree I-1 C > The interval [a,b] is mapped to [-1,1]. X is rescaled accordingly to C XS = (2X-(B+A))/(B-A) C > The evaluation of the Tchebyshev polynomials is based on the C three-term recurrence relation (T_0 = 1 ; T_1 = x) C T_i = 2xT_i-1 - T_i-2 ; i = 2,3,4, ... C MODIFICATION HISTORY: C DEC-1991; Paul Hick (UCSD) C- real A real B real X integer N real CN(N) Chebyshev_exp = CN(1) ! N = 1 if (N .eq. 1) return XS = (2*X-(B+A))/(B-A) ! Scale X to [-1,1] Chebyshev_exp = Chebyshev_exp+CN(2)*XS ! N = 2 if (N .eq. 2) return CM2 = 1 CM1 = XS XS = 2*XS do I=3,N CM3 = CM2 ! degree I-3 CM2 = CM1 ! degree I-2 CM1 = XS*CM2-CM3 ! degree I-1 (by recursion) Chebyshev = Chebyshev_exp+CN(I)*CM1 ! Expansion end do return end