#! /usr/bin/env python # def w_polynomial_value ( n, x ): #*****************************************************************************80 # ## W_POLYNOMIAL_VALUE: returns the single value W(n,x). # # Discussion: # # In cases where calling W_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 W(n,x). # import numpy as np from w_polynomial import w_polynomial if ( n < 0 ): value = 0.0 else: m = 1 x_vec = np.array ( [ x ] ) v_vec = w_polynomial ( m, n, x_vec ) value = v_vec[0,n] return value def w_polynomial_value_test ( ): #*****************************************************************************80 # ## W_POLYNOMIAL_VALUE_TEST tests W_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 w_polynomial_values import w_polynomial_values print ( '' ) print ( 'W_POLYNOMIAL_VALUE_TEST:' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' W_POLYNOMIAL_VALUE evaluates the Chebyshev polynomial W(n,x).' ) print ( '' ) print ( ' Tabulated Computed' ) print ( ' N X W(n,x) W(n,x) Error' ) print ( '' ) n_data = 0 while ( True ): n_data, n, x, fx1 = w_polynomial_values ( n_data ) if ( n_data == 0 ): break fx2 = w_polynomial_value ( n, x ) e = fx1 - fx2 print ( ' %4d %12g %24.16g %24.16g %8.2g' % ( n, x, fx1, fx2, e ) ) # # Terminate. # print ( '' ) print ( 'W_POLYNOMIAL_VALUE_TEST:' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) w_polynomial_value_test ( ) timestamp ( )