#! /usr/bin/env python # def hermite_1_set ( n ): #*****************************************************************************80 # ## HERMITE_1_SET sets abscissas and weights for Hermite quadrature. # # Discussion: # # This routine is for the case with unit density: # integral ( -oo < x < +oo ) f(x) dx # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 19 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.7724538509055161 ] ) elif ( n == 2 ): x = np.array ( [ \ - 0.707106781186547524400844362105, \ 0.707106781186547524400844362105 ] ) w = np.array ( [ \ 1.4611411826611391, \ 1.4611411826611391 ] ) elif ( n == 3 ): x = np.array ( [ \ - 1.22474487139158904909864203735, \ 0.0, \ 1.22474487139158904909864203735 ] ) w = np.array ( [ \ 1.3239311752136438, \ 1.1816359006036774, \ 1.3239311752136438 ] ) elif ( n == 4 ): x = np.array ( [ \ - 1.65068012388578455588334111112, \ - 0.524647623275290317884060253835, \ 0.524647623275290317884060253835, \ 1.65068012388578455588334111112 ] ) w = np.array ( [ \ 1.2402258176958150, \ 1.0599644828949693, \ 1.0599644828949693, \ 1.2402258176958150 ] ) elif ( n == 5 ): x = np.array ( [ \ - 2.02018287045608563292872408814, \ - 0.958572464613818507112770593893, \ 0.0, \ 0.958572464613818507112770593893, \ 2.02018287045608563292872408814 ] ) w = np.array ( [ \ 1.1814886255359869, \ 0.98658099675142830, \ 0.94530872048294190, \ 0.98658099675142830, \ 1.1814886255359869 ] ) elif ( n == 6 ): x = np.array ( [ \ - 2.35060497367449222283392198706, \ - 1.33584907401369694971489528297, \ - 0.436077411927616508679215948251, \ 0.436077411927616508679215948251, \ 1.33584907401369694971489528297, \ 2.35060497367449222283392198706 ] ) w = np.array ( [ \ 1.1369083326745253, \ 0.93558055763118075, \ 0.87640133443623058, \ 0.87640133443623058, \ 0.93558055763118075, \ 1.1369083326745253 ] ) elif ( n == 7 ): x = np.array ( [ \ - 2.65196135683523349244708200652, \ - 1.67355162876747144503180139830, \ - 0.816287882858964663038710959027, \ 0.0, \ 0.816287882858964663038710959027, \ 1.67355162876747144503180139830, \ 2.65196135683523349244708200652 ] ) w = np.array ( [ \ 1.1013307296103216, \ 0.89718460022518409, \ 0.82868730328363926, \ 0.81026461755680734, \ 0.82868730328363926, \ 0.89718460022518409, \ 1.1013307296103216 ] ) elif ( n == 8 ): x = np.array ( [ \ - 2.93063742025724401922350270524, \ - 1.98165675669584292585463063977, \ - 1.15719371244678019472076577906, \ - 0.381186990207322116854718885584, \ 0.381186990207322116854718885584, \ 1.15719371244678019472076577906, \ 1.98165675669584292585463063977, \ 2.93063742025724401922350270524 ] ) w = np.array ( [ \ 1.0719301442479805, \ 0.86675260656338138, \ 0.79289004838640131, \ 0.76454412865172916, \ 0.76454412865172916, \ 0.79289004838640131, \ 0.86675260656338138, \ 1.0719301442479805 ] ) elif ( n == 9 ): x = np.array ( [ \ - 3.19099320178152760723004779538, \ - 2.26658058453184311180209693284, \ - 1.46855328921666793166701573925, \ - 0.723551018752837573322639864579, \ 0.0, \ 0.723551018752837573322639864579, \ 1.46855328921666793166701573925, \ 2.26658058453184311180209693284, \ 3.19099320178152760723004779538 ] ) w = np.array ( [ \ 1.0470035809766838, \ 0.84175270147867043, \ 0.76460812509455023, \ 0.73030245274509220, \ 0.72023521560605097, \ 0.73030245274509220, \ 0.76460812509455023, \ 0.84175270147867043, \ 1.0470035809766838 ] ) elif ( n == 10 ): x = np.array ( [ \ - 3.43615911883773760332672549432, \ - 2.53273167423278979640896079775, \ - 1.75668364929988177345140122011, \ - 1.03661082978951365417749191676, \ - 0.342901327223704608789165025557, \ 0.342901327223704608789165025557, \ 1.03661082978951365417749191676, \ 1.75668364929988177345140122011, \ 2.53273167423278979640896079775, \ 3.43615911883773760332672549432 ] ) w = np.array ( [ \ 1.0254516913657352, \ 0.82066612640481640, \ 0.74144193194356511, \ 0.70329632310490608, \ 0.68708185395127341, \ 0.68708185395127341, \ 0.70329632310490608, \ 0.74144193194356511, \ 0.82066612640481640, \ 1.0254516913657352 ] ) else: print ( '' ) print ( 'HERMITE_1_SET - Fatal error!' ) print ( ' Illegal value of N = %d' % ( n ) ) print ( ' Legal values are 1 to 10.' ) exit ( 'HERMITE_1_SET - Fatal error!' ) return x, w def hermite_1_set_test ( ): #*****************************************************************************80 # ## HERMITE_1_SET_TEST tests HERMITE_1_SET. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 19 June 2015 # # Author: # # John Burkardt # import platform print ( '' ) print ( 'HERMITE_1_SET_TEST' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' HERMITE_1_SET sets a unit density Hermite quadrature rule.' ) print ( ' The interval is (-oo,+oo).' ) print ( ' The density is 1.0.' ) print ( '' ) print ( ' Index X W' ) print ( '' ) for n in range ( 1, 11 ): x, w = hermite_1_set ( n ) print ( '' ) for i in range ( 0, n ): print ( ' %2d %24.16g %24.16g' % ( i, x[i], w[i] ) ) # # Terminate. # print ( '' ) print ( 'HERMITE_1_SET_TEST:' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) hermite_1_set_test ( ) timestamp ( )