#! /usr/bin/env python # def u_polynomial_value ( n, x ): #*****************************************************************************80 # ## U_POLYNOMIAL_VALUE: returns the single value U(n,x). # # Discussion: # # In cases where calling U_POLYNOMIAL is inconvenient, because it returns # a vector of values for multiple arguments X, this simpler interface # may be appropriate. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 12 July 2015 # # Author: # # John Burkardt # # Parameters: # # Input, integer N, the order of the polynomial. # # Input, real X, the argument of the polynomial. # # Output, real VALUE, the value of U(n,x). # import numpy as np from u_polynomial import u_polynomial if ( n < 0 ): value = 0.0 else: m = 1 x_vec = np.array ( [ x ] ) v_vec = u_polynomial ( m, n, x_vec ) value = v_vec[0,n] return value def u_polynomial_value_test ( ): #*****************************************************************************80 # ## U_POLYNOMIAL_VALUE_TEST tests U_POLYNOMIAL_VALUE. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 12 July 2015 # # Author: # # John Burkardt # import numpy as np import platform from u_polynomial_values import u_polynomial_values print ( '' ) print ( 'U_POLYNOMIAL_VALUE_TEST:' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' U_POLYNOMIAL_VALUE evaluates the Chebyshev polynomial U(n,x).' ) print ( '' ) print ( ' Tabulated Computed' ) print ( ' N X U(n,x) U(n,x) Error' ) print ( '' ) n_data = 0 while ( True ): n_data, n, x, fx1 = u_polynomial_values ( n_data ) if ( n_data == 0 ): break fx2 = u_polynomial_value ( n, x ) e = fx1 - fx2 print ( ' %4d %12g %24.16g %24.16g %8.2g' % ( n, x, fx1, fx2, e ) ) # # Terminate. # print ( '' ) print ( 'U_POLYNOMIAL_VALUE_TEST:' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) u_polynomial_value_test ( ) timestamp ( )