Example #1
0
def i4vec_add_test ( ):

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

  print ''
  print 'I4VEC_ADD_TEST'
  print '  I4VEC_ADD adds two I4VECs.'

  n = 10
  seed = 123456789

  lo = - n
  hi = n

  a, seed = i4vec_uniform_ab ( n, lo, hi, seed )
  b, seed = i4vec_uniform_ab ( n, lo, hi, seed )
  c = i4vec_add ( n, a, b )

  print ''
  print '     I     A     B     C'
  print ''
  for i in range ( 0, n ):
    print '%6d%6d%6d%6d' % ( i, a[i], b[i], c[i] )
#
#  Terminate.
#
  print ''
  print 'I4VEC_ADD_TEST'
  print '  Normal end of execution.'

  return
Example #2
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
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
Example #4
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
Example #5
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
Example #6
0
def mono_next_grlex_test():

    #*****************************************************************************80
    #
    ## MONO_NEXT_GRLEX_TEST tests MONO_NEXT_GRLEX.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    24 October 2014
    #
    #  Author:
    #
    #    John Burkardt
    #
    from i4vec_uniform_ab import i4vec_uniform_ab

    m = 4

    print ''
    print 'MONO_NEXT_GRLEX_TEST'
    print '  MONO_NEXT_GRLEX computes the next monomial'
    print '  in M variables in grlex order.'
    print ''
    print '  Let M =  %d' % (m)

    a = 0
    b = 3
    seed = 123456789

    for i in range(0, 10):

        x, seed = i4vec_uniform_ab(m, a, b, seed)
        print ''
        print '  ',
        for k in range(0, m):
            print '%2d' % (x[k]),
        print ''

        for j in range(0, 5):
            x = mono_next_grlex(m, x)
            print '  ',
            for k in range(0, m):
                print '%2d' % (x[k]),
            print ''

    print ''
    print 'MONO_NEXT_GRLEX_TEST'
    print '  Normal end of execution.'

    return
def mono_next_grlex_test ( ):

#*****************************************************************************80
#
## MONO_NEXT_GRLEX_TEST tests MONO_NEXT_GRLEX.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    24 October 2014
#
#  Author:
#
#    John Burkardt
#
  from i4vec_uniform_ab import i4vec_uniform_ab

  m = 4

  print ''
  print 'MONO_NEXT_GRLEX_TEST'
  print '  MONO_NEXT_GRLEX computes the next monomial'
  print '  in M variables in grlex order.'
  print ''
  print '  Let M =  %d' % ( m )

  a = 0
  b = 3
  seed = 123456789

  for i in range ( 0, 10 ):

    x, seed = i4vec_uniform_ab ( m, a, b, seed )
    print ''
    print '  ',
    for k in range ( 0, m ):
      print '%2d' % ( x[k] ),
    print ''

    for j in range ( 0, 5 ):
      x = mono_next_grlex ( m, x )
      print '  ',
      for k in range ( 0, m ):
        print '%2d' %  ( x[k] ),
      print ''

  print ''
  print 'MONO_NEXT_GRLEX_TEST'
  print '  Normal end of execution.'

  return
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
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
Example #10
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
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
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
Example #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
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
def i4vec_sort_bubble_a_test ( ):

#*****************************************************************************80
#
## I4VEC_SORT_BUBBLE_A_TEST tests I4VEC_SORT_BUBBLE_A.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    07 May 2015
#
#  Author:
#
#    John Burkardt
#
  from i4vec_transpose_print import i4vec_transpose_print
  from i4vec_uniform_ab import i4vec_uniform_ab
  
  print ''
  print 'I4VEC_SORT_BUBBLE_A_TEST'
  print '  I4VEC_SORT_BUBBLE_A ascending sorts an I4VEC.'

  n = 20
  i4_lo = 0
  i4_hi = 3 * n
  seed = 123456789

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

  i4vec_transpose_print ( n, a, '  Unsorted:' )

  a = i4vec_sort_bubble_a ( n, a )

  i4vec_transpose_print ( n, a, '  Ascending sorted:' )
#
#  Terminate.
#
  print ''
  print 'I4VEC_SORT_BUBBLE_A_TEST:'
  print '  Normal end of execution.'

  return
