コード例 #1
0
def i4vec_data_read_test ( ):

#*****************************************************************************80
#
## I4VEC_DATA_READ_TEST tests I4VEC_DATA_READ.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    03 December 2014
#
#  Author:
#
#    John Burkardt
#
  from i4vec_print import i4vec_print

  print ''
  print 'I4VEC_DATA_READ_TEST:'
  print '  Test I4VEC_DATA_READ, which reads data from an I4VEC.'

  m = 5
  n = 3
  filename = 'i4vec_write_test.txt'
  a = i4vec_data_read ( filename, m )
  i4vec_print ( m, a, '  Data read from file:' )

  print ''
  print 'I4VEC_DATA_READ_TEST:'
  print '  Normal end of execution.'

  return
コード例 #2
0
def fibonacci_recursive_test ( ):

#*****************************************************************************80
#
## FIBONACCI_RECURSIVE_TEST tests FIBONACCI_RECURSIVE.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    07 February 2015
#
#  Author:
#
#    John Burkardt
#
  from i4vec_print import i4vec_print

  n = 20

  print ''
  print 'FIBONACCI_RECURSIVE_TEST'
  print '  FIBONACCI_RECURSIVE computes Fibonacci numbers recursively;'

  f = fibonacci_recursive ( n )

  i4vec_print ( n + 1, f, '  The Fibonacci numbers:' )

  print ''
  print 'FIBONACCI_RECURSIVE_TEST'
  print '  Normal end of execution.'

  return
コード例 #3
0
def i4vec_indicator0_test ( ):

#*****************************************************************************80
#
## I4VEC_INDICATOR0_TEST tests I4VEC_INDICATOR0.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    08 November 2014
#
#  Author:
#
#    John Burkardt
#
  from i4vec_print import i4vec_print

  print ''
  print 'I4VEC_INDICATOR0_TEST'
  print '  I4VEC_INDICATOR0 returns an indicator vector.'

  n = 10
  a = i4vec_indicator0 ( n )
  i4vec_print ( n, a, '  The indicator0 vector:' )

  print ''
  print 'I4VEC_INDICATOR0_TEST'
  print '  Normal end of execution.'

  return
コード例 #4
0
def i4vec_indicator0_test():

    #*****************************************************************************80
    #
    ## I4VEC_INDICATOR0_TEST tests I4VEC_INDICATOR0.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    08 November 2014
    #
    #  Author:
    #
    #    John Burkardt
    #
    from i4vec_print import i4vec_print

    print ''
    print 'I4VEC_INDICATOR0_TEST'
    print '  I4VEC_INDICATOR0 returns an indicator vector.'

    n = 10
    a = i4vec_indicator0(n)
    i4vec_print(n, a, '  The indicator0 vector:')
    #
    #  Terminate.
    #
    print ''
    print 'I4VEC_INDICATOR0_TEST'
    print '  Normal end of execution.'

    return
コード例 #5
0
def fibonacci_recursive_test():

    #*****************************************************************************80
    #
    ## FIBONACCI_RECURSIVE_TEST tests FIBONACCI_RECURSIVE.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    07 February 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    from i4vec_print import i4vec_print

    n = 20

    print ''
    print 'FIBONACCI_RECURSIVE_TEST'
    print '  FIBONACCI_RECURSIVE computes Fibonacci numbers recursively;'

    f = fibonacci_recursive(n)

    i4vec_print(n + 1, f, '  The Fibonacci numbers:')

    print ''
    print 'FIBONACCI_RECURSIVE_TEST'
    print '  Normal end of execution.'

    return
