#! /usr/bin/env python # def chebyshev2_set ( n ): #*****************************************************************************80 # ## CHEBYSHEV2_SET sets a Chebyshev Type 2 quadrature rule. # # Discussion: # # The integral: # # integral ( -1 <= x <= 1 ) f(x) * sqrt ( 1 - x * x ) dx # # The quadrature rule: # # sum ( 1 <= i <= n ) w(i) * f ( x(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 ( [ \ 1.570796326794897 ] ) elif ( n == 2 ): x = np.array ( [ \ -0.5000000000000000, \ 0.5000000000000000 ] ) w = np.array ( [ \ 0.7853981633974484, \ 0.7853981633974481 ] ) elif ( n == 3 ): x = np.array ( [ \ -0.7071067811865475, \ 0.0, \ 0.7071067811865476 ] ) w = np.array ( [ \ 0.3926990816987243, \ 0.7853981633974483, \ 0.3926990816987240 ] ) elif ( n == 4 ): x = np.array ( [ \ -0.8090169943749473, \ -0.3090169943749473, \ 0.3090169943749475, \ 0.8090169943749475 ] ) w = np.array ( [ \ 0.2170787134227061, \ 0.5683194499747424, \ 0.5683194499747423, \ 0.2170787134227060 ] ) elif ( n == 5 ): x = np.array ( [ \ -0.8660254037844387, \ -0.5000000000000000, \ 0.0, \ 0.5000000000000000, \ 0.8660254037844387 ] ) w = np.array ( [ \ 0.1308996938995747, \ 0.3926990816987242, \ 0.5235987755982988, \ 0.3926990816987240, \ 0.1308996938995747 ] ) elif ( n == 6 ): x = np.array ( [ \ -0.9009688679024190, \ -0.6234898018587335, \ -0.2225209339563143, \ 0.2225209339563144, \ 0.6234898018587336, \ 0.9009688679024191 ] ) w = np.array ( [ \ 0.08448869089158863, \ 0.2743330560697779, \ 0.4265764164360819, \ 0.4265764164360819, \ 0.2743330560697778, \ 0.08448869089158857 ] ) elif ( n == 7 ): x = np.array ( [ \ -0.9238795325112867, \ -0.7071067811865475, \ -0.3826834323650897, \ 0.0, \ 0.3826834323650898, \ 0.7071067811865476, \ 0.9238795325112867 ] ) w = np.array ( [ \ 0.05750944903191316, \ 0.1963495408493621, \ 0.3351896326668110, \ 0.3926990816987241, \ 0.3351896326668110, \ 0.1963495408493620, \ 0.05750944903191313 ] ) elif ( n == 8 ): x = np.array ( [ \ -0.9396926207859083, \ -0.7660444431189779, \ -0.5000000000000000, \ -0.1736481776669303, \ 0.1736481776669304, \ 0.5000000000000000, \ 0.7660444431189780, \ 0.9396926207859084 ] ) w = np.array ( [ \ 0.04083294770910712, \ 0.1442256007956728, \ 0.2617993877991495, \ 0.3385402270935190, \ 0.3385402270935190, \ 0.2617993877991494, \ 0.1442256007956727, \ 0.04083294770910708 ] ) elif ( n == 9 ): x = np.array ( [ \ -0.9510565162951535, \ -0.8090169943749473, \ -0.5877852522924730, \ -0.3090169943749473, \ 0.0, \ 0.3090169943749475, \ 0.5877852522924731, \ 0.8090169943749475, \ 0.9510565162951535 ] ) w = np.array ( [ \ 0.02999954037160818, \ 0.1085393567113530, \ 0.2056199086476263, \ 0.2841597249873712, \ 0.3141592653589793, \ 0.2841597249873711, \ 0.2056199086476263, \ 0.1085393567113530, \ 0.02999954037160816 ] ) elif ( n == 10 ): x = np.array ( [ \ -0.9594929736144974, \ -0.8412535328311811, \ -0.6548607339452850, \ -0.4154150130018863, \ -0.1423148382732850, \ 0.1423148382732851, \ 0.4154150130018864, \ 0.6548607339452851, \ 0.8412535328311812, \ 0.9594929736144974 ] ) w = np.array ( [ \ 0.02266894250185884, \ 0.08347854093418908, \ 0.1631221774548166, \ 0.2363135602034873, \ 0.2798149423030966, \ 0.2798149423030965, \ 0.2363135602034873, \ 0.1631221774548166, \ 0.08347854093418902, \ 0.02266894250185884 ] ) else: print ( '' ) print ( 'CHEBYSHEV2_SET - Fatal error!' ) print ( ' Illegal value of N = %d' % ( n ) ) print ( ' Legal values are 1 through 10.' ) exit ( 'CHEBYSHEV2_SET - Fatal error!' ) return x, w def chebyshev2_set_test ( ): #*****************************************************************************80 # ## CHEBYSHEV2_SET_TEST tests CHEBYSHEV2_SET. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 11 June 2015 # # Author: # # John Burkardt # import platform print ( '' ) print ( 'CHEBYSHEV2_SET_TEST' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' CHEBYSHEV2_SET sets' ) print ( ' a Chebyshev Type 2 quadrature rule over [-1,1]' ) print ( '' ) print ( ' Index X W' ) for n in range ( 1, 11 ): x, w = chebyshev2_set ( n ) print ( '' ) for i in range ( 0, n ): print ( ' %2d %24.16g %24.16g' % ( i, x[i], w[i] ) ) # # Terminate. # print ( '' ) print ( 'CHEBYSHEV2_SET_TEST:' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) chebyshev2_set_test ( ) timestamp ( )