#! /usr/bin/env python # def chebyshev1_set ( n ): #*****************************************************************************80 # ## CHEBYSHEV1_SET sets a Chebyshev Type 1 quadrature rule. # # Discussion: # # The integral: # # integral (-1 <= x <= 1 ) f(x) / sqrt (1 - x * x ) dx # # The quadrature rule: # # sum (1 <= i <= n ) (i) * f ( (i) ) # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 11 June 2015 # # Author: # # John Burkardt # # Parameters: # # Input, integer N, the order. # N must be between 1 and 10. # # Output, real X(N), the abscissas. # # Output, real W(N), the weights. # import numpy as np from sys import exit if ( n == 1 ): x = np.array ( [ \ 0.0 ] ) w = np.array ( [ \ 3.141592653589793 ] ) elif ( n == 2 ): x = np.array ( [ \ -0.7071067811865475, \ 0.7071067811865476 ] ) w = np.array ( [ \ 1.570796326794897, \ 1.570796326794897 ] ) elif ( n == 3 ): x = np.array ( [ \ -0.8660254037844387, \ 0.0, \ 0.8660254037844387 ] ) w = np.array ( [ \ 1.047197551196598, \ 1.047197551196598, \ 1.047197551196598 ] ) elif ( n == 4 ): x = np.array ( [ \ -0.9238795325112867, \ -0.3826834323650897, \ 0.3826834323650898, \ 0.9238795325112867 ] ) w = np.array ( [ \ 0.7853981633974483, \ 0.7853981633974483, \ 0.7853981633974483, \ 0.7853981633974483 ] ) elif ( n == 5 ): x = np.array ( [ \ -0.9510565162951535, \ -0.5877852522924730, \ 0.0, \ 0.5877852522924731, \ 0.9510565162951535 ] ) w = np.array ( [ \ 0.6283185307179586, \ 0.6283185307179586, \ 0.6283185307179586, \ 0.6283185307179586, \ 0.6283185307179586 ] ) elif ( n == 6 ): x = np.array ( [ \ -0.9659258262890682, \ -0.7071067811865475, \ -0.2588190451025206, \ 0.2588190451025207, \ 0.7071067811865476, \ 0.9659258262890683 ] ) w = np.array ( [ \ 0.5235987755982988, \ 0.5235987755982988, \ 0.5235987755982988, \ 0.5235987755982988, \ 0.5235987755982988, \ 0.5235987755982988 ] ) elif ( n == 7 ): x = np.array ( [ \ -0.9749279121818237, \ -0.7818314824680295, \ -0.4338837391175581, \ 0.0, \ 0.4338837391175582, \ 0.7818314824680298, \ 0.9749279121818236 ] ) w = np.array ( [ \ 0.4487989505128276, \ 0.4487989505128276, \ 0.4487989505128276, \ 0.4487989505128276, \ 0.4487989505128276, \ 0.4487989505128276, \ 0.4487989505128276 ] ) elif ( n == 8 ): x = np.array ( [ \ -0.9807852804032304, \ -0.8314696123025453, \ -0.5555702330196020, \ -0.1950903220161282, \ 0.1950903220161283, \ 0.5555702330196023, \ 0.8314696123025452, \ 0.9807852804032304 ] ) w = np.array ( [ \ 0.3926990816987241, \ 0.3926990816987241, \ 0.3926990816987241, \ 0.3926990816987241, \ 0.3926990816987241, \ 0.3926990816987241, \ 0.3926990816987241, \ 0.3926990816987241 ] ) elif ( n == 9 ): x = np.array ( [ \ -0.9848077530122080, \ -0.8660254037844385, \ -0.6427876096865394, \ -0.3420201433256688, \ 0.0, \ 0.3420201433256688, \ 0.6427876096865394, \ 0.8660254037844387, \ 0.9848077530122080 ] ) w = np.array ( [ \ 0.3490658503988659, \ 0.3490658503988659, \ 0.3490658503988659, \ 0.3490658503988659, \ 0.3490658503988659, \ 0.3490658503988659, \ 0.3490658503988659, \ 0.3490658503988659, \ 0.3490658503988659 ] ) elif ( n == 10 ): x = np.array ( [ \ -0.9876883405951377, \ -0.8910065241883678, \ -0.7071067811865475, \ -0.4539904997395467, \ -0.1564344650402306, \ 0.1564344650402309, \ 0.4539904997395468, \ 0.7071067811865476, \ 0.8910065241883679, \ 0.9876883405951378 ] ) w = np.array ( [ \ 0.3141592653589793, \ 0.3141592653589793, \ 0.3141592653589793, \ 0.3141592653589793, \ 0.3141592653589793, \ 0.3141592653589793, \ 0.3141592653589793, \ 0.3141592653589793, \ 0.3141592653589793, \ 0.3141592653589793 ] ) else: print ( '' ) print ( 'CHEBYSHEV1_SET - Fatal error!' ) print ( ' Illegal value of N = %d' % ( n ) ) print ( ' Legal values are 1 through 10.' ) exit ( 'CHEBYSHEV1_SET - Fatal error!' ) return x, w def chebyshev1_set_test ( ): #*****************************************************************************80 # ## CHEBYSHEV1_SET_TEST tests CHEBYSHEV1_SET. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 11 June 2015 # # Author: # # John Burkardt # import platform print ( '' ) print ( 'CHEBYSHEV1_SET_TEST' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' CHEBYSHEV1_SET sets' ) print ( ' a Chebyshev Type 1 quadrature rule over [-1,1]' ) print ( '' ) print ( ' Index X W' ) print ( '' ) for n in range ( 1, 11 ): x, w = chebyshev1_set ( n ) print ( '' ) for i in range ( 0, n ): print ( ' %2d %24.16g %24.16g' % ( i, x[i], w[i] ) ) # # Terminate. # print ( '' ) print ( 'CHEBYSHEV1_SET_TEST:' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) chebyshev1_set_test ( ) timestamp ( )