#! /usr/bin/env python # def t_polynomial_plot ( n_num, n_val, filename ): #*****************************************************************************80 # ## T_POLYNOMIAL_PLOT plots Chebyshev polynomials T(n,x). # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 21 July 2015 # # Author: # # John Burkardt # # Parameters: # # Input, integer N_NUM, the number of polynomials to plot. # # Input, integer N_VAL(N_NUM), the degree of each polynomial. # # Input, string FILENAME, the name into which the graphics information is # to be stored. Note that the PNG format will be used. # import matplotlib.pyplot as plt import numpy as np from t_polynomial import t_polynomial a = -1.0 b = +1.0 m = 501 x = np.linspace ( a, b, m ) for i in range ( 0, n_num ): n = n_val[i] y = t_polynomial ( m, n, x ) plt.plot ( x, y, 'b-', linewidth = 2.0 ) t = 'T(n,x), for n = ' for i in range ( 0, n_num ): n = n_val[i] t = t + str ( n ) if ( 1 < n_num and i < n_num - 1 ): t = t + ', ' plt.title ( t ) plt.grid ( True ) plt.xlabel ( '<---X--->' ) plt.ylabel ( '<---T(n,x)--->' ) plt.savefig ( filename ) plt.clf ( ) print ( ' Created plot file "%s".' % ( filename ) ) return def t_polynomial_plot_test ( ): #*****************************************************************************80 # ## T_POLYNOMIAL_PLOT_TEST tests T_POLYNOMIAL_PLOT. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 21 July 2015 # # Author: # # John Burkardt # import numpy as np import platform print ( '' ) print ( 'T_POLYNOMIAL_PLOT_TEST:' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' Plot several Chebyshev T polynomials.' ) n_num = 6 n_val = np.array ( [ 0, 1, 2, 3, 4, 5 ] ) filename = 't_polynomial_plot.png' t_polynomial_plot ( n_num, n_val, filename ) # # Terminate. # print ( '' ) print ( 'T_POLYNOMIAL_PLOT_TEST:' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) t_polynomial_plot_test ( ) timestamp ( )