#! /usr/bin/env python # def triangle_monte_carlo_test02 ( ): #*****************************************************************************80 # ## TRIANGLE_MONTE_CARLO_TEST02 samples a general triangle. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 18 July 2018 # # Author: # # John Burkardt # import numpy as np from r8mat_transpose_print import r8mat_transpose_print from triangle_monte_carlo import triangle_monte_carlo t = np.array ( [ \ [ 2.0, 3.0, 0.0 ], \ [ 0.0, 4.0, 3.0 ] ] ) r8mat_transpose_print ( 2, 3, t, ' Triangle vertices:' ) print ( '' ) print ( 'TRIANGLE_MONTE_CARLO_TEST02' ) print ( ' Integrate xy^3' ) print ( ' Integration region is a general triangle.' ) print ( ' Use an increasing number of points N.' ) seed = 123456789 print ( '' ) print ( ' N XY^3' ) print ( '' ) n = 1 while ( n <= 65536 ): result, seed = triangle_monte_carlo ( t, n, triangle_integrand, seed ) print ( ' %8d %14f' % ( n, result ) ) n = 2 * n return def triangle_integrand ( p ): #*****************************************************************************80 # ## TRIANGLE_INTEGRAND evaluates xy^3 # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 15 August 2009 # # Author: # # John Burkardt # # Parameters: # # Input, real P(2,P_NUM), the evaluation points. # # Output, real FP(P_NUM), the integrand values. # fp = p[0,:] * p[1,:] ** 3 return fp if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) triangle_monte_carlo_test02 ( ) timestamp ( )