コード例 #6
0
def i4vec_frac_test():

    #*****************************************************************************80
    #
    #% I4VEC_FRAC_TEST tests I4VEC_FRAC
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    26 May 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    from i4vec_print import i4vec_print
    from i4vec_uniform_ab import i4vec_uniform_ab

    n = 10
    b = 1
    c = 2 * n
    seed = 123456789

    print ''
    print 'I4VEC_FRAC_TEST'
    print '  I4VEC_FRAC: K-th smallest integer vector entry.'
    print '  Using initial random number seed = %d' % (seed)

    a, seed = i4vec_uniform_ab(n, b, c, seed)

    i4vec_print(n, a, '  The array to search:')

    print ''
    print '  Fractile    Value'
    print ''

    nh = (n // 3)

    for k in range(1, n + 1, nh):

        afrac = i4vec_frac(n, a, k)

        print '  %6d  %6d' % (k, afrac)


#
#  Terminate.
#
    print ''
    print 'I4VEC_FRAC_TEST'
    print '  Normal end of execution.'

    return
コード例 #7
0
def i4vec_sort_heap_index_a_test():

    #*****************************************************************************80
    #
    ## I4VEC_SORT_HEAP_INDEX_A_TEST tests I4VEC_SORT_HEAP_INDEX_A.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    27 October 2014
    #
    #  Author:
    #
    #    John Burkardt
    #
    from i4vec_print import i4vec_print
    from i4vec_uniform_ab import i4vec_uniform_ab

    n = 20

    print ''
    print 'I4VEC_SORT_HEAP_INDEX_A_TEST'
    print '  I4VEC_SORT_HEAP_INDEX_A creates an ascending'
    print '  sort index for an I4VEC.'

    b = 0
    c = 3 * n
    seed = 123456789

    a, seed = i4vec_uniform_ab(n, b, c, seed)

    i4vec_print(n, a, '  Unsorted array A:')

    indx = i4vec_sort_heap_index_a(n, a)

    i4vec_print(n, indx, '  Sort vector INDX:')

    print ''
    print '       I   INDX(I)  A(INDX(I))'
    print ''
    for i in range(0, n):
        print '  %8d  %8d  %8d' % (i, indx[i], a[indx[i]])


#
#  Terminate.
#
    print ''
    print 'I4VEC_SORT_HEAP_INDEX_A_TEST:'
    print '  Normal end of execution.'

    return
コード例 #8
0
def i4vec_frac_test ( ):

#*****************************************************************************80
#
#% I4VEC_FRAC_TEST tests I4VEC_FRAC
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    26 May 2015
#
#  Author:
#
#    John Burkardt
#
  from i4vec_print import i4vec_print
  from i4vec_uniform_ab import i4vec_uniform_ab

  n = 10
  b = 1
  c = 2 * n
  seed = 123456789

  print ''
  print 'I4VEC_FRAC_TEST'
  print '  I4VEC_FRAC: K-th smallest integer vector entry.'
  print '  Using initial random number seed = %d' % ( seed )

  a, seed = i4vec_uniform_ab ( n, b, c, seed )

  i4vec_print ( n, a, '  The array to search:' )

  print ''
  print '  Fractile    Value'
  print ''

  nh = ( n // 3 )

  for k in range ( 1, n + 1, nh ):

    afrac = i4vec_frac ( n, a, k )

    print '  %6d  %6d' % ( k, afrac )
#
#  Terminate.
#
  print ''
  print 'I4VEC_FRAC_TEST'
  print '  Normal end of execution.'

  return
コード例 #9
0
def i4vec_index_test():

    #*****************************************************************************80
    #
    ## I4VEC_INDEX_TEST tests I4VEC_INDEX;
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    27 May 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    from i4vec_print import i4vec_print
    from i4vec_uniform_ab import i4vec_uniform_ab

    n = 10

    print ''
    print 'I4VEC_INDEX_TEST'
    print '  For an integer vector:'
    print '  I4VEC_INDEX:              first index of given value;'

    seed = 123456789
    i4_lo = -n
    i4_hi = n

    a, seed = i4vec_uniform_ab(n, i4_lo, i4_hi, seed)

    i4vec_print(n, a, '  Input vector:')

    i = (n // 2)
    aval = a[i]

    print ''
    j = i4vec_index(n, a, aval)
    print '  Index of first occurrence of %d is %d' % (aval, j)

    aval = aval + 1
    j = i4vec_index(n, a, aval)
    print '  Index of first occurrence of %d is %d' % (aval, j)
    #
    #  Terminate.
    #
    print ''
    print 'I4VEC_INDEX_TEST:'
    print '  Normal end of execution.'

    return
コード例 #10
0
def i4vec_index_test ( ):

#*****************************************************************************80
#
## I4VEC_INDEX_TEST tests I4VEC_INDEX;
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    27 May 2015
#
#  Author:
#
#    John Burkardt
#
  from i4vec_print import i4vec_print
  from i4vec_uniform_ab import i4vec_uniform_ab

  n = 10

  print ''
  print 'I4VEC_INDEX_TEST'
  print '  For an integer vector:'
  print '  I4VEC_INDEX:              first index of given value;'

  seed = 123456789
  i4_lo = -n
  i4_hi = n

  a, seed = i4vec_uniform_ab ( n, i4_lo, i4_hi, seed );

  i4vec_print ( n, a, '  Input vector:' )

  i = ( n // 2 )
  aval = a[i]

  print ''
  j = i4vec_index ( n, a, aval )
  print '  Index of first occurrence of %d is %d' % ( aval, j )

  aval = aval + 1
  j = i4vec_index ( n, a, aval )
  print '  Index of first occurrence of %d is %d' % ( aval, j )
#
#  Terminate.
#
  print ''
  print 'I4VEC_INDEX_TEST:'
  print '  Normal end of execution.'

  return
コード例 #11
0
def i4vec_sort_heap_index_d_test ( ):

#*****************************************************************************80
#
## I4VEC_SORT_HEAP_INDEX_D_TEST tests I4VEC_SORT_HEAP_INDEX_D.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    25 May 2015
#
#  Author:
#
#    John Burkardt
#
  from i4vec_print import i4vec_print
  from i4vec_uniform_ab import i4vec_uniform_ab

  n = 20

  print ''
  print 'I4VEC_SORT_HEAP_INDEX_D_TEST'
  print '  I4VEC_SORT_HEAP_INDEX_D creates a descending'
  print '  sort index for an I4VEC.'

  b = 0
  c = 3 * n
  seed = 123456789

  a, seed = i4vec_uniform_ab ( n, b, c, seed )

  i4vec_print ( n, a, '  Unsorted array A:' )

  indx = i4vec_sort_heap_index_d ( n, a )

  i4vec_print ( n, indx, '  Sort vector INDX:' )

  print ''
  print '       I   INDX(I)  A(INDX(I))'
  print ''
  for i in range ( 0, n ):
     print '  %8d  %8d  %8d' % ( i, indx[i], a[indx[i]] )
#
#  Terminate.
#
  print ''
  print 'I4VEC_SORT_HEAP_INDEX_D_TEST:'
  print '  Normal end of execution.'

  return
コード例 #12
0
def i4vec_sort_heap_index_a_test ( ):

#*****************************************************************************80
#
## I4VEC_SORT_HEAP_INDEX_A_TEST tests I4VEC_SORT_HEAP_INDEX_A.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    27 October 2014
#
#  Author:
#
#    John Burkardt
#
  from i4vec_print import i4vec_print
  from i4vec_uniform_ab import i4vec_uniform_ab

  n = 20

  print ''
  print 'I4VEC_SORT_HEAP_INDEX_A_TEST'
  print '  I4VEC_SORT_HEAP_INDEX_A creates an ascending'
  print '  sort index for an I4VEC.'

  b = 0
  c = 3 * n
  seed = 123456789

  a, seed = i4vec_uniform_ab ( n, b, c, seed )

  i4vec_print ( n, a, '  Unsorted array A:' )

  indx = i4vec_sort_heap_index_a ( n, a )

  i4vec_print ( n, indx, '  Sort vector INDX:' )

  print ''
  print '       I   INDX(I)  A(INDX(I))'
  print ''
  for i in range ( 0, n ):
     print '  %8d  %8d  %8d' % ( i, indx[i], a[indx[i]] )

  return
コード例 #13
0
def i4vec_reverse_test ( ):

#*****************************************************************************80
#
## I4VEC_REVERSE_TEST tests I4VEC_REVERSE.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    14 April 2009
#
#  Author:
#
#    John Burkardt
#
  from i4vec_print import i4vec_print
  from i4vec_uniform_ab import i4vec_uniform_ab

  n = 10
  b = 0
  c = 3 * n

  print ''
  print 'I4VEC_REVERSE_TEST'
  print '  I4VEC_REVERSE reverses a list of integers.'

  seed = 123456789

  a, seed = i4vec_uniform_ab ( n, b, c, seed )

  i4vec_print ( n, a, '  Original vector:' )

  a = i4vec_reverse ( n, a )

  i4vec_print ( n, a, '  Reversed:' )
#
#  Terminate.
#
  print ''
  print 'I4VEC_REVERSE_TEST:'
  print '  Normal end of execution.'

  return
コード例 #14
0
def r8vec_permute_test():

    #*****************************************************************************80
    #
    ## R8VEC_PERMUTE_TEST tests R8VEC_PERMUTE.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    26 October 2014
    #
    #  Author:
    #
    #    John Burkardt
    #
    from i4vec_print import i4vec_print
    from r8vec_print import r8vec_print
    import numpy as np

    n = 5

    print ''
    print 'R8VEC_PERMUTE_TEST'
    print '  R8VEC_PERMUTE permutes an R8VEC.'

    x = np.array([1.1, 2.2, 3.3, 4.4, 5.5], dtype=np.float64)
    p = np.array([1, 3, 4, 0, 2], dtype=np.int32)

    r8vec_print(n, x, '  Original array X[]:')

    i4vec_print(n, p, '  Permutation vector P[]:')

    x = r8vec_permute(n, p, x)

    r8vec_print(n, x, '  Permuted array X[P[*]]:')
    #
    #  Terminate.
    #
    print ''
    print 'R8VEC_PERMUTE_TEST:'
    print '  Normal end of execution.'

    return
コード例 #15
0
def i4vec_uniform_ab_test ( ):

#*****************************************************************************80
#
## I4VEC_UNIFORM_AB_TEST tests I4VEC_UNIFORM_AB.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license. 
#
#  Modified:
#
#    27 October 2014
#
#  Author:
#
#    John Burkardt
#
  from i4vec_print import i4vec_print

  n = 20
  a = -100
  b = 200
  seed = 123456789

  print ''
  print 'I4VEC_UNIFORM_AB_TEST'
  print '  I4VEC_UNIFORM_AB computes pseudorandom values'
  print '  in an interval [A,B].'
  print ''
  print '  The lower endpoint A = %d' % ( a )
  print '  The upper endpoint B = %d' % ( b )
  print '  The initial seed is %d' % ( seed )
  print ''

  v, seed = i4vec_uniform_ab ( n, a, b, seed )

  i4vec_print ( n, v, '  The random vector:' )
#
#  Terminate.
#
  print ''
  print 'I4VEC_UNIFORM_AB_TEST:'
  print '  Normal end of execution.'

  return
コード例 #16
0
def r8vec_permute_test ( ):

#*****************************************************************************80
#
## R8VEC_PERMUTE_TEST tests R8VEC_PERMUTE.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    26 October 2014
#
#  Author:
#
#    John Burkardt
#
  from i4vec_print import i4vec_print
  from r8vec_print import r8vec_print
  import numpy as np

  n = 5

  print ''
  print 'R8VEC_PERMUTE_TEST'
  print '  R8VEC_PERMUTE permutes an R8VEC.'

  x = np.array ( [ 1.1, 2.2, 3.3, 4.4, 5.5 ], dtype = np.float64 )
  p = np.array ( [ 1, 3, 4, 0, 2 ], dtype = np.int32 )

  r8vec_print ( n, x, '  Original array X[]:' )

  i4vec_print ( n, p, '  Permutation vector P[]:' )

  x = r8vec_permute ( n, p, x )

  r8vec_print ( n, x, '  Permuted array X[P[*]]:' )
#
#  Terminate.
#
  print ''
  print 'R8VEC_PERMUTE_TEST:'
  print '  Normal end of execution.'

  return
コード例 #17
0
def i4vec_max_test ( ):

#*****************************************************************************80
#
## I4VEC_MAX_TEST tests I4VEC_MAX.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    08 November 2014
#
#  Author:
#
#    John Burkardt
#
  from i4vec_print import i4vec_print
  from i4vec_uniform_ab import i4vec_uniform_ab

  print ''
  print 'I4VEC_MAX_TEST'
  print '  I4VEC_MAX returns the maximum entry in an I4VEC.'

  n = 10
  a = 1
  b = 30
  seed = 123456789
  x, seed = i4vec_uniform_ab ( n, a, b, seed )

  i4vec_print ( n, x, '  The vector:' )
  
  x_max = i4vec_max ( n, x )
 
  print ''
  print '  Maximum entry = %d' % ( x_max )
#
#  Terminate.
#
  print ''
  print 'I4VEC_MAX_TEST'
  print '  Normal end of execution.'

  return
コード例 #18
0
def i4vec_min_test():

    #*****************************************************************************80
    #
    ## I4VEC_MIN_TEST tests I4VEC_MIN.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    08 November 2014
    #
    #  Author:
    #
    #    John Burkardt
    #
    from i4vec_print import i4vec_print
    from i4vec_uniform_ab import i4vec_uniform_ab

    print ''
    print 'I4VEC_MIN_TEST'
    print '  I4VEC_MIN returns the minimum entry in an I4VEC.'

    n = 10
    a = 1
    b = 30
    seed = 123456789
    x, seed = i4vec_uniform_ab(n, a, b, seed)

    i4vec_print(n, x, '  The vector:')

    x_min = i4vec_min(n, x)

    print ''
    print '  Minimum entry = %d' % (x_min)
    #
    #  Terminate.
    #
    print ''
    print 'I4VEC_MIN_TEST'
    print '  Normal end of execution.'

    return
コード例 #19
0
def i4vec_product_test():

    #*****************************************************************************80
    #
    ## I4VEC_PRODUCT_TEST tests I4VEC_PRODUCT.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    25 May 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    from i4vec_print import i4vec_print
    from i4vec_uniform_ab import i4vec_uniform_ab

    print ''
    print 'I4VEC_PRODUCT_TEST'
    print '  I4VEC_PRODUCT computes the product of the entries in an I4VEC.'

    n = 10
    i4_lo = -5
    i4_hi = +5
    seed = 123456789

    a, seed = i4vec_uniform_ab(n, i4_lo, i4_hi, seed)

    i4vec_print(n, a, '  Input vector:')

    value = i4vec_product(n, a)
    print ''
    print '  Product of entries = %d' % (value)
    #
    #  Terminate.
    #
    print ''
    print 'I4VEC_PRODUCT_TEST:'
    print '  Normal end of execution.'

    return
コード例 #20
0
def i4vec_product_test ( ):

#*****************************************************************************80
#
## I4VEC_PRODUCT_TEST tests I4VEC_PRODUCT.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    25 May 2015
#
#  Author:
#
#    John Burkardt
#
  from i4vec_print import i4vec_print
  from i4vec_uniform_ab import i4vec_uniform_ab

  print ''
  print 'I4VEC_PRODUCT_TEST'
  print '  I4VEC_PRODUCT computes the product of the entries in an I4VEC.'

  n = 10
  i4_lo = - 5
  i4_hi = + 5
  seed = 123456789

  a, seed = i4vec_uniform_ab ( n, i4_lo, i4_hi, seed )

  i4vec_print ( n, a, '  Input vector:' )

  value = i4vec_product ( n, a )
  print ''
  print '  Product of entries = %d' % ( value )
#
#  Terminate.
#
  print ''
  print 'I4VEC_PRODUCT_TEST:'
  print '  Normal end of execution.'

  return
コード例 #21
0
def i4vec_permute_uniform_test ( ):

#*****************************************************************************80
#
## I4VEC_PERMUTE_UNIFORM_TEST tests I4VEC_PERMUTE_UNIFORM.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    23 May 2015
#
#  Author:
#
#    John Burkardt
#
  import numpy as np
  from i4vec_print import i4vec_print

  n = 12
  seed = 123456789

  print ''
  print 'I4VEC_PERMUTE_UNIFORM_TEST'
  print '  I4VEC_PERMUTE_UNIFORM randomly reorders an I4VEC.'

  a = np.zeros ( n )
  for i in range ( 0, n ):
    a[i] = 101 + i

  i4vec_print ( n, a, '  A, before rearrangement:' )

  a, seed = i4vec_permute_uniform ( n, a, seed )

  i4vec_print ( n, a, '  A, after rearrangement:' )
#
#  Terminate.
#
  print ''
  print 'I4VEC_PERMUTE_UNIFORM_TEST:'
  print '  Normal end of execution.'

  return
コード例 #22
0
def chinese_check_test():

    #*****************************************************************************80
    #
    ## CHINESE_CHECK_TEST tests CHINESE_CHECK.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    25 May 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    import numpy as np
    from i4vec_print import i4vec_print

    n = 4
    m1 = np.array([1, 3, 8, 25])
    m2 = np.array([1, 3, -8, 25])
    m3 = np.array([1, 3, 1, 25])
    m4 = np.array([1, 3, 8, 24])

    print ''
    print 'CHINESE_CHECK_TEST'
    print '  CHINESE_CHECK checks a set of moduluses for use with'
    print '  the Chinese Remainder representation.'

    i4vec_print(n, m1, '  Modulus set #1:')
    ierror = chinese_check(n, m1)
    print '  IERROR = %d' % (ierror)

    i4vec_print(n, m2, '  Modulus set #2:')
    ierror = chinese_check(n, m2)
    print '  IERROR = %d' % (ierror)

    i4vec_print(n, m3, '  Modulus set #3:')
    ierror = chinese_check(n, m3)
    print '  IERROR = %d' % (ierror)

    i4vec_print(n, m4, '  Modulus set #4:')
    ierror = chinese_check(n, m4)
    print '  IERROR = %d' % (ierror)
    #
    #  Terminate.
    #
    print ''
    print 'CHINESE_CHECK_TEST'
    print '  Normal end of execution.'

    return
コード例 #23
0
def chinese_check_test ( ):

#*****************************************************************************80
#
## CHINESE_CHECK_TEST tests CHINESE_CHECK.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    25 May 2015
#
#  Author:
#
#    John Burkardt
#
  import numpy as np
  from i4vec_print import i4vec_print

  n = 4
  m1 = np.array ( [ 1, 3,  8, 25 ] )
  m2 = np.array ( [ 1, 3, -8, 25 ] )
  m3 = np.array ( [ 1, 3,  1, 25 ] )
  m4 = np.array ( [ 1, 3,  8, 24 ] )

  print ''
  print 'CHINESE_CHECK_TEST'
  print '  CHINESE_CHECK checks a set of moduluses for use with'
  print '  the Chinese Remainder representation.'

  i4vec_print ( n, m1, '  Modulus set #1:' )
  ierror = chinese_check ( n, m1 )
  print '  IERROR = %d' % ( ierror )

  i4vec_print ( n, m2, '  Modulus set #2:' )
  ierror = chinese_check ( n, m2 )
  print '  IERROR = %d' % ( ierror )

  i4vec_print ( n, m3, '  Modulus set #3:' )
  ierror = chinese_check ( n, m3 )
  print '  IERROR = %d' % ( ierror )

  i4vec_print ( n, m4, '  Modulus set #4:' )
  ierror = chinese_check ( n, m4 )
  print '  IERROR = %d' % ( ierror )
#
#  Terminate.
#
  print ''
  print 'CHINESE_CHECK_TEST'
  print '  Normal end of execution.'

  return
コード例 #24
0
def i4vec_amax_test ( ):

#*****************************************************************************80
#
## I4VEC_AMAX_TEST tests I4VEC_AMAX.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    29 September 2014
#
#  Author:
#
#    John Burkardt
#
  from i4vec_print import i4vec_print
  from i4vec_uniform_ab import i4vec_uniform_ab

  print ''
  print 'I4VEC_AMAX_TEST'
  print '  I4VEC_AMAX computes the largest of the magnitudes of the'
  print '  entries of an I4VEC.'

  n = 10
  lo = - 10
  hi = 5
  seed = 123456789

  a, seed = i4vec_uniform_ab ( n, lo, hi, seed )
  i4vec_print ( n, a, '  Vector A:' )
  a_amax = i4vec_amax ( n, a )
  print ''
  print '  Largest magnitude of entries of A = %d' % ( a_amax )
#
#  Terminate.
#
  print ''
  print 'I4VEC_AMAX_TEST'
  print '  Normal end of execution.'

  return
コード例 #25
0
ファイル: i4vec_amin.py プロジェクト: wangwt9907/jburkardt-py
def i4vec_amin_test ( ):

#*****************************************************************************80
#
## I4VEC_AMIN_TEST tests I4VEC_AMIN.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    29 September 2014
#
#  Author:
#
#    John Burkardt
#
  from i4vec_print import i4vec_print
  from i4vec_uniform_ab import i4vec_uniform_ab

  print ''
  print 'I4VEC_AMIN_TEST'
  print '  I4VEC_AMIN computes the smallest of the magnitudes of the'
  print '  entries of an I4VEC.'

  n = 10
  lo = - 10
  hi = 5
  seed = 123456789

  a, seed = i4vec_uniform_ab ( n, lo, hi, seed )
  i4vec_print ( n, a, '  Vector A:' )
  a_amin = i4vec_amin ( n, a )
  print ''
  print '  Smallest magnitude of entries of A = %d' % ( a_amin )
#
#  Terminate.
#
  print ''
  print 'I4VEC_AMIN_TEST'
  print '  Normal end of execution.'

  return
コード例 #26
0
def i4vec_sum_test ( ):

#*****************************************************************************80
#
## I4VEC_SUM_TEST tests I4VEC_SUM.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    27 October 2014
#
#  Author:
#
#    John Burkardt
#
  from i4vec_print import i4vec_print
  from i4vec_uniform_ab import i4vec_uniform_ab

  print ''
  print 'I4VEC_SUM_TEST'
  print '  I4VEC_SUM sums the entries of an I4VEC.'

  n = 5
  lo = 0
  hi = 10
  seed = 123456789
  a, seed = i4vec_uniform_ab ( n, lo, hi, seed )
  i4vec_print ( n, a, '  The vector:' )

  s = i4vec_sum ( n, a )
  print ''
  print '  The vector entries sum to %d' % ( s )
#
#  Terminate.
#
  print ''
  print 'I4VEC_SUM_TEST:'
  print '  Normal end of execution.'

  return
コード例 #27
0
def i4vec_increment_test ( ):

#*****************************************************************************80
#
## I4VEC_INCREMENT_TEST tests I4VEC_INCREMENT.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    09 January 2015
#
#  Author:
#
#    John Burkardt
#
  from i4vec_print import i4vec_print
  from i4vec_uniform_ab import i4vec_uniform_ab

  n = 4

  print ''
  print 'I4VEC_INCREMENT_TEST'
  print '  I4VEC_INCREMENT increments an I4VEC.'

  v_lo = -5
  v_hi = 10
  seed = 123456789
  v, seed = i4vec_uniform_ab ( n, v_lo, v_hi, seed )
  i4vec_print ( n, v, '  The I4VEC:' )
  v = i4vec_increment ( n, v )
  i4vec_print ( n, v, '  The I4VEC after incrementing:' )
#
#  Terminate.
#
  print ''
  print 'I4VEC_INCREMENT_TEST:'
  print '  Normal end of execution.'

  return
コード例 #28
0
def i4vec_copy_test ( ):

#*****************************************************************************80
#
## I4VEC_COPY_TEST tests I4VEC_COPY.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    28 October 2014
#
#  Author:
#
#    John Burkardt
#
  from i4vec_print import i4vec_print
  import numpy as np

  n1 = 5;

  a1 = np.array ( [ 91, 31, 71, 51, 31 ], dtype = np.int32 )
 
  print ''
  print 'I4VEC_COPY_TEST'
  print '  I4VEC_COPY copies an I4VEC.'

  i4vec_print ( n1, a1, '  Array 1:' );
  a2 = i4vec_copy ( n1, a1 );
  i4vec_print ( n1, a2, '  Array 2:' );
#
#  Terminate.
#
  print ''
  print 'I4VEC_COPY_TEST'
  print '  Normal end of execution.'

  return
コード例 #29
0
ファイル: padovan.py プロジェクト: wangwt9907/jburkardt-py
def padovan_test():

    #*****************************************************************************80
    #
    ## PADOVAN_TEST tests PADOVAN.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    26 May 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    from i4vec_print import i4vec_print

    n = 10

    print ''
    print 'PADOVAN_TEST'
    print '  PADOVAN computes the Padovan numbers.'

    p = padovan(n)

    i4vec_print(n, p, '  Initial Padovan sequence:')
    #
    #  Terminate.
    #
    print ''
    print 'PADOVAN_TEST:'
    print '  Normal end of execution.'

    return
コード例 #30
0
ファイル: perrin.py プロジェクト: wangwt9907/jburkardt-py
def perrin_test():

    #*****************************************************************************80
    #
    ## PERRIN_TEST tests PERRIN.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    07 May 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    from i4vec_print import i4vec_print

    n = 20

    print ''
    print 'PERRIN_TEST'
    print '  PERRIN computes the Perrin numbers.'

    p = perrin(n)

    i4vec_print(n, p, '  The Perrin sequence:')
    #
    #  Terminate.
    #
    print ''
    print 'PERRIN_TEST:'
    print '  Normal end of execution.'

    return
コード例 #31
0
def i4_to_chinese_test ( ):

#*****************************************************************************80
#
## I4_TO_CHINESE_TEST tests I4_TO_CHINESE.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    25 May 2015
#
#  Author:
#
#    John Burkardt
#
  import numpy as np
  from chinese_to_i4 import chinese_to_i4
  from i4vec_print import i4vec_print

  n = 4
  m = np.array ( [ 3, 4, 5, 7 ] )

  print ''
  print 'I4_TO_CHINESE_TEST'
  print '  I4_TO_CHINESE computes the Chinese Remainder'
  print '  representation of an integer.'

  i4vec_print ( n, m, '  The moduli:' )

  j = 37

  print ''
  print '  The number being analyzed is %d' % ( j )

  r = i4_to_chinese ( j, n, m )

  i4vec_print ( n, r, '  The remainders:' )

  j2 = chinese_to_i4 ( n, m, r )

  print ''
  print '  The reconstructed number is %d' % ( j2 )

  r = i4_to_chinese ( j2, n, m )

  i4vec_print ( n, r, '  The remainders of the reconstructed number are:' )
#
#  Terminate.
#
  print ''
  print 'I4_TO_CHINESE_TEST:'
  print '  Normal end of execution.'

  return
コード例 #32
0
ファイル: perrin.py プロジェクト: johannesgerer/jburkardt-py
def perrin_test ( ):

#*****************************************************************************80
#
## PERRIN_TEST tests PERRIN.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    07 May 2015
#
#  Author:
#
#    John Burkardt
#
  from i4vec_print import i4vec_print

  n = 20

  print ''
  print 'PERRIN_TEST'
  print '  PERRIN computes the Perrin numbers.'

  p = perrin ( n )

  i4vec_print ( n, p, '  The Perrin sequence:' )
#
#  Terminate.
#
  print ''
  print 'PERRIN_TEST:'
  print '  Normal end of execution.'

  return
コード例 #33
0
ファイル: padovan.py プロジェクト: johannesgerer/jburkardt-py
def padovan_test ( ):

#*****************************************************************************80
#
## PADOVAN_TEST tests PADOVAN.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    26 May 2015
#
#  Author:
#
#    John Burkardt
#
  from i4vec_print import i4vec_print

  n = 10

  print ''
  print 'PADOVAN_TEST'
  print '  PADOVAN computes the Padovan numbers.'

  p = padovan ( n );

  i4vec_print ( n, p, '  Initial Padovan sequence:' )
#
#  Terminate.
#
  print ''
  print 'PADOVAN_TEST:'
  print '  Normal end of execution.'

  return
コード例 #34
0
def i4vec_permute_test ( ):

#*****************************************************************************80
#
## I4VEC_PERMUTE_TEST tests I4VEC_PERMUTE.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    25 October 2014
#
#  Author:
#
#    John Burkardt
#
  from i4vec_print import i4vec_print
  from i4vec_uniform_ab import i4vec_uniform_ab
  from perm0_uniform import perm0_uniform

  n = 12

  print ''
  print 'I4VEC_PERMUTE_TEST'
  print '  I4VEC_PERMUTE reorders an I4VEC'
  print '  according to a given permutation.'

  b = 0
  c = n
  seed = 123456789
  a, seed = i4vec_uniform_ab ( n, b, c, seed )

  i4vec_print ( n, a, '  A[*], before rearrangement:' )

  p, seed = perm0_uniform ( n, seed )

  i4vec_print ( n, p, '  Permutation vector P[*]:' )

  a = i4vec_permute ( n, p, a )

  i4vec_print ( n, a, '  A[P[*]]:' )
#
#  Terminate.
#
  print ''
  print 'I4VEC_PERMUTE_TEST:'
  print '  Normal end of execution.'

  return
コード例 #35
0
def i4vec_permute_test():

    #*****************************************************************************80
    #
    ## I4VEC_PERMUTE_TEST tests I4VEC_PERMUTE.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    25 October 2014
    #
    #  Author:
    #
    #    John Burkardt
    #
    from i4vec_print import i4vec_print
    from i4vec_uniform_ab import i4vec_uniform_ab
    from perm0_uniform import perm0_uniform

    n = 12

    print ''
    print 'I4VEC_PERMUTE_TEST'
    print '  I4VEC_PERMUTE reorders an I4VEC'
    print '  according to a given permutation.'

    b = 0
    c = n
    seed = 123456789
    a, seed = i4vec_uniform_ab(n, b, c, seed)

    i4vec_print(n, a, '  A[*], before rearrangement:')

    p, seed = perm0_uniform(n, seed)

    i4vec_print(n, p, '  Permutation vector P[*]:')

    a = i4vec_permute(n, p, a)

    i4vec_print(n, a, '  A[P[*]]:')
    #
    #  Terminate.
    #
    print ''
    print 'I4VEC_PERMUTE_TEST:'
    print '  Normal end of execution.'

    return
コード例 #36
0
def i4vec_concatenate_test():

    #*****************************************************************************80
    #
    ## I4VEC_CONCATENATE_TEST tests I4VEC_CONCATENATE.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    24 October 2014
    #
    #  Author:
    #
    #    John Burkardt
    #
    from i4vec_print import i4vec_print
    import numpy as np

    n1 = 5
    n2 = 3
    n3 = n1 + n2

    a1 = np.array([91, 31, 71, 51, 31])
    a2 = np.array([42, 22, 12])

    print ''
    print 'I4VEC_CONCATENATE_TEST'
    print '  I4VEC_CONCATENATE concatenates two I4VECs'

    i4vec_print(n1, a1, '  Array 1:')
    i4vec_print(n2, a2, '  Array 2:')
    a3 = i4vec_concatenate(n1, a1, n2, a2)
    i4vec_print(n3, a3, '  Array 3 = Array 1 + Array 2:')
    #
    #  Terminate.
    #
    print ''
    print 'I4VEC_CONCATENATE_TEST'
    print '  Normal end of execution.'

    return
コード例 #37
0
def i4vec_concatenate_test ( ):

#*****************************************************************************80
#
## I4VEC_CONCATENATE_TEST tests I4VEC_CONCATENATE.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    24 October 2014
#
#  Author:
#
#    John Burkardt
#
  from i4vec_print import i4vec_print
  import numpy as np

  n1 = 5;
  n2 = 3;
  n3 = n1 + n2;

  a1 = np.array ( [ 91, 31, 71, 51, 31 ] )
  a2 = np.array ( [ 42, 22, 12 ] )

  print ''
  print 'I4VEC_CONCATENATE_TEST'
  print '  I4VEC_CONCATENATE concatenates two I4VECs'

  i4vec_print ( n1, a1, '  Array 1:' );
  i4vec_print ( n2, a2, '  Array 2:' );
  a3 = i4vec_concatenate ( n1, a1, n2, a2 );
  i4vec_print ( n3, a3, '  Array 3 = Array 1 + Array 2:' );

  print ''
  print 'I4VEC_CONCATENATE_TEST'
  print '  Normal end of execution.'

  return
コード例 #38
0
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
コード例 #39
0
def cfrac_to_rat_test():

    # *****************************************************************************80
    #
    #% CFRAC_TO_RAT_TEST tests CFRAC_TO_RAT.
    #
    #  Discussion:
    #
    #    Compute the continued fraction form of 4096/15625.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    28 May 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    from rat_to_cfrac import rat_to_cfrac
    from i4vec_print import i4vec_print

    m = 10

    print ""
    print "CFRAC_TO_RAT_TEST"
    print "  CFRAC_TO_RAT continued fraction => fraction."
    print ""

    top = 4096
    bot = 15625

    print "  Regular fraction is %6d / %6d" % (top, bot)

    n, a = rat_to_cfrac(top, bot)

    i4vec_print(n, a, "  Continued fraction coefficients:")

    p, q = cfrac_to_rat(n, a)

    print ""
    print "  The continued fraction convergents."
    print "  The last row contains the value of the continued"
    print "  fraction, written as a common fraction."
    print ""
    print "  I, P(I), Q(I), P(I)/Q(I)"
    print ""

    for i in range(0, n):
        print "  %3d  %6d  %6d  %14f" % (i, p[i], q[i], p[i] / q[i])
    #
    #  Terminate.
    #
    print ""
    print "CFRAC_TO_RAT_TEST"
    print "  Normal end of execution."

    return
コード例 #40
0
def sort_safe_rc_i4vec_test ( ):

#*****************************************************************************80
#
## SORT_SAFE_RC_I4VEC_TEST tests SORT_SAFE_RC on an integer vector.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license. 
#
#  Modified:
#
#    11 March 2015
#
#  Author:
#
#    John Burkardt
#
  from i4vec_print import i4vec_print
  from i4vec_uniform_ab import i4vec_uniform_ab

  n = 20

  print ''
  print 'SORT_SAFE_RC_I4VEC_TEST'
  print '  SORT_SAFE_RC sorts objects externally.'
  print '  This function does not use persistent memory.'
#
#  Generate some data to sort.
#
  i4_lo = 1
  i4_hi = n
  seed = 123456789

  a, seed = i4vec_uniform_ab ( n, i4_lo, i4_hi, seed )
 
  i4vec_print ( n, a, '  Unsorted array:' )
#
#  Sort the data.
#
  indx = 0
  isgn = 0
  i_save = 0
  j_save = 0
  k_save = 0
  l_save = 0
  n_save = 0

  while ( True ):

    indx, i, j, i_save, j_save, k_save, l_save, n_save = \
      sort_safe_rc ( n, indx, isgn, i_save, j_save, k_save, l_save, n_save )
 
    if ( indx < 0 ):
      isgn = 1
      if ( a[i-1] <= a[j-1] ):
        isgn = -1
    elif ( 0 < indx ):
      k      = a[i-1]
      a[i-1] = a[j-1]
      a[j-1] = k
    else:
      break
#
#  Display the sorted data.
#
  i4vec_print ( n, a, '  Sorted array:' )

  print ''
  print 'SORT_SAFE_RC_TEST:'
  print '  Normal end of execution.'

  return
コード例 #41
0
def bellman_ford_test():

    #*****************************************************************************80
    #
    ## BELLMAN_FORD_TEST tests BELLMAN_FORD.
    #
    #  Discussion:
    #
    #    The correct distances are { 0, -6, -2, 3, 0, 0 }.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    13 November 2014
    #
    #  Author:
    #
    #    John Burkardt
    #
    from i4mat_transpose_print import i4mat_transpose_print
    from i4vec_print import i4vec_print
    from r8vec_print import r8vec_print
    import numpy as np

    e_num = 10
    v_num = 6

    e = np.array ( ( \
      ( 1, 4, 1, 2, 4, 2, 5, 3, 5, 3 ), \
      ( 0, 1, 2, 4, 0, 5, 0, 2, 3, 0 ) ) )
    e_weight = np.array ( ( \
      -3.0,  6.0, -4.0, -1.0,  4.0, -2.0,  2.0, 8.0, -3.0,  3.0 ) )

    source = 0

    print ''
    print 'BELLMAN_FORD_TEST'
    print '  Bellman-Ford shortest path algorithm.'

    print ''
    print '  Number of vertices = %d' % (v_num)
    print '  Number of edges = %d' % (e_num)
    print '  The reference vertex is %d' % (source)

    i4mat_transpose_print(2, e_num, e, '  The edge array:')
    r8vec_print(e_num, e_weight, '  The edge weights:')

    [v_weight, predecessor] = bellman_ford(v_num, e_num, source, e, e_weight)

    r8vec_print(v_num, v_weight, '  The shortest distances:')

    i4vec_print ( v_num, predecessor, \
      '  The vertex predecessor parents for the shortest paths:' )

    print ''
    print 'BELLMAN_FORD_TEST_TEST:'
    print '  Normal end of execution.'

    return
コード例 #42
0
def bellman_ford_test ( ):

#*****************************************************************************80
#
## BELLMAN_FORD_TEST tests BELLMAN_FORD.
#
#  Discussion:
#
#    The correct distances are { 0, -6, -2, 3, 0, 0 }.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    13 November 2014
#
#  Author:
#
#    John Burkardt
#
  from i4mat_transpose_print import i4mat_transpose_print
  from i4vec_print import i4vec_print
  from r8vec_print import r8vec_print
  import numpy as np

  e_num = 10
  v_num = 6

  e = np.array ( ( \
    ( 1, 4, 1, 2, 4, 2, 5, 3, 5, 3 ), \
    ( 0, 1, 2, 4, 0, 5, 0, 2, 3, 0 ) ) )
  e_weight = np.array ( ( \
    -3.0,  6.0, -4.0, -1.0,  4.0, -2.0,  2.0, 8.0, -3.0,  3.0 ) )
 
  source = 0

  print ''
  print 'BELLMAN_FORD_TEST'
  print '  Bellman-Ford shortest path algorithm.'

  print ''
  print '  Number of vertices = %d' % ( v_num )
  print '  Number of edges = %d' % ( e_num )
  print '  The reference vertex is %d' % ( source )

  i4mat_transpose_print ( 2, e_num, e, '  The edge array:' )
  r8vec_print ( e_num, e_weight, '  The edge weights:' )

  [ v_weight, predecessor ] = bellman_ford ( v_num, e_num, source, e, e_weight )

  r8vec_print ( v_num, v_weight, '  The shortest distances:' )

  i4vec_print ( v_num, predecessor, \
    '  The vertex predecessor parents for the shortest paths:' )

  print ''
  print 'BELLMAN_FORD_TEST_TEST:'
  print '  Normal end of execution.'

  return
def sort_safe_rc_i4vec_test():

    #*****************************************************************************80
    #
    ## SORT_SAFE_RC_I4VEC_TEST tests SORT_SAFE_RC on an integer vector.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    11 March 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    from i4vec_print import i4vec_print
    from i4vec_uniform_ab import i4vec_uniform_ab

    n = 20

    print ''
    print 'SORT_SAFE_RC_I4VEC_TEST'
    print '  SORT_SAFE_RC sorts objects externally.'
    print '  This function does not use persistent memory.'
    #
    #  Generate some data to sort.
    #
    i4_lo = 1
    i4_hi = n
    seed = 123456789

    a, seed = i4vec_uniform_ab(n, i4_lo, i4_hi, seed)

    i4vec_print(n, a, '  Unsorted array:')
    #
    #  Sort the data.
    #
    indx = 0
    isgn = 0
    i_save = 0
    j_save = 0
    k_save = 0
    l_save = 0
    n_save = 0

    while (True):

        indx, i, j, i_save, j_save, k_save, l_save, n_save = \
          sort_safe_rc ( n, indx, isgn, i_save, j_save, k_save, l_save, n_save )

        if (indx < 0):
            isgn = 1
            if (a[i - 1] <= a[j - 1]):
                isgn = -1
        elif (0 < indx):
            k = a[i - 1]
            a[i - 1] = a[j - 1]
            a[j - 1] = k
        else:
            break


#
#  Display the sorted data.
#
    i4vec_print(n, a, '  Sorted array:')

    print ''
    print 'SORT_SAFE_RC_TEST:'
    print '  Normal end of execution.'

    return
コード例 #44
0
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
コード例 #45
0
def cfrac_to_rat_test ( ):

#*****************************************************************************80
#
#% CFRAC_TO_RAT_TEST tests CFRAC_TO_RAT.
#
#  Discussion:
#
#    Compute the continued fraction form of 4096/15625.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    28 May 2015
#
#  Author:
#
#    John Burkardt
#
  from rat_to_cfrac import rat_to_cfrac
  from i4vec_print import i4vec_print

  m = 10

  print ''
  print 'CFRAC_TO_RAT_TEST'
  print '  CFRAC_TO_RAT continued fraction => fraction.'
  print ''

  top = 4096
  bot = 15625

  print '  Regular fraction is %6d / %6d' % ( top, bot )
 
  n, a = rat_to_cfrac ( top, bot )
 
  i4vec_print ( n, a, '  Continued fraction coefficients:' )

  p, q = cfrac_to_rat ( n, a )
 
  print ''
  print '  The continued fraction convergents.'
  print '  The last row contains the value of the continued'
  print '  fraction, written as a common fraction.'
  print ''
  print '  I, P(I), Q(I), P(I)/Q(I)'
  print ''

  for i in range ( 0, n ):
    print '  %3d  %6d  %6d  %14f' % ( i, p[i], q[i], p[i] / q[i] )
#
#  Terminate.
#
  print ''
  print 'CFRAC_TO_RAT_TEST'
  print '  Normal end of execution.'

  return
コード例 #46
0
def rat_to_cfrac_test ( ):

#*****************************************************************************80
#
## RAT_TO_CFRAC_TEST tests RAT_TO_CFRAC.
#
#  Discussion:
#
#    Compute the continued fraction form of 4096/15625.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    10 April 2009
#
#  Author:
#
#    John Burkardt
#
  from cfrac_to_rat import cfrac_to_rat
  from i4vec_print import i4vec_print

  m = 10

  print ''
  print 'RAT_TO_CFRAC_TEST'
  print '  RAT_TO_CFRAC fraction => continued fraction,'
  print ''

  top = 4096
  bot = 15625

  print '  Regular fraction is %6d / %6d' % ( top, bot )
 
  n, a = rat_to_cfrac ( top, bot )
 
  i4vec_print ( n, a, '  Continued fraction coefficients:' )

  p, q = cfrac_to_rat ( n, a )
 
  print ''
  print '  The continued fraction convergents.'
  print '  The last row contains the value of the continued'
  print '  fraction, written as a common fraction.'
  print ''
  print '  I, P(I), Q(I), P(I)/Q(I)'
  print ''

  for i in range ( 0, n ):
    print '  %3d  %6d  %6d  %14f' % ( i, p[i], q[i], p[i] / q[i] )
#
#  Terminate.
#
  print ''
  print 'RAT_TO_CFRAC_TEST'
  print '  Normal end of execution.'

  return