#! /usr/bin/env python # def pyramid01_sample ( n, seed ): #*****************************************************************************80 # ## PYRAMID01_SAMPLE: sample the unit pyramid. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 22 June 2015 # # Author: # # John Burkardt # # Parameters: # # Input, integer N, the number of samples desired. # # Input/output, integer SEED, a seed for the random # number generator. # # Output, real X(3,N), the sample values. # from r8mat_uniform_01 import r8mat_uniform_01 one_third = 1.0 / 3.0 x, seed = r8mat_uniform_01 ( 3, n, seed ) for j in range ( 0, n ): x[2,j] = 1.0 - x[2,j] ** one_third x[1,j] = ( 1.0 - x[2,j] ) * ( 2.0 * x[1,j] - 1.0 ) x[0,j] = ( 1.0 - x[2,j] ) * ( 2.0 * x[0,j] - 1.0 ) return x, seed def pyramid01_sample_test ( ): #*****************************************************************************80 # ## PYRAMID01_SAMPLE_TEST tests PYRAMID01_SAMPLE. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 22 June 2015 # # Author: # # John Burkardt # import platform from r8mat_transpose_print import r8mat_transpose_print print ( '' ) print ( 'PYRAMID01_SAMPLE_TEST' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' PYRAMID01_SAMPLE samples points from the unit pyramid.' ) n = 20 seed = 123456789 x, seed = pyramid01_sample ( n, seed ) m = 3 r8mat_transpose_print ( m, n, x, ' Unit pyramid points' ) # # Terminate. # print ( '' ) print ( 'PYRAMID01_SAMPLE_TEST' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) pyramid01_sample_test ( ) timestamp ( )