#! /usr/bin/env python # def u_polynomial_coefficients ( n ): #*****************************************************************************80 # ## U_POLYNOMIAL_COEFFICIENTS: coefficients of the Chebyshev polynomial U(n,x). # # First terms: # # N/K 0 1 2 3 4 5 6 7 8 9 10 # # 0 1 # 1 0 2 # 2 -1 0 4 # 3 0 -4 0 8 # 4 1 0 -12 0 16 # 5 0 6 0 -32 0 32 # 6 -1 0 24 0 -80 0 64 # 7 0 -8 0 80 0 -192 0 128 # # Recursion: # # U(0)(X) = 1, # U(1)(X) = 2*X, # U(N)(X) = 2 * X * U(N-1)(X) - U(N-2)(X) # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 15 July 2015 # # Author: # # John Burkardt # # Reference: # # Milton Abramowitz and Irene Stegun, # Handbook of Mathematical Functions, # US Department of Commerce, 1964. # # Parameters: # # Input, integer N, the highest order polynomial to compute. # Note that polynomials 0 through N will be computed. # # Output, real C(1:N+1,1:N+1), the coefficients of the Chebyshev T # polynomials. # import numpy as np c = np.zeros ( [ n + 1, n + 1 ] ) c[0,0] = 1.0 if ( 0 < n ): c[1,1] = 2.0 for i in range ( 2, n + 1 ): c[i,0] = - c[i-2,0] for j in range ( 1, i - 1 ): c[i,j] = 2.0 * c[i-1,j-1] - c[i-2,j] c[i,i-1] = 2.0 * c[i-1,i-2] c[i,i] = 2.0 * c[i-1,i-1] return c def u_polynomial_coefficients_test ( ): #*****************************************************************************80 # ## U_POLYNOMIAL_COEFFICIENTS_TEST tests U_POLYNOMIAL_COEFFICIENTS. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 15 July 2015 # # Author: # # John Burkardt # import numpy as np import platform from r8poly_print import r8poly_print n = 5 print ( '' ) print ( 'U_POLYNOMIAL_COEFFICIENTS_TEST' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' U_POLYNOMIAL_COEFFICIENTS determines the Chebyshev' ) print ( ' polynomial coefficients.' ) c = u_polynomial_coefficients ( n ) for i in range ( 0, n + 1 ): c2 = np.zeros ( i + 1 ) for j in range ( 0, i + 1 ): c2[j] = c[i,j] r8poly_print ( i, c2, '' ) # # Terminate. # print ( '' ) print ( 'U_POLYNOMIAL_COEFFICIENTS_TEST:' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) u_polynomial_coefficients_test ( ) timestamp ( )