#! /usr/bin/env python # def p_integral ( n ): #*****************************************************************************80 # ## P_INTEGRAL evaluates a monomial integral associated with P(n,x). # # Discussion: # # The integral: # # integral ( -1 <= x < +1 ) x^n dx # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 15 March 2016 # # Author: # # John Burkardt # # Parameters: # # Input, integer N, the exponent. # 0 <= N. # # Output, real VALUE, the value of the integral. # if ( ( n % 2 ) == 1 ): value = 0.0 else: value = 2.0 / ( n + 1 ) return value def p_integral_test ( ): #*****************************************************************************80 # ## P_INTEGRAL_TEST tests P_INTEGRAL. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 15 March 2016 # # Author: # # John Burkardt # import platform print ( '' ) print ( 'P_INTEGRAL_TEST' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' P_INTEGRAL returns the integral of P(n,x) over [-1,+1].' ) print ( '' ) print ( ' N Integral' ) print ( '' ) for n in range ( 0, 11 ): value = p_integral ( n ) print ( ' %4d %24.16g' % ( n, value ) ) # # Terminate. # print ( '' ) print ( 'P_INTEGRAL_TEST' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) p_integral_test ( ) timestamp ( )