Esempio n. 1
0
def r8mat_norm_li_test():

    #*****************************************************************************80
    #
    ## R8MAT_NORM_LI_TEST tests R8MAT_NORM_LI.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    16 February 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    from r8mat_print import r8mat_print
    from r8mat_uniform_ab import r8mat_uniform_ab

    m = 5
    n = 4
    x1 = -5.0
    x2 = +5.0
    seed = 123456789

    a, seed = r8mat_uniform_ab(m, n, x1, x2, seed)

    for j in range(0, n):
        for i in range(0, m):
            a[i, j] = round(a[i, j])

    print ''
    print 'R8MAT_NORM_LI_TEST'
    print '  R8MAT_NORM_LI computes the Loo norm of an R8MAT;'

    t = r8mat_norm_li(m, n, a)

    r8mat_print(m, n, a, '  A:')
    print ''
    print '  Computed Loo norm = %g' % (t)

    print ''
    print 'R8MAT_NORM_LI_TEST'
    print '  Normal end of execution.'

    return
def r8mat_norm_li_test():

    # *****************************************************************************80
    #
    ## R8MAT_NORM_LI_TEST tests R8MAT_NORM_LI.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    16 February 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    from r8mat_print import r8mat_print
    from r8mat_uniform_ab import r8mat_uniform_ab

    m = 5
    n = 4
    x1 = -5.0
    x2 = +5.0
    seed = 123456789

    a, seed = r8mat_uniform_ab(m, n, x1, x2, seed)

    for j in range(0, n):
        for i in range(0, m):
            a[i, j] = round(a[i, j])

    print ""
    print "R8MAT_NORM_LI_TEST"
    print "  R8MAT_NORM_LI computes the Loo norm of an R8MAT;"

    t = r8mat_norm_li(m, n, a)

    r8mat_print(m, n, a, "  A:")
    print ""
    print "  Computed Loo norm = %g" % (t)

    print ""
    print "R8MAT_NORM_LI_TEST"
    print "  Normal end of execution."

    return
Esempio n. 3
0
def r8mat_nint_test():

    # *****************************************************************************80
    #
    ## R8MAT_NINT_TEST tests R8MAT_NINT.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    06 December 2014
    #
    #  Author:
    #
    #    John Burkardt
    #
    from r8mat_print import r8mat_print
    from r8mat_uniform_ab import r8mat_uniform_ab

    m = 5
    n = 4

    print ""
    print "R8MAT_NINT_TEST"
    print "  R8MAT_NINT rounds an R8MAT."

    x1 = -5.0
    x2 = +5.0
    seed = 123456789
    a, seed = r8mat_uniform_ab(m, n, x1, x2, seed)
    r8mat_print(m, n, a, "  Matrix A:")
    a = r8mat_nint(m, n, a)
    r8mat_print(m, n, a, "  Rounded matrix A:")

    print ""
    print "R8MAT_NINT_TEST"
    print "  Normal end of execution."

    return
Esempio n. 4
0
def r8mat_nint_test():

    #*****************************************************************************80
    #
    ## R8MAT_NINT_TEST tests R8MAT_NINT.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    06 December 2014
    #
    #  Author:
    #
    #    John Burkardt
    #
    from r8mat_print import r8mat_print
    from r8mat_uniform_ab import r8mat_uniform_ab

    m = 5
    n = 4

    print ''
    print 'R8MAT_NINT_TEST'
    print '  R8MAT_NINT rounds an R8MAT.'

    x1 = -5.0
    x2 = +5.0
    seed = 123456789
    a, seed = r8mat_uniform_ab(m, n, x1, x2, seed)
    r8mat_print(m, n, a, '  Matrix A:')
    a = r8mat_nint(m, n, a)
    r8mat_print(m, n, a, '  Rounded matrix A:')

    print ''
    print 'R8MAT_NINT_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
Esempio n. 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
def r8vec_house_column_test ( ):

#*****************************************************************************80
#
## R8VEC_HOUSE_COLUMN_TEST tests R8VEC_HOUSE_COLUMN.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    14 February 2015
#
#  Author:
#
#    John Burkardt
#
  import numpy as np
  from r8mat_house_form import r8mat_house_form
  from r8mat_mm import r8mat_mm
  from r8mat_print import r8mat_print
  from r8mat_uniform_ab import r8mat_uniform_ab

  print ''
  print 'R8VEC_HOUSE_COLUMN_TEST'
  print '  R8VEC_HOUSE_COLUMN returns the compact form of'
  print '  a Householder matrix that "packs" a column'
  print '  of a matrix.'
#
#  Get a random matrix.
#
  n = 4
  r8_lo = 0.0
  r8_hi = 5.0
  seed = 123456789;

  a, seed = r8mat_uniform_ab ( n, n, r8_lo, r8_hi, seed )

  r8mat_print ( n, n, a, '  Matrix A:' )

  a_col = np.zeros ( n )

  for k in range ( 0, n - 1 ):

    print ''
    print '  Working on column K = %d' % ( k )

    for i in range ( 0, n ):
      a_col[i] = a[i,k]

    v = r8vec_house_column ( n, a_col, k )

    h = r8mat_house_form ( n, v )

    r8mat_print ( n, n, h, '  Householder matrix H:' )

    ha = r8mat_mm ( n, n, n, h, a )

    r8mat_print ( n, n, ha, '  Product H*A:' )
#
#  If we set A := HA, then we can successively convert A to upper
#  triangular form.
#
    a = ha

  print ''
  print 'R8VEC_HOUSE_COLUMN_TEST'
  print '  Normal end of execution.'

  return
