#! /usr/bin/env python # def chebyshev3_set ( n ): #*****************************************************************************80 # ## CHEBYSHEV3_SET sets a Chebyshev Type 3 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: # # 12 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.000000000000000 ] ) w = np.array ( [ \ 3.141592653589793 ] ) elif ( n == 2 ): x = np.array ( [ \ -1.000000000000000, \ 1.000000000000000 ] ) w = np.array ( [ \ 1.570796326794897, \ 1.570796326794897 ] ) elif ( n == 3 ): x = np.array ( [ \ -1.000000000000000, \ 0.0, \ 1.000000000000000 ] ) w = np.array ( [ \ 0.7853981633974483, \ 1.570796326794897, \ 0.7853981633974483 ] ) elif ( n == 4 ): x = np.array ( [ \ -1.000000000000000, \ -0.5000000000000000, \ 0.5000000000000000, \ 1.000000000000000 ] ) w = np.array ( [ \ 0.5235987755982988, \ 1.047197551196598, \ 1.047197551196598, \ 0.5235987755982988 ] ) elif ( n == 5 ): x = np.array ( [ \ -1.000000000000000, \ -0.7071067811865475, \ 0.0, \ 0.7071067811865476, \ 1.000000000000000 ] ) w = np.array ( [ \ 0.3926990816987241, \ 0.7853981633974483, \ 0.7853981633974483, \ 0.7853981633974483, \ 0.3926990816987241 ] ) elif ( n == 6 ): x = np.array ( [ \ -1.000000000000000, \ -0.8090169943749473, \ -0.3090169943749473, \ 0.3090169943749475, \ 0.8090169943749475, \ 1.000000000000000 ] ) w = np.array ( [ \ 0.3141592653589793, \ 0.6283185307179586, \ 0.6283185307179586, \ 0.6283185307179586, \ 0.6283185307179586, \ 0.3141592653589793 ] ) elif ( n == 7 ): x = np.array ( [ \ -1.000000000000000, \ -0.8660254037844387, \ -0.5000000000000000, \ 0.0, \ 0.5000000000000001, \ 0.8660254037844387, \ 1.000000000000000 ] ) w = np.array ( [ \ 0.2617993877991494, \ 0.5235987755982988, \ 0.5235987755982988, \ 0.5235987755982988, \ 0.5235987755982988, \ 0.5235987755982988, \ 0.2617993877991494 ] ) elif ( n == 8 ): x = np.array ( [ \ -1.000000000000000, \ -0.9009688679024190, \ -0.6234898018587335, \ -0.2225209339563143, \ 0.2225209339563144, \ 0.6234898018587336, \ 0.9009688679024191, \ 1.000000000000000 ] ) w = np.array ( [ \ 0.2243994752564138, \ 0.4487989505128276, \ 0.4487989505128276, \ 0.4487989505128276, \ 0.4487989505128276, \ 0.4487989505128276, \ 0.4487989505128276, \ 0.2243994752564138 ] ) elif ( n == 9 ): x = np.array ( [ \ -1.000000000000000, \ -0.9238795325112867, \ -0.7071067811865475, \ -0.3826834323650897, \ 0.0, \ 0.3826834323650898, \ 0.7071067811865476, \ 0.9238795325112867, \ 1.000000000000000 ] ) w = np.array ( [ \ 0.1963495408493621, \ 0.3926990816987241, \ 0.3926990816987241, \ 0.3926990816987241, \ 0.3926990816987241, \ 0.3926990816987241, \ 0.3926990816987241, \ 0.3926990816987241, \ 0.1963495408493621 ] ) elif ( n == 10 ): x = np.array ( [ \ -1.000000000000000, \ -0.9396926207859083, \ -0.7660444431189779, \ -0.5000000000000000, \ -0.1736481776669303, \ 0.1736481776669304, \ 0.5000000000000001, \ 0.7660444431189780, \ 0.9396926207859084, \ 1.000000000000000 ] ) w = np.array ( [ \ 0.1745329251994329, \ 0.3490658503988659, \ 0.3490658503988659, \ 0.3490658503988659, \ 0.3490658503988659, \ 0.3490658503988659, \ 0.3490658503988659, \ 0.3490658503988659, \ 0.3490658503988659, \ 0.1745329251994329 ] ) else: print ( '' ) print ( 'CHEBYSHEV3_SET - Fatal error!' ) print ( ' Illegal value of N = %d' % ( n ) ) print ( ' Legal values are 1 through 10.' ) exit ( 'CHEBYSHEV3_SET - Fatal error!' ) return x, w def chebyshev3_set_test ( ): #*****************************************************************************80 # ## CHEBYSHEV3_SET_TEST tests CHEBYSHEV3_SET. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 12 June 2015 # # Author: # # John Burkardt # import platform print ( '' ) print ( 'CHEBYSHEV3_SET_TEST' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' CHEBYSHEV3_SET sets a Chebyshev Type 3 quadrature rule over [-1,1].' ) print ( '' ) print ( ' Index X W' ) for n in range ( 1, 11 ): x, w = chebyshev3_set ( n ) print ( '' ) for i in range ( 0, n ): print ( ' %2d %24.16g %24.16g' % ( i, x[i], w[i] ) ) # # Terminate. # print ( '' ) print ( 'CHEBYSHEV3_SET_TEST:' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) chebyshev3_set_test ( ) timestamp ( )