Пример #1
0
def lpp_to_polynomial_test():

    #*****************************************************************************80
    #
    ## LPP_TO_POLYNOMIAL_TEST tests LPP_TO_POLYNOMIAL.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    31 October 2014
    #
    #  Author:
    #
    #    John Burkardt
    #
    from comp_unrank_grlex import comp_unrank_grlex
    from polynomial_print import polynomial_print
    import numpy as np

    m = 2

    print ''
    print 'LPP_TO_POLYNOMIAL_TEST:'
    print '  LPP_TO_POLYNOMIAL is given a Legendre product polynomial'
    print '  and determines its polynomial representation.'

    print ''
    print '  Using spatial dimension M = %d' % (m)

    for rank in range(1, 12):
        l = comp_unrank_grlex(m, rank)

        o_max = 1
        for i in range(0, m):
            o_max = o_max * (l[i] + 2) // 2

        c = np.zeros(o_max, dtype=np.float64)
        e = np.zeros(o_max, dtype=np.int32)

        o, c, e = lpp_to_polynomial(m, l, o_max)

        label = '  LPP #' + repr ( rank ) + ' = L(' + repr ( l[0] ) \
          + ',X)*L(' + repr ( l[1] ) + ',Y) = '

        print ''
        polynomial_print(m, o, c, e, label)

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

    return
def lpp_to_polynomial_test ( ):

#*****************************************************************************80
#
## LPP_TO_POLYNOMIAL_TEST tests LPP_TO_POLYNOMIAL.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    31 October 2014
#
#  Author:
#
#    John Burkardt
#
  from comp_unrank_grlex import comp_unrank_grlex
  from polynomial_print import polynomial_print
  import numpy as np

  m = 2

  print ''
  print 'LPP_TO_POLYNOMIAL_TEST:'
  print '  LPP_TO_POLYNOMIAL is given a Legendre product polynomial'
  print '  and determines its polynomial representation.'

  print ''
  print '  Using spatial dimension M = %d' % ( m )

  for rank in range ( 1, 12 ):
    l = comp_unrank_grlex ( m, rank )

    o_max = 1
    for i in range ( 0, m ):
      o_max = o_max * ( l[i] + 2 ) // 2

    c = np.zeros ( o_max, dtype = np.float64 )
    e = np.zeros ( o_max, dtype = np.int32 )

    o, c, e = lpp_to_polynomial ( m, l, o_max )

    label = '  LPP #' + repr ( rank ) + ' = L(' + repr ( l[0] ) \
      + ',X)*L(' + repr ( l[1] ) + ',Y) = '

    print ''
    polynomial_print ( m, o, c, e, label )

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

  return
def comp_random_grlex ( kc, rank1, rank2, seed ):

#*****************************************************************************80
#
## COMP_RANDOM_GRLEX: random composition with degree less than or equal to NC.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    09 September 2014
#
#  Author:
#
#    John Burkardt
#
#  Parameters:
#
#    Input, int KC, the number of parts in the composition.
#
#    Input, int RANK1, RANK2, the minimum and maximum ranks.
#    1 <= RANK1 <= RANK2.
#
#    Input, int SEED, the random number seed.
#
#    Output, int X[KC], the random composition.
#
#    Output, int RANK, the rank of the composition.
#
#    Output, int SEED, the random number seed.
#
  from comp_unrank_grlex import comp_unrank_grlex
  from i4_uniform_ab import i4_uniform_ab
  from sys import exit
#
#  Ensure that 1 <= KC.
#
  if ( kc < 1 ):
    print ''
    print 'COMP_RANDOM_GRLEX - Fatal error!'
    print '  KC < 1'
    exit ( 'COMP_RANDOM_GRLEX - Fatal error!' );
#
#  Ensure that 1 <= RANK1.
#
  if ( rank1 < 1 ):
    print ''
    print 'COMP_RANDOM_GRLEX - Fatal error!'
    print '  RANK1 < 1'
    exit ( 'COMP_RANDOM_GRLEX - Fatal error!' );
#
#  Ensure that RANK1 <= RANK2.
#
  if ( rank2 < rank1 ):
    print ''
    print 'COMP_RANDOM_GRLEX - Fatal error!'
    print '  RANK2 < RANK1'
    exit ( 'COMP_RANDOM_GRLEX - Fatal error!' )
#
#  Choose RANK between RANK1 and RANK2.
#
  rank, seed = i4_uniform_ab ( rank1, rank2, seed )
#
#  Recover the composition of given RANK.
#
  xc = comp_unrank_grlex ( kc, rank )

  return xc, rank, seed
