#! /usr/bin/env python # def grid_side ( m, n ): #*****************************************************************************80 # ## GRID_SIDE finds the smallest M-D grid containing at least N points. # # Discussion: # # Each coordinate of the grid will have N_SIDE distinct values. # Thus the total number of points in the grid is N_SIDE**M. # This routine seeks the smallest N_SIDE such that N <= N_SIDE**M. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 22 August 2016 # # Author: # # John Burkardt # # Parameters: # # Input, integer M, the spatial dimension. # # Input, integer N, the number of points to generate. # # Output, integer N_SIDE, the length of one side of the smallest # grid in M dimensions that contains at least N points. # if ( n <= 0 ): n_side = 0 elif ( m <= 0 ): n_side = -1 else: exponent = 1.0 / float ( m ) n_side = int ( ( float ( n ) ) ** exponent ) if ( ( n_side ** m ) < n ): n_side = n_side + 1 return n_side def grid_side_test ( ): #*****************************************************************************80 # ## GRID_SIDE_TEST tests GRID_SIDE. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 22 August 2016 # # Author: # # John Burkardt # import platform print ( '' ) print ( 'GRID_SIDE_TEST' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' GRID_SIDE returns the smallest N_SIDE, such that' ) print ( ' N <= NSIDE^M' ) print ( '' ) print ( ' M N NSIDE NSIDE^M' ) for m in range ( 2, 5 ): print ( '' ) for n in [ 10, 100, 1000, 10000 ]: n_side = grid_side ( m, n ) print ( ' %1d %5d %5d %5d' % ( m, n, n_side, n_side ** m ) ) # # Terminate. # print ( '' ) print ( 'GRID_SIDE_TEST:' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) grid_side_test ( ) timestamp ( )