#! /usr/bin/env python # def w_moment ( e ): #*****************************************************************************80 # ## W_MOMENT: integral ( -1 <= x <= +1 ) x^e sqrt(1-x) / sqrt(1+x) dx. # # Discussion: # # This function returns the moments of the distribution associated # with the Chebyshev W polynomial. # # E W_MOMENT # -- ------------- # 0 pi # 1 - pi / 2 # 2 pi / 2 # 3 - 3 pi / 8 # 4 3 pi / 8 # 5 - 5 pi / 16 # 6 5 pi / 16 # 7 - 35 pi / 128 # 8 35 pi / 128 # 9 - 63 pi / 256 # 10 63 pi / 256 # 11 - 231 pi / 1024 # 12 231 pi / 1024 # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 18 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_factorial import r8_factorial from r8_gamma import r8_gamma from r8_hyper_2f1 import r8_hyper_2f1 from r8_mop import r8_mop r8_e = float ( e ) f1 = 1.0 / r8_gamma ( 1.5 + r8_e ) f2 = r8_mop ( e ) f3 = np.pi * r8_gamma ( 1.5 + r8_e ) f4 = 2.0 * r8_mop ( e ) * r8_hyper_2f1 ( 0.5, - r8_e, 1.0, 2.0 ) f5 = ( -1.0 + r8_mop ( e ) ) * r8_hyper_2f1 ( 0.5, - r8_e, 2.0, 2.0 ) f6 = np.sqrt ( np.pi ) * r8_factorial ( e ) f7 = ( - 1.0 + r8_mop ( e ) ) * r8_hyper_2f1 ( -0.5, 1.0 + r8_e, 1.5 + r8_e, - 1.0 ) f8 = 2.0 * r8_mop ( e ) * r8_hyper_2f1 ( 0.5, 1.0 + r8_e, 1.5 + r8_e, -1.0 ) value = f1 * f2 * ( f3 * ( f4 - f5 ) + f6 * ( f7 - f8 ) ) return value def w_moment_test ( ): #*****************************************************************************80 # ## W_MOMENT_TEST tests W_MOMENT. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 18 July 2015 # # Author: # # John Burkardt # import platform print ( '' ) print ( 'W_MOMENT_TEST:' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' W_MOMENT returns the value of' ) print ( ' integral ( -1 <=x <= +1 ) x^e * sqrt(1-x) / sqrt(1+x) dx' ) print ( '' ) print ( ' E Integral' ) print ( '' ) for e in range ( 0, 11 ): value = w_moment ( e ) print ( ' %2d %14.6g' % ( e, value ) ) # # Terminate. # print ( '' ) print ( 'W_MOMENT_TEST:' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) w_moment_test ( ) timestamp ( )