Пример #4
0
def lpp_value_test():

    # *****************************************************************************80
    #
    ## LPP_VALUE_TEST tests LPP_VALUE.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    31 October 2014
    #
    #  Author:
    #
    #    John Burkardt
    #
    from comp_unrank_grlex import comp_unrank_grlex
    from lpp_to_polynomial import lpp_to_polynomial
    from polynomial_value import polynomial_value
    from r8mat_uniform_ab import r8mat_uniform_ab

    print ""
    print "LPP_VALUE_TEST:"
    print "  LPP_VALUE evaluates a Legendre product polynomial."

    m = 3
    n = 1
    xlo = -1.0
    xhi = +1.0
    seed = 123456789
    x, seed = r8mat_uniform_ab(m, n, xlo, xhi, seed)

    print ""
    print "  Evaluate at X = ",
    for j in range(0, n):
        for i in range(0, m):
            print "%g  " % (x[i][j]),
    print ""
    print ""
    print "  Rank  I1  I2  I3:  L(I1,X1)*L(I2,X2)*L(I3,X3)    P(X1,X2,X3)"
    print ""

    for rank in range(1, 21):
        l = comp_unrank_grlex(m, rank)
        #
        #  Evaluate the LPP directly.
        #
        v1 = lpp_value(m, n, l, x)
        #
        #  Convert the LPP to a polynomial.
        #
        o_max = 1
        for i in range(0, m):
            o_max = o_max * (l[i] + 2) // 2

        o, c, e = lpp_to_polynomial(m, l, o_max)
        #
        #  Evaluate the polynomial.
        #
        v2 = polynomial_value(m, o, c, e, n, x)
        #
        #  Compare results.
        #
        print "  %4d  %2d  %2d  %2d  %14.6g  %14.6g" % (rank, l[0], l[1], l[2], v1[0], v2[0])

    print ""
    print "LPP_VALUE_TEST:"
    print "  Normal end of execution."

    return
Пример #5
0
def comp_random_grlex(kc, rank1, rank2, seed):

    #*****************************************************************************80
    #
    ## COMP_RANDOM_GRLEX: random composition with degree less than or equal to NC.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    09 September 2014
    #
    #  Author:
    #
    #    John Burkardt
    #
    #  Parameters:
    #
    #    Input, int KC, the number of parts in the composition.
    #
    #    Input, int RANK1, RANK2, the minimum and maximum ranks.
    #    1 <= RANK1 <= RANK2.
    #
    #    Input, int SEED, the random number seed.
    #
    #    Output, int X[KC], the random composition.
    #
    #    Output, int RANK, the rank of the composition.
    #
    #    Output, int SEED, the random number seed.
    #
    from comp_unrank_grlex import comp_unrank_grlex
    from i4_uniform_ab import i4_uniform_ab
    from sys import exit
    #
    #  Ensure that 1 <= KC.
    #
    if (kc < 1):
        print ''
        print 'COMP_RANDOM_GRLEX - Fatal error!'
        print '  KC < 1'
        exit('COMP_RANDOM_GRLEX - Fatal error!')
#
#  Ensure that 1 <= RANK1.
#
    if (rank1 < 1):
        print ''
        print 'COMP_RANDOM_GRLEX - Fatal error!'
        print '  RANK1 < 1'
        exit('COMP_RANDOM_GRLEX - Fatal error!')
#
#  Ensure that RANK1 <= RANK2.
#
    if (rank2 < rank1):
        print ''
        print 'COMP_RANDOM_GRLEX - Fatal error!'
        print '  RANK2 < RANK1'
        exit('COMP_RANDOM_GRLEX - Fatal error!')


#
#  Choose RANK between RANK1 and RANK2.
#
    rank, seed = i4_uniform_ab(rank1, rank2, seed)
    #
    #  Recover the composition of given RANK.
    #
    xc = comp_unrank_grlex(kc, rank)

    return xc, rank, seed
Пример #6
0
def lpp_value_test():

    #*****************************************************************************80
    #
    ## LPP_VALUE_TEST tests LPP_VALUE.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    31 October 2014
    #
    #  Author:
    #
    #    John Burkardt
    #
    from comp_unrank_grlex import comp_unrank_grlex
    from lpp_to_polynomial import lpp_to_polynomial
    from polynomial_value import polynomial_value
    from r8mat_uniform_ab import r8mat_uniform_ab

    print ''
    print 'LPP_VALUE_TEST:'
    print '  LPP_VALUE evaluates a Legendre product polynomial.'

    m = 3
    n = 1
    xlo = -1.0
    xhi = +1.0
    seed = 123456789
    x, seed = r8mat_uniform_ab(m, n, xlo, xhi, seed)

    print ''
    print '  Evaluate at X = ',
    for j in range(0, n):
        for i in range(0, m):
            print '%g  ' % (x[i][j]),
    print ''
    print ''
    print '  Rank  I1  I2  I3:  L(I1,X1)*L(I2,X2)*L(I3,X3)    P(X1,X2,X3)'
    print ''

    for rank in range(1, 21):
        l = comp_unrank_grlex(m, rank)
        #
        #  Evaluate the LPP directly.
        #
        v1 = lpp_value(m, n, l, x)
        #
        #  Convert the LPP to a polynomial.
        #
        o_max = 1
        for i in range(0, m):
            o_max = o_max * (l[i] + 2) // 2

        o, c, e = lpp_to_polynomial(m, l, o_max)
        #
        #  Evaluate the polynomial.
        #
        v2 = polynomial_value(m, o, c, e, n, x)
        #
        #  Compare results.
        #
        print '  %4d  %2d  %2d  %2d  %14.6g  %14.6g' % \
          ( rank, l[0], l[1], l[2], v1[0], v2[0] )

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

    return