#! /usr/bin/env python # def disk01_quarter_monomial_integral ( e ): #*****************************************************************************80 # ## DISK01_QUARTER_MONOMIAL_INTEGRAL: monomial integrals in unit quarter disk. # # Discussion: # # The integration region is # # X^2 + Y^2 <= 1. # 0 <= X, 0 <= Y. # # The monomial is F(X,Y) = X^E(1) * Y^E(2). # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 06 May 2016 # # Author: # # John Burkardt # # Parameters: # # Input, integer E(2), the exponents of X and Y in the # monomial. Each exponent must be nonnegative. # # Output, real INTEGRAL, the integral. # from r8_gamma import r8_gamma f1 = r8_gamma ( ( e[0] + 3 ) / 2.0 ) f2 = r8_gamma ( ( e[1] + 1 ) / 2.0 ) f3 = r8_gamma ( ( e[0] + e[1] + 4 ) / 2.0 ) integral = f1 * f2 / f3 / 2.0 / ( 1.0 + e[0] ) return integral def disk01_quarter_monomial_integral_test ( ): #*****************************************************************************80 # ## DISK01_QUARTER_MONOMIAL_INTEGRAL_TEST tests DISK01_QUARTER_MONOMIAL_INTEGRAL. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 06 May 2016 # # Author: # # John Burkardt # import numpy as np import platform from disk01_quarter_area import disk01_quarter_area from disk01_quarter_sample import disk01_quarter_sample from i4vec_uniform_ab import i4vec_uniform_ab from monomial_value import monomial_value m = 2 n = 4192 test_num = 20 print ( '' ) print ( 'DISK01_QUARTER_MONOMIAL_INTEGRAL_TEST' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' DISK01_QUARTER_MONOMIAL_INTEGRAL computes monomial integrals' ) print ( ' over the interior of the unit disk in 2D.' ) print ( ' Compare with a Monte Carlo value.' ) # # Get sample points. # seed = 123456789 x, seed = disk01_quarter_sample ( n, seed ) print ( '' ) print ( ' Number of sample points used is %d' % ( n ) ) # # Randomly choose X,Y exponents between 0 and 8. # print ( '' ) print ( ' We will restrict this test to randomly chosen even exponents.' ) print ( '' ) print ( ' Ex Ey MC-Estimate Exact Error' ) print ( '' ) for test in range ( 0, test_num ): e, seed = i4vec_uniform_ab ( m, 0, 4, seed ) value = monomial_value ( m, n, e, x ) result = disk01_quarter_area ( ) * np.sum ( value ) / float ( n ) exact = disk01_quarter_monomial_integral ( e ) error = abs ( result - exact ) print ( ' %2d %2d %14.6g %14.6g %10.2g' \ % ( e[0], e[1], result, exact, error ) ) # # Terminate. # print ( '' ) print ( 'DISK01_QUARTER_MONOMIAL_INTEGRAL_TEST:' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) disk01_quarter_monomial_integral_test ( ) timestamp ( )