def r8vec_direct_product_test ( ): #*****************************************************************************80 # ## R8VEC_DIRECT_PRODUCT_TEST tests R8VEC_DIRECT_PRODUCT. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 10 April 2015 # # Author: # # John Burkardt # import numpy as np from r8mat_transpose_print import r8mat_transpose_print factor_num = 3 point_num = 24 print '' print 'R8VEC_DIRECT_PRODUCT_TEST' print ' R8VEC_DIRECT_PRODUCT forms the entries of a' print ' direct product of a given number of R8VEC factors.' x = np.zeros ( ( factor_num, point_num ) ) contig = 0 skip = 0 rep = 0 for factor_index in range ( 0, factor_num ): if ( factor_index == 0 ): factor_order = 4 factor_value = np.array ( [ 1.0, 2.0, 3.0, 4.0 ] ) elif ( factor_index == 1 ): factor_order = 3 factor_value = np.array ( [ 50.0, 60.0, 70.0 ] ) elif ( factor_index == 2 ): factor_order = 2 factor_value = np.array ( [ 800.0, 900.0 ] ) x, contig, rep, skip = r8vec_direct_product ( factor_index, factor_order, \ factor_value, factor_num, point_num, x, contig, rep, skip ); r8mat_transpose_print ( factor_num, point_num, x, ' Matrix (transposed)' ) # # Terminate. # print '' print 'R8VEC_DIRECT_PRODUCT_TEST:' print ' Normal end of execution.' return
def r8vec_direct_product_test(): #*****************************************************************************80 # ## R8VEC_DIRECT_PRODUCT_TEST tests R8VEC_DIRECT_PRODUCT. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 10 April 2015 # # Author: # # John Burkardt # import numpy as np from r8mat_transpose_print import r8mat_transpose_print factor_num = 3 point_num = 24 print '' print 'R8VEC_DIRECT_PRODUCT_TEST' print ' R8VEC_DIRECT_PRODUCT forms the entries of a' print ' direct product of a given number of R8VEC factors.' x = np.zeros((factor_num, point_num)) contig = 0 skip = 0 rep = 0 for factor_index in range(0, factor_num): if (factor_index == 0): factor_order = 4 factor_value = np.array([1.0, 2.0, 3.0, 4.0]) elif (factor_index == 1): factor_order = 3 factor_value = np.array([50.0, 60.0, 70.0]) elif (factor_index == 2): factor_order = 2 factor_value = np.array([800.0, 900.0]) x, contig, rep, skip = r8vec_direct_product ( factor_index, factor_order, \ factor_value, factor_num, point_num, x, contig, rep, skip ) r8mat_transpose_print(factor_num, point_num, x, ' Matrix (transposed)') # # Terminate. # print '' print 'R8VEC_DIRECT_PRODUCT_TEST:' print ' Normal end of execution.' return
def simplex_volume_test(): #*****************************************************************************80 # ## SIMPLEX_VOLUME_TEST tests SIMPLEX_VOLUME. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 28 June 2015 # # Author: # # John Burkardt # import numpy as np import platform from r8mat_transpose_print import r8mat_transpose_print print('') print('SIMPLEX_VOLUME_TEST') print(' Python version: %s' % (platform.python_version())) print(' SIMPLEX_VOLUME returns the volume of a simplex') print(' in M dimensions.') m = 2 x2 = np.array ( [ \ [ 0.0, 7.0, 4.0 ], \ [ 0.0, 2.0, 4.0 ] ] ) r8mat_transpose_print(m, m + 1, x2, ' Triangle:') value = simplex_volume(m, x2) print('') print(' Volume = %g' % (value)) m = 3 x3 = np.array ( [ \ [ 0.0, 7.0, 4.0, 0.0 ], \ [ 0.0, 2.0, 4.0, 0.0 ], \ [ 0.0, 0.0, 0.0, 6.0 ] ] ) r8mat_transpose_print(m, m + 1, x3, ' Tetrahedron:') value = simplex_volume(m, x3) print('') print(' Volume = %g' % (value)) # # Terminate. # print('') print('SIMPLEX_VOLUME_TEST') print(' Normal end of execution.') return
def latin_random_test ( seed ): #*****************************************************************************80 # ## TEST01 tests LATIN_RANDOM. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 13 November 2014 # # Author: # # John Burkardt # # Parameters: # # Input/output, integer SEED, a seed for the random number # generator. # from r8mat_transpose_print import r8mat_transpose_print dim_num = 2 point_num = 10 print '' print 'LATIN_RANDOM_TEST' print ' LATIN_RANDOM chooses a random Latin Square' print ' cell arrangement, and then returns' print ' a random point from each cell.' print ' ' print ' Spatial dimension = %d' % ( dim_num ) print ' Number of points = %d' % ( point_num ) print ' Random number SEED = %d' % ( seed ) x, seed = latin_random ( dim_num, point_num, seed ) r8mat_transpose_print ( dim_num, point_num, x, \ ' The Latin Random Square points:' ) print '' print 'LATIN_RANDOM_TEST' print ' Normal end of execution.' return seed
def triangle01_sample_test ( ): #*****************************************************************************80 # ## TRIANGLE01_SAMPLE_TEST tests TRIANGLE01_SAMPLE. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 18 April 2015 # # Author: # # John Burkardt # from r8mat_transpose_print import r8mat_transpose_print print '' print 'TRIANGLE01_SAMPLE_TEST' print ' TRIANGLE01_SAMPLE randomly samples the unit triangle.' m = 2 n = 10 seed = 123456789 print '' print ' Number of samples to select is N = %d' % ( n ) x, seed = triangle01_sample ( n, seed ) r8mat_transpose_print ( m, n, x, ' Random points in unit triangle.' ) # # Terminate. # print '' print 'TRIANGLE01_SAMPLE_TEST:' print ' Normal end of execution.' return
def triangle01_sample_test(): #*****************************************************************************80 # ## TRIANGLE01_SAMPLE_TEST tests TRIANGLE01_SAMPLE. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 18 April 2015 # # Author: # # John Burkardt # from r8mat_transpose_print import r8mat_transpose_print print '' print 'TRIANGLE01_SAMPLE_TEST' print ' TRIANGLE01_SAMPLE randomly samples the unit triangle.' m = 2 n = 10 seed = 123456789 print '' print ' Number of samples to select is N = %d' % (n) x, seed = triangle01_sample(n, seed) r8mat_transpose_print(m, n, x, ' Random points in unit triangle.') # # Terminate. # print '' print 'TRIANGLE01_SAMPLE_TEST:' print ' Normal end of execution.' return
def monomial_value_test ( ): #*****************************************************************************80 # ## MONOMIAL_VALUE_TEST tests MONOMIAL_VALUE. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 18 April 2015 # # Author: # # John Burkardt # import numpy as np from i4vec_print import i4vec_print from r8mat_transpose_print import r8mat_transpose_print from r8mat_uniform_01 import r8mat_uniform_01 print '' print 'MONOMIAL_VALUE_TEST' print ' MONOMIAL_VALUE evaluates a monomial at multiple points X.' m = 2 n = 10 seed = 123456789 print '' print ' Spatial dimension M = %d' % ( m ) print ' Number of samples to select is N = %d' % ( n ) x, seed = r8mat_uniform_01 ( m, n, seed ) r8mat_transpose_print ( m, n, x, ' Random points.' ) e = np.array ( [ 1, 2 ], dtype = np.int32 ) i4vec_print ( m, e, ' Monomial exponents:' ) v = monomial_value ( m, n, e, x ) print '' print ' Monomial values:' print '' print ' J X Y X*Y^2' print '' for j in range ( 0, n ): print ' %2d:' % ( j ), for i in range ( 0, m ): print ' %10.4g' % ( x[i,j] ), print ' %10.4g' % ( v[j] ) # # Terminate. # print '' print 'MONOMIAL_VALUE_TEST:' print ' Normal end of execution.' return
def monomial_value_test(): #*****************************************************************************80 # ## MONOMIAL_VALUE_TEST tests MONOMIAL_VALUE. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 18 April 2015 # # Author: # # John Burkardt # import numpy as np from i4vec_print import i4vec_print from r8mat_transpose_print import r8mat_transpose_print from r8mat_uniform_01 import r8mat_uniform_01 print '' print 'MONOMIAL_VALUE_TEST' print ' MONOMIAL_VALUE evaluates a monomial at multiple points X.' m = 2 n = 10 seed = 123456789 print '' print ' Spatial dimension M = %d' % (m) print ' Number of samples to select is N = %d' % (n) x, seed = r8mat_uniform_01(m, n, seed) r8mat_transpose_print(m, n, x, ' Random points.') e = np.array([1, 2], dtype=np.int32) i4vec_print(m, e, ' Monomial exponents:') v = monomial_value(m, n, e, x) print '' print ' Monomial values:' print '' print ' J X Y X*Y^2' print '' for j in range(0, n): print ' %2d:' % (j), for i in range(0, m): print ' %10.4g' % (x[i, j]), print ' %10.4g' % (v[j]) # # Terminate. # print '' print 'MONOMIAL_VALUE_TEST:' print ' Normal end of execution.' return