#! /usr/bin/env python # def t_moment ( e ): #*****************************************************************************80 # ## T_MOMENT: integral ( -1 <= x <= +1 ) x^e dx / sqrt ( 1 - x^2 ). # # Discussion: # # Set # x = cos ( theta ), # dx = - sin ( theta ) d theta = - sqrt ( 1 - x^2 ) d theta # to transform the integral to # integral ( 0 <= theta <= pi ) - ( cos ( theta ) )^e d theta # which becomes # 0 if E is odd, # (1/2^e) * choose ( e, e/2 ) * pi if E is even. # # 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_choose import r8_choose if ( ( e % 2 ) == 1 ): value = 0.0 else: value = r8_choose ( e, e // 2 ) * np.pi / 2.0 ** e return value def t_moment_test ( ): #*****************************************************************************80 # ## T_MOMENT_TEST tests T_MOMENT. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 14 July 2015 # # Author: # # John Burkardt # import platform print ( '' ) print ( 'T_MOMENT_TEST:' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' T_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 = t_moment( e ) print ( ' %2d %14.6g' % ( e, value ) ) # # Terminate. # print ( '' ) print ( 'T_MOMENT_TEST:' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) t_moment_test ( ) timestamp ( )