Esempio n. 8
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
Esempio n. 9
0
def r8mat_is_solution_test():

    #*****************************************************************************80
    #
    ## R8MAT_IS_SOLUTION_TEST tests R8MAT_IS_SOLUTION.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    02 March 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    from i4_uniform_ab import i4_uniform_ab
    from r8mat_mm import r8mat_mm
    from r8mat_uniform_ab import r8mat_uniform_ab

    print ''
    print 'R8MAT_IS_SOLUTION_TEST:'
    print '  R8MAT_IS_SOLUTION tests whether X is the solution of'
    print '  A*X=B by computing the Frobenius norm of the residual.'
    #
    #  Get random shapes.
    #
    i4_lo = 1
    i4_hi = 10
    seed = 123456789
    m, seed = i4_uniform_ab(i4_lo, i4_hi, seed)
    n, seed = i4_uniform_ab(i4_lo, i4_hi, seed)
    k, seed = i4_uniform_ab(i4_lo, i4_hi, seed)
    #
    #  Get a random A.
    #
    r8_lo = -5.0
    r8_hi = +5.0
    a, seed = r8mat_uniform_ab(m, n, r8_lo, r8_hi, seed)
    #
    #  Get a random X.
    #
    r8_lo = -5.0
    r8_hi = +5.0
    x, seed = r8mat_uniform_ab(n, k, r8_lo, r8_hi, seed)
    #
    #  Compute B = A * X.
    #
    b = r8mat_mm(m, n, k, a, x)
    #
    #  Compute || A*X-B||
    #
    enorm = r8mat_is_solution(m, n, k, a, x, b)

    print ''
    print '  A is %d by %d' % (m, n)
    print '  X is %d by %d' % (n, k)
    print '  B is %d by %d' % (m, k)
    print '  Frobenius error in A*X-B is %g' % (enorm)

    print ''
    print 'R8MAT_IS_SOLUTION_TEST'
    print '  Normal end of execution.'

    return
def r8mat_is_solution_test ( ):

#*****************************************************************************80
#
## R8MAT_IS_SOLUTION_TEST tests R8MAT_IS_SOLUTION.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    02 March 2015
#
#  Author:
#
#    John Burkardt
#
  from i4_uniform_ab import i4_uniform_ab
  from r8mat_mm import r8mat_mm
  from r8mat_uniform_ab import r8mat_uniform_ab

  print ''
  print 'R8MAT_IS_SOLUTION_TEST:'
  print '  R8MAT_IS_SOLUTION tests whether X is the solution of'
  print '  A*X=B by computing the Frobenius norm of the residual.'
#
#  Get random shapes.
#
  i4_lo = 1
  i4_hi = 10
  seed = 123456789
  m, seed = i4_uniform_ab ( i4_lo, i4_hi, seed )
  n, seed = i4_uniform_ab ( i4_lo, i4_hi, seed )
  k, seed = i4_uniform_ab ( i4_lo, i4_hi, seed )
#
#  Get a random A.
#
  r8_lo = -5.0
  r8_hi = +5.0
  a, seed = r8mat_uniform_ab ( m, n, r8_lo, r8_hi, seed )
#
#  Get a random X.
#
  r8_lo = -5.0
  r8_hi = +5.0
  x, seed = r8mat_uniform_ab ( n, k, r8_lo, r8_hi, seed )
#
#  Compute B = A * X.
#
  b = r8mat_mm ( m, n, k, a, x )
#
#  Compute || A*X-B||
#
  enorm = r8mat_is_solution ( m, n, k, a, x, b )
  
  print ''
  print '  A is %d by %d' % ( m, n )
  print '  X is %d by %d' % ( n, k )
  print '  B is %d by %d' % ( m, k )
  print '  Frobenius error in A*X-B is %g' % ( enorm )

  print ''
  print 'R8MAT_IS_SOLUTION_TEST'
  print '  Normal end of execution.'

  return
Esempio n. 11
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
def r8vec_house_column_test ( ):

#*****************************************************************************80
#
## R8VEC_HOUSE_COLUMN_TEST tests R8VEC_HOUSE_COLUMN.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    14 February 2015
#
#  Author:
#
#    John Burkardt
#
  import numpy as np
  from r8mat_house_form import r8mat_house_form
  from r8mat_mm import r8mat_mm
  from r8mat_print import r8mat_print
  from r8mat_uniform_ab import r8mat_uniform_ab

  print ''
  print 'R8VEC_HOUSE_COLUMN_TEST'
  print '  R8VEC_HOUSE_COLUMN returns the compact form of'
  print '  a Householder matrix that "packs" a column'
  print '  of a matrix.'
#
#  Get a random matrix.
#
  n = 4
  r8_lo = 0.0
  r8_hi = 5.0
  seed = 123456789;

  a, seed = r8mat_uniform_ab ( n, n, r8_lo, r8_hi, seed )

  r8mat_print ( n, n, a, '  Matrix A:' )

  a_col = np.zeros ( n )

  for k in range ( 0, n - 1 ):

    print ''
    print '  Working on column K = %d' % ( k )

    for i in range ( 0, n ):
      a_col[i] = a[i,k]

    v = r8vec_house_column ( n, a_col, k )

    h = r8mat_house_form ( n, v )

    r8mat_print ( n, n, h, '  Householder matrix H:' )

    ha = r8mat_mm ( n, n, n, h, a )

    r8mat_print ( n, n, ha, '  Product H*A:' )
#
#  If we set A := HA, then we can successively convert A to upper
#  triangular form.
#
    a = ha
#
#  Terminate.
#
  print ''
  print 'R8VEC_HOUSE_COLUMN_TEST'
  print '  Normal end of execution.'

  return