def r8poly_dif_test(): #*****************************************************************************80 # ## R8POLY_DIF_TEST tests R8POLY_DIF. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 30 May 2015 # # Author: # # John Burkardt # import numpy as np from r8poly_print import r8poly_print test_num = 2 print '' print 'R8POLY_DIF_TEST' print ' R8POLY_DIF computes derivatives of an R8POLY.' # # 1: Differentiate X^3 + 2*X^2 - 5*X - 6 once. # 2: Differentiate X^4 + 3*X^3 + 2*X^2 - 2 3 times. # for test in range(0, 2): if (test == 0): na = 3 d = 1 a = np.array([-6.0, -5.0, 2.0, 1.0]) elif (test == 1): na = 4 d = 3 a = np.array([-2.0, 5.0, 2.0, 3.0, 1.0]) r8poly_print(na, a, ' The polynomial A:') print '' print ' Differentiate A %d times.' % (d) b = r8poly_dif(na, a, d) r8poly_print(na - d, b, ' The derivative, B:') # # Terminate. # print '' print 'R8POLY_DIF_TEST:' print ' Normal end of execution.' return
def r8poly_degree_test ( ): #*****************************************************************************80 # ## R8POLY_DEGREE_TEST tests R8POLY_DEGREE. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 05 January 2015 # # Author: # # John Burkardt # import numpy as np from r8poly_print import r8poly_print c1 = np.array ( [ 1.0, 2.0, 3.0, 4.0 ] ) c2 = np.array ( [ 1.0, 2.0, 3.0, 0.0 ] ) c3 = np.array ( [ 1.0, 2.0, 0.0, 4.0 ] ) c4 = np.array ( [ 1.0, 0.0, 0.0, 0.0 ] ) c5 = np.array ( [ 0.0, 0.0, 0.0, 0.0 ] ) print '' print 'R8POLY_DEGREE_TEST' print ' R8POLY_DEGREE determines the degree of an R8POLY.' m = 3 r8poly_print ( m, c1, ' The R8POLY:' ) d = r8poly_degree ( m, c1 ) print ' Dimensioned degree = %d, Actual degree = %d' % ( m, d ) r8poly_print ( m, c2, ' The R8POLY:' ) d = r8poly_degree ( m, c2 ) print ' Dimensioned degree = %d, Actual degree = %d' % ( m, d ) r8poly_print ( m, c3, ' The R8POLY:' ) d = r8poly_degree ( m, c3 ) print ' Dimensioned degree = %d, Actual degree = %d' % ( m, d ) r8poly_print ( m, c4, ' The R8POLY:' ) d = r8poly_degree ( m, c4 ) print ' Dimensioned degree = %d, Actual degree = %d' % ( m, d ) r8poly_print ( m, c5, ' The R8POLY:' ) d = r8poly_degree ( m, c5 ) print ' Dimensioned degree = %d, Actual degree = %d' % ( m, d ) print '' print 'R8POLY_DEGREE_TEST:' print ' Normal end of execution.' return
def r8poly_degree_test(): #*****************************************************************************80 # ## R8POLY_DEGREE_TEST tests R8POLY_DEGREE. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 05 January 2015 # # Author: # # John Burkardt # import numpy as np from r8poly_print import r8poly_print c1 = np.array([1.0, 2.0, 3.0, 4.0]) c2 = np.array([1.0, 2.0, 3.0, 0.0]) c3 = np.array([1.0, 2.0, 0.0, 4.0]) c4 = np.array([1.0, 0.0, 0.0, 0.0]) c5 = np.array([0.0, 0.0, 0.0, 0.0]) print '' print 'R8POLY_DEGREE_TEST' print ' R8POLY_DEGREE determines the degree of an R8POLY.' m = 3 r8poly_print(m, c1, ' The R8POLY:') d = r8poly_degree(m, c1) print ' Dimensioned degree = %d, Actual degree = %d' % (m, d) r8poly_print(m, c2, ' The R8POLY:') d = r8poly_degree(m, c2) print ' Dimensioned degree = %d, Actual degree = %d' % (m, d) r8poly_print(m, c3, ' The R8POLY:') d = r8poly_degree(m, c3) print ' Dimensioned degree = %d, Actual degree = %d' % (m, d) r8poly_print(m, c4, ' The R8POLY:') d = r8poly_degree(m, c4) print ' Dimensioned degree = %d, Actual degree = %d' % (m, d) r8poly_print(m, c5, ' The R8POLY:') d = r8poly_degree(m, c5) print ' Dimensioned degree = %d, Actual degree = %d' % (m, d) print '' print 'R8POLY_DEGREE_TEST:' print ' Normal end of execution.' return
def r8poly_dif_test ( ): #*****************************************************************************80 # ## R8POLY_DIF_TEST tests R8POLY_DIF. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 30 May 2015 # # Author: # # John Burkardt # import numpy as np from r8poly_print import r8poly_print test_num = 2 print '' print 'R8POLY_DIF_TEST' print ' R8POLY_DIF computes derivatives of an R8POLY.' # # 1: Differentiate X^3 + 2*X^2 - 5*X - 6 once. # 2: Differentiate X^4 + 3*X^3 + 2*X^2 - 2 3 times. # for test in range ( 0, 2 ): if ( test == 0 ): na = 3 d = 1 a = np.array ( [ -6.0, -5.0, 2.0, 1.0 ] ) elif ( test == 1 ): na = 4 d = 3 a = np.array ( [ -2.0, 5.0, 2.0, 3.0, 1.0 ] ) r8poly_print ( na, a, ' The polynomial A:' ) print '' print ' Differentiate A %d times.' % ( d ) b = r8poly_dif ( na, a, d ) r8poly_print ( na - d, b, ' The derivative, B:' ) # # Terminate. # print '' print 'R8POLY_DIF_TEST:' print ' Normal end of execution.' return
def r8poly_value_horner_test(): #*****************************************************************************80 # ## R8POLY_VALUE_HORNER_TEST tests R8POLY_VALUE_HORNER. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 04 March 2016 # # Author: # # John Burkardt # import numpy as np import platform from r8poly_print import r8poly_print m = 4 n = 16 c = np.array([24.0, -50.0, +35.0, -10.0, 1.0]) print('') print('R8POLY_VALUE_HORNER_TEST') print(' Python version: %s' % (platform.python_version())) print(' R8POLY_VALUE_HORNER evaluates a polynomial at a point') print(' using Horners method.') r8poly_print(m, c, ' The polynomial coefficients:') x_lo = 0.0 x_hi = 5.0 x = np.linspace(x_lo, x_hi, n) print('') print(' I X P(X)') print('') for i in range(0, n): p = r8poly_value_horner(m, c, x[i]) print(' %2d %8.4f %14.6g' % (i, x[i], p)) # # Terminate. # print('') print('R8POLY_VALUE_HORNER_TEST:') print(' Normal end of execution.') return
def r8poly_value_horner_test(): # *****************************************************************************80 # ## R8POLY_VALUE_HORNER_TEST tests R8POLY_VALUE_HORNER. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 05 January 2015 # # Author: # # John Burkardt # import numpy as np from r8poly_print import r8poly_print from r8vec_linspace import r8vec_linspace m = 4 n = 16 c = np.array([24.0, -50.0, +35.0, -10.0, 1.0]) print "" print "R8POLY_VALUE_HORNER_TEST" print " R8POLY_VALUE_HORNER evaluates a polynomial at a point" print " using Horners method." r8poly_print(m, c, " The polynomial coefficients:") x_lo = 0.0 x_hi = 5.0 x = r8vec_linspace(n, x_lo, x_hi) print "" print " I X P(X)" print "" for i in range(0, n): p = r8poly_value_horner(m, c, x[i]) print " %2d %8.4f %14.6g" % (i, x[i], p) print "" print "R8POLY_VALUE_HORNER_TEST:" print " Normal end of execution." return
def r8poly_value_horner_test(): #*****************************************************************************80 # ## R8POLY_VALUE_HORNER_TEST tests R8POLY_VALUE_HORNER. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 05 January 2015 # # Author: # # John Burkardt # import numpy as np from r8poly_print import r8poly_print from r8vec_linspace import r8vec_linspace m = 4 n = 16 c = np.array([24.0, -50.0, +35.0, -10.0, 1.0]) print '' print 'R8POLY_VALUE_HORNER_TEST' print ' R8POLY_VALUE_HORNER evaluates a polynomial at a point' print ' using Horners method.' r8poly_print(m, c, ' The polynomial coefficients:') x_lo = 0.0 x_hi = 5.0 x = r8vec_linspace(n, x_lo, x_hi) print '' print ' I X P(X)' print '' for i in range(0, n): p = r8poly_value_horner(m, c, x[i]) print ' %2d %8.4f %14.6g' % (i, x[i], p) print '' print 'R8POLY_VALUE_HORNER_TEST:' print ' Normal end of execution.' return
def roots_to_r8poly_test(): #*****************************************************************************80 # ## ROOTS_TO_R8POLY_TEST tests ROOTS_TO_R8POLY. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 11 March 2015 # # Author: # # John Burkardt # import numpy as np from r8poly_print import r8poly_print from r8vec_print import r8vec_print n = 5 x = np.array ( [ \ [ 1.0 ], \ [ -4.0 ], \ [ 3.0 ], \ [ 0.0 ], \ [ 3.0 ] ] ) print '' print 'ROOTS_TO_R8POLY_TEST' print ' ROOTS_TO_R8POLY is given N real roots,' print ' and constructs the coefficient vector' print ' of the corresponding polynomial.' r8vec_print(n, x, ' N real roots:') c = roots_to_r8poly(n, x) r8poly_print(n, c, ' The polynomial:') print '' print 'ROOTS_TO_R8POLY_TEST:' print ' Normal end of execution.' return
def roots_to_r8poly_test(): # *****************************************************************************80 # ## ROOTS_TO_R8POLY_TEST tests ROOTS_TO_R8POLY. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 11 March 2015 # # Author: # # John Burkardt # import numpy as np from r8poly_print import r8poly_print from r8vec_print import r8vec_print n = 5 x = np.array([[1.0], [-4.0], [3.0], [0.0], [3.0]]) print "" print "ROOTS_TO_R8POLY_TEST" print " ROOTS_TO_R8POLY is given N real roots," print " and constructs the coefficient vector" print " of the corresponding polynomial." r8vec_print(n, x, " N real roots:") c = roots_to_r8poly(n, x) r8poly_print(n, c, " The polynomial:") print "" print "ROOTS_TO_R8POLY_TEST:" print " Normal end of execution." return
def r8poly_degree_test ( ): #*****************************************************************************80 # ## R8POLY_DEGREE_TEST tests R8POLY_DEGREE. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 26 May 2015 # # Author: # # John Burkardt # import numpy as np from r8poly_print import r8poly_print print '' print 'R8POLY_DEGREE_TEST' print ' R8POLY_DEGREE returns the degree of an R8POLY.' n = 10 a = np.array ( [ 0.0, 1.1, 0.0, 3.3, 4.4, 0.0, 6.6, 7.7, 0.0, 0.0, 0.0 ] ) r8poly_print ( n, a, ' The polynomial:' ) degree = r8poly_degree ( n, a ) print '' print ' The polynomial degree is %d' % ( degree ) # # Terminate. # print '' print 'R8POLY_DEGREE_TEST:' print ' Normal end of execution.' return
def r8poly_degree_test(): #*****************************************************************************80 # ## R8POLY_DEGREE_TEST tests R8POLY_DEGREE. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 26 May 2015 # # Author: # # John Burkardt # import numpy as np from r8poly_print import r8poly_print print '' print 'R8POLY_DEGREE_TEST' print ' R8POLY_DEGREE returns the degree of an R8POLY.' n = 10 a = np.array([0.0, 1.1, 0.0, 3.3, 4.4, 0.0, 6.6, 7.7, 0.0, 0.0, 0.0]) r8poly_print(n, a, ' The polynomial:') degree = r8poly_degree(n, a) print '' print ' The polynomial degree is %d' % (degree) # # Terminate. # print '' print 'R8POLY_DEGREE_TEST:' print ' Normal end of execution.' return
def r8poly_mul_test(): #*****************************************************************************80 # ## R8POLY_MUL_TEST tests R8POLY_MUL. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 29 May 2015 # # Author: # # John Burkardt # import numpy as np from r8poly_print import r8poly_print ntest = 2 print '' print 'R8POLY_MUL_TEST' print ' R8POLY_MUL multiplies two polynomials.' # # 1: Multiply (1+X) times (1-X). Answer is 1-X^2. # 2: Multiply (1+2*X+3*X^2) by (1-2*X). Answer is 1 + 0*X - X^2 - 6*X^3 # for itest in range(0, ntest): if (itest == 0): na = 1 a = np.array([1.0, 1.0]) nb = 1 b = np.array([1.0, -1.0]) elif (itest == 1): na = 2 a = np.array([1.0, 2.0, 3.0]) nb = 1 b = np.array([1.0, -2.0]) c = r8poly_mul(na, a, nb, b) r8poly_print(na, a, ' The factor A:') r8poly_print(nb, b, ' The factor B:') r8poly_print(na + nb, c, ' The product C = A*B:') # # Terminate. # print '' print 'R8POLY_MUL_TEST:' print ' Normal end of execution.' return
def r8poly_mul_test ( ): #*****************************************************************************80 # ## R8POLY_MUL_TEST tests R8POLY_MUL. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 29 May 2015 # # Author: # # John Burkardt # import numpy as np from r8poly_print import r8poly_print ntest = 2 print '' print 'R8POLY_MUL_TEST' print ' R8POLY_MUL multiplies two polynomials.' # # 1: Multiply (1+X) times (1-X). Answer is 1-X^2. # 2: Multiply (1+2*X+3*X^2) by (1-2*X). Answer is 1 + 0*X - X^2 - 6*X^3 # for itest in range ( 0, ntest ): if ( itest == 0 ): na = 1 a = np.array ( [ 1.0, 1.0 ] ) nb = 1 b = np.array ( [ 1.0, -1.0 ] ) elif ( itest == 1 ): na = 2 a = np.array ( [ 1.0, 2.0, 3.0 ] ) nb = 1 b = np.array ( [ 1.0, -2.0 ] ) c = r8poly_mul ( na, a, nb, b ) r8poly_print ( na, a, ' The factor A:' ) r8poly_print ( nb, b, ' The factor B:' ) r8poly_print ( na+nb, c, ' The product C = A*B:' ) # # Terminate. # print '' print 'R8POLY_MUL_TEST:' print ' Normal end of execution.' return
def zernike_poly_coef_test ( ): #*****************************************************************************80 # ## ZERNIKE_POLY_COEF_TEST tests ZERNIKE_POLY_COEF. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 27 February 2015 # # Author: # # John Burkardt # from r8poly_print import r8poly_print n = 5 print '' print 'ZERNIKE_POLY_COEF_TEST' print ' ZERNIKE_POLY_COEF determines the Zernike' print ' polynomial coefficients.' for m in range ( 0, n + 1 ): c = zernike_poly_coef ( m, n ) r8poly_print ( n, c, ' Zernike polynomial:' ) print '' print 'ZERNIKE_POLY_COEF_TEST' print ' Normal end of execution.' return
def r8poly_add_test(): #*****************************************************************************80 # ## R8POLY_ADD_TEST tests R8POLY_ADD. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 28 May 2015 # # Author: # # John Burkardt # import numpy as np from r8poly_degree import r8poly_degree from r8poly_print import r8poly_print print '' print 'R8POLY_ADD_TEST' print ' R8POLY_ADD adds two R8POLY\'s.' na = 5 a = np.array([0.0, 1.1, 2.2, 3.3, 4.4, 5.5]) nb = 5 b = np.array([1.0, -2.1, 7.2, 8.3, 0.0, -5.5]) c = r8poly_add(na, a, nb, b) r8poly_print(na, a, ' Polynomial A:') r8poly_print(nb, b, ' Polynomial B:') nc = max(na, nb) nc2 = r8poly_degree(nc, c) r8poly_print(nc2, c, ' Polynomial C = A+B:') # # Terminate. # print '' print 'R8POLY_ADD_TEST:' print ' Normal end of execution.' return
def r8poly_add_test(): # *****************************************************************************80 # ## R8POLY_ADD_TEST tests R8POLY_ADD. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 28 May 2015 # # Author: # # John Burkardt # import numpy as np from r8poly_degree import r8poly_degree from r8poly_print import r8poly_print print "" print "R8POLY_ADD_TEST" print " R8POLY_ADD adds two R8POLY's." na = 5 a = np.array([0.0, 1.1, 2.2, 3.3, 4.4, 5.5]) nb = 5 b = np.array([1.0, -2.1, 7.2, 8.3, 0.0, -5.5]) c = r8poly_add(na, a, nb, b) r8poly_print(na, a, " Polynomial A:") r8poly_print(nb, b, " Polynomial B:") nc = max(na, nb) nc2 = r8poly_degree(nc, c) r8poly_print(nc2, c, " Polynomial C = A+B:") # # Terminate. # print "" print "R8POLY_ADD_TEST:" print " Normal end of execution." return
def r8poly_div_test(): #*****************************************************************************80 # ## R8POLY_DIV_TEST tests R8POLY_DIV. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 30 May 2015 # # Author: # # John Burkardt # import numpy as np from r8poly_print import r8poly_print print '' print 'R8POLY_DIV_TEST' print ' R8POLY_DIV computes the quotient and' print ' remainder for polynomial division.' # # 1: Divide X^3 + 2*X^2 - 5*X - 6 by X-2. # Quotient is 3+4*X+X^2, remainder is 0. # # 2: Divide X^4 + 3*X^3 + 2*X^2 - 2 by X^2 + X - 3. # Quotient is X^2 + 2*X + 3, remainder 8*X + 7. # ntest = 2 for test in range(0, ntest): if (test == 0): na = 3 a = np.array([-6.0, -5.0, 2.0, 1.0]) nb = 1 b = np.array([-2.0, 1.0]) elif (test == 1): na = 4 a = np.array([-2.0, 5.0, 2.0, 3.0, 1.0]) nb = 2 b = np.array([-3.0, 1.0, 1.0]) r8poly_print(na, a, ' The polynomial to be divided, A:') r8poly_print(nb, b, ' The divisor polynomial, B:') nq, q, nr, r = r8poly_div(na, a, nb, b) r8poly_print(nq, q, ' The quotient polynomial, Q:') r8poly_print(nr, r, ' The remainder polynomial, R:') # # Terminate. # print '' print 'R8POLY_DIV_TEST:' print ' Normal end of execution.' return
def r8poly_div_test ( ): #*****************************************************************************80 # ## R8POLY_DIV_TEST tests R8POLY_DIV. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 30 May 2015 # # Author: # # John Burkardt # import numpy as np from r8poly_print import r8poly_print print '' print 'R8POLY_DIV_TEST' print ' R8POLY_DIV computes the quotient and' print ' remainder for polynomial division.' # # 1: Divide X^3 + 2*X^2 - 5*X - 6 by X-2. # Quotient is 3+4*X+X^2, remainder is 0. # # 2: Divide X^4 + 3*X^3 + 2*X^2 - 2 by X^2 + X - 3. # Quotient is X^2 + 2*X + 3, remainder 8*X + 7. # ntest = 2 for test in range ( 0, ntest ): if ( test == 0 ): na = 3 a = np.array ( [ -6.0, -5.0, 2.0, 1.0 ] ) nb = 1 b = np.array ( [ -2.0, 1.0 ] ) elif ( test == 1 ): na = 4 a = np.array ( [ -2.0, 5.0, 2.0, 3.0, 1.0 ] ) nb = 2 b = np.array ( [ -3.0, 1.0, 1.0 ] ) r8poly_print ( na, a, ' The polynomial to be divided, A:' ) r8poly_print ( nb, b, ' The divisor polynomial, B:' ) nq, q, nr, r = r8poly_div ( na, a, nb, b ) r8poly_print ( nq, q, ' The quotient polynomial, Q:' ) r8poly_print ( nr, r, ' The remainder polynomial, R:' ) # # Terminate. # print '' print 'R8POLY_DIV_TEST:' print ' Normal end of execution.' return