#! /usr/bin/env python # def u_moment ( e ): #*****************************************************************************80 # ## U_MOMENT: integral ( -1 <= x <= +1 ) x^e sqrt ( 1 - x^2 ) dx. # # Discussion: # # E U_MOMENT # -- -------------- # 0 pi / 2 # 2 pi / 8 # 4 pi / 16 # 6 5 * pi / 128 # 8 7 * pi / 256 # 10 21 * pi / 1024 # 12 33 * pi / 2048 # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 14 July 2015 # # Author: # # John Burkardt # # Parameters: # # Input, integer E, the exponent of X. # 0 <= E. # # Output, real VALUE, the value of the integral. # import numpy as np from r8_gamma import r8_gamma if ( ( e % 2 ) == 1 ): value = 0.0 else: arg1 = 0.5 * float ( 1 + e ) arg2 = 2.0 + 0.5 * float ( e ) value = 0.5 * np.sqrt ( np.pi ) * r8_gamma ( arg1 ) / r8_gamma ( arg2 ) return value def u_moment_test ( ): #*****************************************************************************80 # ## U_MOMENT_TEST tests U_MOMENT. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 14 July 2015 # # Author: # # John Burkardt # import platform print ( '' ) print ( 'U_MOMENT_TEST:' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' U_MOMENT returns the value of' ) print ( ' integral ( -1 <=x <= +1 ) x^e * sqrt ( 1 - x^2 ) dx' ) print ( '' ) print ( ' E Integral' ) print ( '' ) for e in range ( 0, 11 ): value = u_moment ( e ) print ( ' %2d %14.6g' % ( e, value ) ) # # Terminate. # print ( '' ) print ( 'U_MOMENT_TEST:' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) u_moment_test ( ) timestamp ( )