/* Functions for Chebyshev Polynomials in Maxima (descendant of DOE Macsyma). Copyright (C) 2004 Exstrom Laboratories LLC This work is freely redistributable under the terms of the GNU General Public License as published by the Free Software Foundation. This work comes with ABSOLUTELY NO WARRANTY. */ /* This function expands a given polynomial, p, in terms of the Chebyshev polynomials of the 1st kind (T). An array, a, of size hipow(p)+1, is returned, containing the expansion coefficients where a[0] corresponds to the highest power Chebyshev polynomial used (= hipow(p)), and each successive element of the "a" array corresponds to one lower power Chebyshev polynomial. Date: 4/15/04. Usage: chebtpoly(p) */ chebtpoly(p):= block([hp, size, a, pd, i, cp, ct], /*variables in brackets are local*/ hp:hipow(p,x), size:hp+1, a:makelist(0,i,1,size), pd:p, while hp>0 do( hp:hipow(pd,x), cp:coeff(pd,x,hp), ct:chebtcof(hp,0), a[size-hp]:cp/ct, pd:expand(pd-a[size-hp]*chebt(hp,x)) /*use of the expand function above is essential for hipow to work right*/ ), return(a) )\$ /* This function expands a given polynomial, p, in terms of the Chebyshev polynomials of the 2nd kind (U). An array, a, of size hipow(p)+1, is returned, containing the expansion coefficients where a[0] corresponds to the highest power Chebyshev polynomial used (= hipow(p)), and each successive element of the "a" array corresponds to one lower power Chebyshev polynomial. Date: 4/15/04. Usage: chebupoly(p) */ chebupoly(p):= block([hp, size, a, pd, i, cp, cu], /*variables in brackets are local*/ hp:hipow(p,x), size:hp+1, a:makelist(0,i,1,size), pd:p, while hp>0 do( hp:hipow(pd,x), cp:coeff(pd,x,hp), cu:chebucof(hp,0), a[size-hp]:cp/cu, pd:expand(pd-a[size-hp]*chebu(hp,x)) /*expand is essential for hipow to work right*/ /*use of the expand function above is essential for hipow to work right*/ ), return(a) )\$ /* This function returns the kth coefficient of the nth Chebyshev polynomial of the second kind (U). For the nth Chebyshev polynomial, there are a total of m coefficients where m = floor(n/2)+1. The index k has the range 0...(m-1), where k = 0 corresponds to the coefficient of the highest power of x. The index n has the range n>=0. Date: 4/15/04. Usage: chebucof(n,k) */ chebucof(n,k):= block([c], /*variables in brackets are local*/ c:2^n*(-1/4)^k*(n-k)!/(k!*(n-2*k)!), return(c) )\$ /* This function returns the kth coefficient of the nth Chebyshev polynomial of the first kind (T). For the nth Chebyshev polynomial, there are a total of m coefficients where m = floor(n/2)+1. The index k has the range 0...(m-1), where k = 0 corresponds to the coefficient of the highest power of x. The index n has the range n>=0, since the coefficients of T(n) are identical to those of T(-n). This function implements equation (2.18) of Mason & Handscomb's book "Chebyshev Polynomials". Date: 4/11/04. Usage: chebtcof(n,k) */ chebtcof(n,k):= block([c], /*variables in brackets are local*/ if n=2*k then c:(-1)^k else c:(-1)^k*2^(n-2*k-1)*n*(n-k)!/((n-k)*k!*(n-k-k)!), return(c) )\$ /* This function returns the nth Chebyshev polynomial of the second kind (U) evaluated at x. Unlike the chebyshev_u function in "specfun", this function also works correctly for n<=0. Date: 4/09/04. Usage: chebu(n,x) */ chebu(n,x):= block([U, U0, U1, i], /*variables in brackets are local*/ if n=0 then U:1 else if n>0 then( U0:1, U1:2*x, U:U1, for i:1 step 1 while in do( U:2*x*U1-U0, U0:U1, U1:U ) ), return(U) )\$ /* This function returns the nth Chebyshev polynomial of the first kind (T) evaluated at x. Unlike the chebyshev_t function in "specfun", this function also works correctly for n<=0. Date: 4/10/04. Usage: chebt(n,x) */ chebt(n,x):= block([T, T0, T1, m, i], /*variables in brackets are local*/ if n=0 then T:1 else( T0:1, T1:x, T:T1, if n<0 then m:-n else m:n, for i:1 step 1 while i