Example #16
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
Example #17
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
def i4vec_sort_bubble_a_test():

    #*****************************************************************************80
    #
    ## I4VEC_SORT_BUBBLE_A_TEST tests I4VEC_SORT_BUBBLE_A.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    07 May 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    from i4vec_transpose_print import i4vec_transpose_print
    from i4vec_uniform_ab import i4vec_uniform_ab

    print ''
    print 'I4VEC_SORT_BUBBLE_A_TEST'
    print '  I4VEC_SORT_BUBBLE_A ascending sorts an I4VEC.'

    n = 20
    i4_lo = 0
    i4_hi = 3 * n
    seed = 123456789

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

    i4vec_transpose_print(n, a, '  Unsorted:')

    a = i4vec_sort_bubble_a(n, a)

    i4vec_transpose_print(n, a, '  Ascending sorted:')
    #
    #  Terminate.
    #
    print ''
    print 'I4VEC_SORT_BUBBLE_A_TEST:'
    print '  Normal end of execution.'

    return
Example #19
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
Example #20
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
Example #21
0
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
Example #22
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
Example #23
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
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
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
def monomial_value_test ( ):

#*****************************************************************************80
#
## MONOMIAL_VALUE_TEST tests MONOMIAL_VALUE on sets of data in various dimensions.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    07 April 2015
#
#  Author:
#
#    John Burkardt
#
  from i4vec_transpose_print import i4vec_transpose_print
  from i4vec_uniform_ab import i4vec_uniform_ab
  from monomial_value import monomial_value
  from r8mat_nint import r8mat_nint
  from r8mat_uniform_ab import r8mat_uniform_ab

  print ''
  print 'MONOMIAL_VALUE_TEST'
  print '  Use monomial_value() to evaluate some monomials'
  print '  in dimensions 1 through 3.'

  e_min = -3
  e_max = 6
  n = 5
  seed = 123456789
  x_min = -2.0
  x_max = +10.0

  for m in range ( 1, 4 ):

    print ''
    print '  Spatial dimension M =  %d' % ( m )

    e, seed = i4vec_uniform_ab ( m, e_min, e_max, seed )
    i4vec_transpose_print ( m, e, '  Exponents:' )
    x, seed = r8mat_uniform_ab ( m, n, x_min, x_max, seed )
#
#  To make checking easier, make the X values integers.
#
    x = r8mat_nint ( m, n, x )
    v = monomial_value ( m, n, e, x )

    print ''
    print '   V(X)         ',
    for i in range ( 0, m ):
      print '      X(%d)' % ( i ),
    print ''
    print ''
    for j in range ( 0, n ):
      print '%14.6g  ' % ( v[j] ),
      for i in range ( 0, m ):
        print '%10.4f' % ( x[i,j] ),
      print ''

  print ''
  print 'MONOMIAL_VALUE_TEST'
  print '  Normal end of execution.'

  return
Example #27
0
def monomial_value_test():

    #*****************************************************************************80
    #
    ## MONOMIAL_VALUE_TEST tests MONOMIAL_VALUE on sets of data in various dimensions.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    07 April 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    from i4vec_transpose_print import i4vec_transpose_print
    from i4vec_uniform_ab import i4vec_uniform_ab
    from monomial_value import monomial_value
    from r8mat_nint import r8mat_nint
    from r8mat_uniform_ab import r8mat_uniform_ab

    print ''
    print 'MONOMIAL_VALUE_TEST'
    print '  Use monomial_value() to evaluate some monomials'
    print '  in dimensions 1 through 3.'

    e_min = -3
    e_max = 6
    n = 5
    seed = 123456789
    x_min = -2.0
    x_max = +10.0

    for m in range(1, 4):

        print ''
        print '  Spatial dimension M =  %d' % (m)

        e, seed = i4vec_uniform_ab(m, e_min, e_max, seed)
        i4vec_transpose_print(m, e, '  Exponents:')
        x, seed = r8mat_uniform_ab(m, n, x_min, x_max, seed)
        #
        #  To make checking easier, make the X values integers.
        #
        x = r8mat_nint(m, n, x)
        v = monomial_value(m, n, e, x)

        print ''
        print '   V(X)         ',
        for i in range(0, m):
            print '      X(%d)' % (i),
        print ''
        print ''
        for j in range(0, n):
            print '%14.6g  ' % (v[j]),
            for i in range(0, m):
                print '%10.4f' % (x[i, j]),
            print ''

    print ''
    print 'MONOMIAL_VALUE_TEST'
    print '  Normal end of execution.'

    return