#! /usr/bin/env python3 # def wedge01_sample ( n, seed ): #*****************************************************************************80 # ## WEDGE01_SAMPLE samples points uniformly from the unit wedge in 3D. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 23 June 2015 # # Author: # # John Burkardt # # Reference: # # Reuven Rubinstein, # Monte Carlo Optimization, Simulation, and Sensitivity # of Queueing Networks, # Krieger, 1992, # ISBN: 0894647644, # LC: QA298.R79. # # Parameters: # # Input, integer N, the number of points. # # Input/output, integer SEED, a seed for the random # number generator. # # Output, real X(3,N), the points. # import numpy as np from r8vec_uniform_01 import r8vec_uniform_01 m = 3 x = np.zeros ( [ m, n ] ) for j in range ( 0, n ): e, seed = r8vec_uniform_01 ( m + 1, seed ); el = np.zeros ( m ) el_sum = 0.0 for i in range ( 0, m ): el[i] = - np.log ( e[i] ) el_sum = el_sum + el[i] x[0,j] = el[0] / el_sum x[1,j] = el[1] / el_sum x[2,j] = 2.0 * e[3] - 1.0 return x, seed def wedge01_sample_test ( ): #*****************************************************************************80 # ## WEDGE01_SAMPLE_TEST tests WEDGE01_SAMPLE. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 23 June 2015 # # Author: # # John Burkardt # import platform from r8mat_transpose_print import r8mat_transpose_print print ( '' ) print ( 'WEDGE01_SAMPLE_TEST' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' WEDGE01_SAMPLE samples the unit wedge.' ) m = 3 n = 10 seed = 123456789 x, seed = wedge01_sample ( n, seed ) r8mat_transpose_print ( m, n, x, ' Sample points in the unit wedge.' ) # # Terminate. # print ( '' ) print ( 'WEDGE01_SAMPLE_TEST' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) wedge01_sample_test ( ) timestamp ( )