#! /usr/bin/env python # def v_polynomial ( m, n, x ): #*****************************************************************************80 # ## V_POLYNOMIAL evaluates Chebyshev polynomials V(n,x). # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 12 July 2105 # # Author: # # John Burkardt # # Parameters: # # Input, integer M, the number of evaluation points. # # Input, integer N, the highest polynomial to compute. # # Input, real X(M,1), the evaluation points. # # Output, real V(1:M,1:N+1), the values of the N+1 Chebyshev polynomials. # import numpy as np from sys import exit if ( n < 0 ): print ( '' ) print ( 'V_POLYNOMIAL - Fatal error!' ) print ( ' N < 0' ) exit ( 'V_POLYNOMIAL - Fatal error.' ) v = np.zeros ( [ m, n + 1 ] ) for i in range ( 0, m ): v[i,0] = 1.0 if ( n < 1 ): return v for i in range ( 0, m ): v[i,1] = 2.0 * x[i] - 1.0 for i in range ( 0, m ): for j in range ( 2, n + 1 ): v[i,j] = 2.0 * x[i] * v[i,j-1] - v[i,j-2] return v def v_polynomial_test ( ): #*****************************************************************************80 # ## V_POLYNOMIAL_TEST tests V_POLYNOMIAL. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 12 July 2015 # # Author: # # John Burkardt # import numpy as np import platform from v_polynomial_values import v_polynomial_values print ( '' ) print ( 'V_POLYNOMIAL_TEST:' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' V_POLYNOMIAL evaluates the Chebyshev polynomial V(n,x).' ) print ( '' ) print ( ' Tabulated Computed' ) print ( ' N X V(n,x) V(n,x) Error' ) print ( '' ) n_data = 0 x_vec = np.zeros ( 1 ) while ( True ): n_data, n, x, fx1 = v_polynomial_values ( n_data ) if ( n_data == 0 ): break if ( n < 0 ): continue x_vec[0] = x fx2_vec = v_polynomial ( 1, n, x_vec ) fx2 = fx2_vec[0,n] e = fx1 - fx2 print ( ' %4d %12g %24.16g %24.16g %8.2g' % ( n, x, fx1, fx2, e ) ) # # Terminate. # print ( '' ) print ( 'V_POLYNOMIAL_TEST:' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) v_polynomial_test ( ) timestamp ( )