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
Example #3
0
def polynomial_value_test():

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

    m = 3
    o = 6
    c = np.array([7.0, -5.0, 9.0, 11.0, 0.0, -13.0], dtype=np.float64)
    e = np.array([1, 2, 4, 5, 12, 33], dtype=np.int32)
    nx = 2
    x = np.array ( [ 1.0, 2.0, 3.0, \
                    -2.0, 4.0, 1.0 ], dtype = np.float64 )

    print ''
    print 'POLYNOMIAL_VALUE_TEST'
    print '  POLYNOMIAL_VALUE evaluates a polynomial.'

    print ''
    title = '  P(X) = '
    polynomial_print(m, o, c, e, title)

    p = polynomial_value(m, o, c, e, nx, x)

    print ''
    for j in range(0, nx):
        print '  P(%f,%f,%f) = %g' % (x[0 + j * m], x[1 + j * m], x[2 + j * m],
                                      p[j])

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

    return
def polynomial_value_test ( ):

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

  m = 3
  o = 6
  c = np.array ( [ 7.0, - 5.0, 9.0, 11.0, 0.0, - 13.0 ], dtype = np.float64 )
  e = np.array ( [ 1, 2, 4, 5, 12, 33 ], dtype = np.int32 )
  nx = 2
  x = np.array ( [ 1.0, 2.0, 3.0, \
                  -2.0, 4.0, 1.0 ], dtype = np.float64 );

  print ''
  print 'POLYNOMIAL_VALUE_TEST'
  print '  POLYNOMIAL_VALUE evaluates a polynomial.'

  print ''
  title = '  P(X) = '
  polynomial_print ( m, o, c, e, title )

  p = polynomial_value ( m, o, c, e, nx, x )

  print ''
  for j in range ( 0, nx ):
    print '  P(%f,%f,%f) = %g' % ( x[0+j*m], x[1+j*m], x[2+j*m], p[j] )

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

  return
def lp_coefficients_test ( ):

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

  m = 1
  n_max = 10

  print ''
  print 'LP_COEFFICIENTS_TEST'
  print '  LP_COEFFICIENTS: coefficients of Legendre polynomial P(n,x).'
  print ''

  for n in range ( 0, n_max + 1 ):

    o, c, f = lp_coefficients ( n )

    e = np.zeros ( o, dtype = np.int32 )

    for i in range ( 0, o ):
      e[i] = f[i] + 1

    label = '  P(' + repr ( n ) + ',x) = '
    polynomial_print ( m, o, c, e, label )

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

  return
def polynomial_sort_test():

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

    m = 3
    o = 6
    c = np.array([0.0, 9.0, -5.0, -13.0, 7.0, 11.0], dtype=np.float64)
    e = np.array([12, 4, 2, 33, 1, 5], dtype=np.int32)

    print ''
    print 'POLYNOMIAL_SORT_TEST'
    print '  POLYNOMIAL_SORT sorts a polynomial by exponent index.'

    print ''
    title = '  Unsorted polynomial:'
    polynomial_print(m, o, c, e, title)

    c, e = polynomial_sort(o, c, e)

    print ''
    title = '  Sorted polynomial:'
    polynomial_print(m, o, c, e, title)

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

    return
def polynomial_sort_test ( ):

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

  m = 3
  o = 6
  c = np.array ( [ 0.0, 9.0, -5.0, - 13.0, 7.0, 11.0 ], dtype = np.float64 )
  e = np.array ( [ 12, 4, 2, 33, 1, 5 ], dtype = np.int32 )

  print ''
  print 'POLYNOMIAL_SORT_TEST'
  print '  POLYNOMIAL_SORT sorts a polynomial by exponent index.'

  print ''
  title = '  Unsorted polynomial:'
  polynomial_print ( m, o, c, e, title )

  c, e = polynomial_sort ( o, c, e )

  print ''
  title = '  Sorted polynomial:'
  polynomial_print ( m, o, c, e, title )

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

  return
def polynomial_compress_test ( ):

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

  print ''
  print 'POLYNOMIAL_COMPRESS_TEST'
  print '  POLYNOMIAL_COMPRESS compresses a polynomial.'

  m = 3
  o = 10
  c = np.array ( [ 7.0, - 5.0, 5.0, 9.0, 11.0, 3.0, 6.0, 0.0, - 13.0, 1.0E-20 ], \
    dtype = np.float64 )
  e = np.array ( [ 1, 2, 2, 4, 5, 5, 5, 12, 33, 35 ], dtype = np.int32 )

  print ''
  title = '  Uncompressed polynomial ='
  polynomial_print ( m, o, c, e, title )

  o2, c2, e2 = polynomial_compress ( o, c, e )
  print ''
  title = '  Compressed polynomial ='
  polynomial_print ( m, o2, c2, e2, title )

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

  return