def r8vec_data_read_test ( ): #*****************************************************************************80 # ## R8VEC_DATA_READ_TEST tests R8VEC_DATA_READ. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 03 December 2014 # # Author: # # John Burkardt # from r8vec_print import r8vec_print print '' print 'R8VEC_DATA_READ_TEST:' print ' Test R8VEC_DATA_READ, which reads data from an R8VEC.' m = 5 n = 3 filename = 'r8vec_write_test.txt' a = r8vec_data_read ( filename, m ) r8vec_print ( m, a, ' Data read from file:' ) print '' print 'R8VEC_DATA_READ_TEST:' print ' Normal end of execution.' return
def aegerter_eigenvalues_test ( ): #*****************************************************************************80 # ## AEGERTER_EIGENVALUES_TEST tests AEGERTER_EIGENVALUES. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 05 December 2014 # # Author: # # John Burkardt # from r8vec_print import r8vec_print print '' print 'AEGERTER_EIGENVALUES_TEST' print ' AEGERTER_EIGENVALUES computes the eigenvalues of the Aegerter matrix.' n = 5 lam = aegerter_eigenvalues ( n ) r8vec_print ( n, lam, ' Aergerter eigenvalues:' ) print '' print 'AEGERTER_EIGENVALUES_TEST' print ' Normal end of execution.' return
def legendre_zeros_test(): #*****************************************************************************80 # ## LEGENDRE_ZEROS_TEST tests LEGENDRE_ZEROS. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 16 February 2015 # # Author: # # John Burkardt # from r8vec_print import r8vec_print print '' print 'LEGENDRE_ZEROS_TEST' print ' LEGENDRE_ZEROS computes the zeros of the N-th Legendre polynomial.' for n in range(1, 8): l = legendre_zeros(n) r8vec_print(n, l, ' Legendre zeros:') print '' print 'FRANK_TEST' print ' Normal end of execution.' return
def legendre_zeros_test ( ): #*****************************************************************************80 # ## LEGENDRE_ZEROS_TEST tests LEGENDRE_ZEROS. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 16 February 2015 # # Author: # # John Burkardt # from r8vec_print import r8vec_print print '' print 'LEGENDRE_ZEROS_TEST' print ' LEGENDRE_ZEROS computes the zeros of the N-th Legendre polynomial.' for n in range ( 1, 8 ): l = legendre_zeros ( n ) r8vec_print ( n, l, ' Legendre zeros:' ) print '' print 'FRANK_TEST' print ' Normal end of execution.' return
def cheby_u_polynomial_test ( ): #*****************************************************************************80 # ## CHEBY_U_POLYNOMIAL_TEST tests CHEBY_U_POLYNOMIAL. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 14 December 2014 # # Author: # # John Burkardt # from r8vec_print import r8vec_print print '' print 'CHEBY_U_POLYNOMIAL_TEST' print ' CHEBY_U_POLYNOMIAL evaluates Chebyshev U polynomials at X.' n = 10 x = 0.25 c = cheby_u_polynomial ( n, x ) r8vec_print ( n + 1, c, ' Chebyshev U polynomials:' ) print '' print 'CHEBY_U_POLYNOMIAL_TEST' print ' Normal end of execution.' return
def aegerter_eigenvalues_test(): #*****************************************************************************80 # ## AEGERTER_EIGENVALUES_TEST tests AEGERTER_EIGENVALUES. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 05 December 2014 # # Author: # # John Burkardt # from r8vec_print import r8vec_print print '' print 'AEGERTER_EIGENVALUES_TEST' print ' AEGERTER_EIGENVALUES computes the eigenvalues of the Aegerter matrix.' n = 5 lam = aegerter_eigenvalues(n) r8vec_print(n, lam, ' Aergerter eigenvalues:') print '' print 'AEGERTER_EIGENVALUES_TEST' print ' Normal end of execution.' return
def eberlein_null_left_test ( ): #*****************************************************************************80 # ## EBERLEIN_NULL_LEFT_TEST tests EBERLEIN_NULL_LEFT. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 07 March 2015 # # Author: # # John Burkardt # from r8_uniform_ab import r8_uniform_ab from r8mat_is_null_left import r8mat_is_null_left from r8mat_print import r8mat_print from r8vec_print import r8vec_print print '' print 'EBERLEIN_NULL_LEFT_TEST' print ' EBERLEIN_NULL_LEFT returns a left null vector of the EBERLEIN matrix.' print '' m = 5 n = 5 r8_lo = -5.0 r8_hi = +5.0 seed = 123456789 alpha, seed = r8_uniform_ab ( r8_lo, r8_hi, seed ) a = eberlein ( alpha, n ) r8mat_print ( m, n, a, ' EBERLEIN matrix A:' ) x = eberlein_null_left ( m, n ) r8vec_print ( m, x, ' Left null vector X:' ) value = r8mat_is_null_left ( m, n, a, x ) print '' print ' ||x\'*A||/||x|| = %g' % ( value ) print '' print 'EBERLEIN_NULL_LEFT_TEST' print ' Normal end of execution.' return
def r8vec_frac_test ( ): #*****************************************************************************80 # ## R8VEC_FRAC_TEST tests R8VEC_FRAC. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 30 May 2015 # # Author: # # John Burkardt # from r8vec_print import r8vec_print from r8vec_uniform_ab import r8vec_uniform_ab n = 10 ahi = 10.0 alo = 0.0 print '' print 'R8VEC_FRAC_TEST' print ' R8VEC_FRAC: K-th smallest real vector entry;' seed = 123456789 a, seed = r8vec_uniform_ab ( n, alo, ahi, seed ) r8vec_print ( n, a, ' The real array to search: ' ) print '' print 'Frac R8VEC_FRAC' print '' for k in range ( 1, n + 1 ): afrac = r8vec_frac ( n, a, k ) print ' %2d %6f' % ( k, afrac ) # # Terminate. # print '' print 'R8VEC_FRAC_TEST' print ' Normal end of execution.' return
def line_grid_test02 ( ): #*****************************************************************************80 # ## LINE_GRID_TEST02 tries an increasing number of points. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 24 April 2015 # # Author: # # John Burkardt # from r8vec_print import r8vec_print a = 0.0 b = 1.0 c = 2 print '' print 'LINE_GRID_TEST02' print ' Create a grid using LINE_GRID.' print ' Try an increasing number of points.' n = 4 for test in range ( 0, 3 ): n = 2 * n + 1 print '' print ' N C A B' print '' print ' %4d %4d %8.4f %8.4f' % ( n, c, a, b ) x = line_grid ( n, a, b, c ) r8vec_print ( n, x, ' Grid points:' ) # # Terminate. # print '' print 'LINE_GRID_TEST02:' print ' Normal end of execution.' return
def imtqlx_test(): #*****************************************************************************80 # ## IMTQLX_TEST tests IMTQLX. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 15 June 2015 # # Author: # # John Burkardt. # import numpy as np import platform from r8vec_print import r8vec_print print('') print('IMTQLX_TEST') print(' Python version: %s' % (platform.python_version())) print(' IMTQLX takes a symmetric tridiagonal matrix A') print(' and computes its eigenvalues LAM.') print(' It also accepts a vector Z and computes Q\'*Z,') print(' where Q is the matrix that diagonalizes A.') n = 5 d = np.zeros(n) for i in range(0, n): d[i] = 2.0 e = np.zeros(n) for i in range(0, n - 1): e[i] = -1.0 e[n - 1] = 0.0 z = np.ones(n) lam, qtz = imtqlx(n, d, e, z) r8vec_print(n, lam, ' Computed eigenvalues:') lam2 = np.zeros(n) for i in range(0, n): angle = float(i + 1) * np.pi / float(2 * (n + 1)) lam2[i] = 4.0 * (np.sin(angle))**2 r8vec_print(n, lam2, ' Exact eigenvalues:') r8vec_print(n, z, ' Vector Z:') r8vec_print(n, qtz, ' Vector Q' '*Z:') # # Terminate. # print('') print('IMTQLX_TEST:') print(' Normal end of execution.') return
def r8mat_mtv_test(): #*****************************************************************************80 # ## R8MAT_MTV_TEST tests R8MAT_MTV. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 07 March 2015 # # Author: # # John Burkardt # import numpy as np from r8mat_print import r8mat_print from r8vec_print import r8vec_print m = 4 n = 2 a = np.array \ ( \ ( ( 1.0, 1.0 ), \ ( 2.0, 1.0 ), \ ( 3.0, 1.0 ), \ ( 4.0, 1.0 ) ) \ ) x = np.array((1.0, 2.0, 3.0, 4.0)) print '' print 'R8MAT_MTV_TEST' print ' R8MAT_MTV computes a matrix-vector product b = A\' * x;' b = r8mat_mtv(m, n, a, x) r8mat_print(m, n, a, ' A:') r8vec_print(m, x, ' X:') r8vec_print(n, b, ' B = A\'*X:') print '' print 'R8MAT_MTV_TEST' print ' Normal end of execution.' return
def r8mat_mtv_test ( ): #*****************************************************************************80 # ## R8MAT_MTV_TEST tests R8MAT_MTV. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 07 March 2015 # # Author: # # John Burkardt # import numpy as np from r8mat_print import r8mat_print from r8vec_print import r8vec_print m = 4 n = 2 a = np.array \ ( \ ( ( 1.0, 1.0 ), \ ( 2.0, 1.0 ), \ ( 3.0, 1.0 ), \ ( 4.0, 1.0 ) ) \ ) x = np.array ( ( 1.0, 2.0, 3.0, 4.0 ) ) print '' print 'R8MAT_MTV_TEST' print ' R8MAT_MTV computes a matrix-vector product b = A\' * x;' b = r8mat_mtv ( m, n, a, x ) r8mat_print ( m, n, a, ' A:' ) r8vec_print ( m, x, ' X:' ) r8vec_print ( n, b, ' B = A\'*X:' ) print '' print 'R8MAT_MTV_TEST' print ' Normal end of execution.' return
def line_grid_test02(): # *****************************************************************************80 # ## LINE_GRID_TEST02 tries an increasing number of points. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 24 April 2015 # # Author: # # John Burkardt # from r8vec_print import r8vec_print a = 0.0 b = 1.0 c = 2 print "" print "LINE_GRID_TEST02" print " Create a grid using LINE_GRID." print " Try an increasing number of points." n = 4 for test in range(0, 3): n = 2 * n + 1 print "" print " N C A B" print "" print " %4d %4d %8.4f %8.4f" % (n, c, a, b) x = line_grid(n, a, b, c) r8vec_print(n, x, " Grid points:") # # Terminate. # print "" print "LINE_GRID_TEST02:" 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 r8mat_is_null_left_test ( ): #*****************************************************************************80 # ## R8MAT_IS_NULL_LEFT_TEST tests R8MAT_IS_NULL_LEFT. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 07 March 2015 # # Author: # # John Burkardt # import numpy as np from r8mat_print import r8mat_print from r8vec_print import r8vec_print m = 3 n = 3 a = np.array ( [ \ [ 1.0, 2.0, 3.0 ], \ [ 4.0, 5.0, 6.0 ], \ [ 7.0, 8.0, 9.0 ] ]) x = np.array ( [ 1.0, -2.0, 1.0 ] ) print '' print 'R8MAT_IS_NULL_LEFT_TEST:' print ' R8MAT_IS_NULL_LEFT tests whether the M vector X' print ' is a left null vector of A, that is, A\'*x=0.' r8mat_print ( m, n, a, ' Matrix A:' ) r8vec_print ( m, x, ' Vector X:' ) enorm = r8mat_is_null_left ( m, n, a, x ) print '' print ' Frobenius norm of A\'*x is %g' % ( enorm ) print '' print 'R8MAT_IS_NULL_LEFT_TEST' print ' Normal end of execution.' return
def r8mat_is_null_left_test(): #*****************************************************************************80 # ## R8MAT_IS_NULL_LEFT_TEST tests R8MAT_IS_NULL_LEFT. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 07 March 2015 # # Author: # # John Burkardt # import numpy as np from r8mat_print import r8mat_print from r8vec_print import r8vec_print m = 3 n = 3 a = np.array ( [ \ [ 1.0, 2.0, 3.0 ], \ [ 4.0, 5.0, 6.0 ], \ [ 7.0, 8.0, 9.0 ] ]) x = np.array([1.0, -2.0, 1.0]) print '' print 'R8MAT_IS_NULL_LEFT_TEST:' print ' R8MAT_IS_NULL_LEFT tests whether the M vector X' print ' is a left null vector of A, that is, A\'*x=0.' r8mat_print(m, n, a, ' Matrix A:') r8vec_print(m, x, ' Vector X:') enorm = r8mat_is_null_left(m, n, a, x) print '' print ' Frobenius norm of A\'*x is %g' % (enorm) print '' print 'R8MAT_IS_NULL_LEFT_TEST' print ' Normal end of execution.' return
def gear_eigenvalues_test ( ): #*****************************************************************************80 # ## GEAR_EIGENVALUES_TEST tests GEAR_EIGENVALUES. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 06 February 2015 # # Author: # # John Burkardt # from gear import gear from i4_uniform_ab import i4_uniform_ab from r8mat_print import r8mat_print from r8vec_print import r8vec_print print '' print 'GEAR_EIGENVALUES_TEST' print ' GEAR_EIGENVALUES computes the GEAR eigenvalues.' m = 5 n = 5 i4_lo = -n i4_hi = +n seed = 123456789 ii, seed = i4_uniform_ab ( i4_lo, i4_hi, seed ) jj, seed = i4_uniform_ab ( i4_lo, i4_hi, seed ) a = gear ( ii, jj, n ) r8mat_print ( m, n, a, ' GEAR matrix:' ) lam = gear_eigenvalues ( ii, jj, n ) r8vec_print ( n, lam, ' GEAR eigenvalues:' ) print '' print 'GEAR_EIGENVALUES_TEST' print ' Normal end of execution.' return
def gear_eigenvalues_test(): #*****************************************************************************80 # ## GEAR_EIGENVALUES_TEST tests GEAR_EIGENVALUES. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 06 February 2015 # # Author: # # John Burkardt # from gear import gear from i4_uniform_ab import i4_uniform_ab from r8mat_print import r8mat_print from r8vec_print import r8vec_print print '' print 'GEAR_EIGENVALUES_TEST' print ' GEAR_EIGENVALUES computes the GEAR eigenvalues.' m = 5 n = 5 i4_lo = -n i4_hi = +n seed = 123456789 ii, seed = i4_uniform_ab(i4_lo, i4_hi, seed) jj, seed = i4_uniform_ab(i4_lo, i4_hi, seed) a = gear(ii, jj, n) r8mat_print(m, n, a, ' GEAR matrix:') lam = gear_eigenvalues(ii, jj, n) r8vec_print(n, lam, ' GEAR eigenvalues:') print '' print 'GEAR_EIGENVALUES_TEST' print ' Normal end of execution.' return
def r8vec_norm_l0_test(): #*****************************************************************************80 # ## R8VEC_NORM_L0_TEST tests R8VEC_NORM_L0. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 03 January 2015 # # Author: # # John Burkardt # from r8vec_nint import r8vec_nint from r8vec_print import r8vec_print from r8vec_uniform_ab import r8vec_uniform_ab print '' print 'R8VEC_NORM_L0_TEST' print ' R8VEC_NORM_L0 computes the L0 "norm" of an R8VEC.' n = 10 a_lo = -2.0 a_hi = +2.0 seed = 123456789 a, seed = r8vec_uniform_ab(n, a_lo, a_hi, seed) a = r8vec_nint(n, a) r8vec_print(n, a, ' Input vector:') value = r8vec_norm_l0(n, a) print '' print ' L0 norm = %g' % (value) # # Terminate. # print '' print 'R8VEC_NORM_L0_TEST:' print ' Normal end of execution.' return
def line_grid_test03 ( ): #*****************************************************************************80 # ## LINE_GRID_TEST03 tries all the centering options. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 24 April 2015 # # Author: # # John Burkardt # from r8vec_print import r8vec_print n = 11 a = 0.0 b = +100.0 print '' print 'LINE_GRID_TEST03' print ' Try the different centering options.' print ' Number of grid points N = %d' % ( n ) for c in range ( 1, 6 ): print '' print ' N C A B' print '' print ' %4d %4d %8.4f %8.4f' % ( n, c, a, b ) x = line_grid ( n, a, b, c ) r8vec_print ( n, x, ' Grid points:' ) # # Terminate. # print '' print 'LINE_GRID_TEST03:' print ' Normal end of execution.' return
def line_grid_test03(): # *****************************************************************************80 # ## LINE_GRID_TEST03 tries all the centering options. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 24 April 2015 # # Author: # # John Burkardt # from r8vec_print import r8vec_print n = 11 a = 0.0 b = +100.0 print "" print "LINE_GRID_TEST03" print " Try the different centering options." print " Number of grid points N = %d" % (n) for c in range(1, 6): print "" print " N C A B" print "" print " %4d %4d %8.4f %8.4f" % (n, c, a, b) x = line_grid(n, a, b, c) r8vec_print(n, x, " Grid points:") # # Terminate. # print "" print "LINE_GRID_TEST03:" print " Normal end of execution." return
def r8vec_norm_l0_test ( ): #*****************************************************************************80 # ## R8VEC_NORM_L0_TEST tests R8VEC_NORM_L0. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 03 January 2015 # # Author: # # John Burkardt # from r8vec_nint import r8vec_nint from r8vec_print import r8vec_print from r8vec_uniform_ab import r8vec_uniform_ab print '' print 'R8VEC_NORM_L0_TEST' print ' R8VEC_NORM_L0 computes the L0 "norm" of an R8VEC.' n = 10 a_lo = - 2.0 a_hi = + 2.0 seed = 123456789 a, seed = r8vec_uniform_ab ( n, a_lo, a_hi, seed ) a = r8vec_nint ( n, a ) r8vec_print ( n, a, ' Input vector:' ) value = r8vec_norm_l0 ( n, a ) print '' print ' L0 norm = %g' % ( value ) # # Terminate. # print '' print 'R8VEC_NORM_L0_TEST:' print ' Normal end of execution.' return
def r8vec_permute_test ( ): #*****************************************************************************80 # ## R8VEC_PERMUTE_TEST tests R8VEC_PERMUTE. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 26 October 2014 # # Author: # # John Burkardt # from i4vec_print import i4vec_print from r8vec_print import r8vec_print import numpy as np n = 5 print '' print 'R8VEC_PERMUTE_TEST' print ' R8VEC_PERMUTE permutes an R8VEC.' x = np.array ( [ 1.1, 2.2, 3.3, 4.4, 5.5 ], dtype = np.float64 ) p = np.array ( [ 1, 3, 4, 0, 2 ], dtype = np.int32 ) r8vec_print ( n, x, ' Original array X[]:' ) i4vec_print ( n, p, ' Permutation vector P[]:' ) x = r8vec_permute ( n, p, x ) r8vec_print ( n, x, ' Permuted array X[P[*]]:' ) # # Terminate. # print '' print 'R8VEC_PERMUTE_TEST:' print ' Normal end of execution.' return
def r8vec_norm_li_test(): # *****************************************************************************80 # ## R8VEC_NORM_LI_TEST tests R8VEC_NORM_LI. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 19 February 2015 # # Author: # # John Burkardt # from r8vec_nint import r8vec_nint from r8vec_print import r8vec_print from r8vec_uniform_ab import r8vec_uniform_ab print "" print "R8VEC_NORM_LI_TEST" print " R8VEC_NORM_LI computes the Loo norm of an R8VEC." n = 10 r8_lo = -5.0 r8_hi = +5.0 seed = 123456789 a, seed = r8vec_uniform_ab(n, r8_lo, r8_hi, seed) r8vec_print(n, a, " Input vector:") value = r8vec_norm_li(n, a) print "" print " Loo norm = %g" % (value) # # Terminate. # print "" print "R8VEC_NORM_LI_TEST:" print " Normal end of execution." return
def r8vec_norm_li_test(): #*****************************************************************************80 # ## R8VEC_NORM_LI_TEST tests R8VEC_NORM_LI. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 19 February 2015 # # Author: # # John Burkardt # from r8vec_nint import r8vec_nint from r8vec_print import r8vec_print from r8vec_uniform_ab import r8vec_uniform_ab print '' print 'R8VEC_NORM_LI_TEST' print ' R8VEC_NORM_LI computes the Loo norm of an R8VEC.' n = 10 r8_lo = -5.0 r8_hi = +5.0 seed = 123456789 a, seed = r8vec_uniform_ab(n, r8_lo, r8_hi, seed) r8vec_print(n, a, ' Input vector:') value = r8vec_norm_li(n, a) print '' print ' Loo norm = %g' % (value) # # Terminate. # print '' print 'R8VEC_NORM_LI_TEST:' print ' Normal end of execution.' return
def moler2_null_left_test(): #*****************************************************************************80 # ## MOLER2_NULL_LEFT_TEST tests MOLER2_NULL_LEFT. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 08 March 2015 # # Author: # # John Burkardt # from r8mat_is_null_left import r8mat_is_null_left from r8mat_print import r8mat_print from r8vec_print import r8vec_print print '' print 'MOLER2_NULL_LEFT_TEST' print ' MOLER2_NULL_LEFT returns a left null vector of the MOLER2 matrix.' print '' m = 5 n = 5 a = moler2() r8mat_print(m, n, a, ' MOLER2 matrix A:') x = moler2_null_left() r8vec_print(m, x, ' Left null vector X:') value = r8mat_is_null_left(m, n, a, x) print '' print ' ||x\'*A||/||x|| = %g' % (value) print '' print 'MOLER2_NULL_LEFT_TEST' print ' Normal end of execution.' return
def r8vec_permute_test(): #*****************************************************************************80 # ## R8VEC_PERMUTE_TEST tests R8VEC_PERMUTE. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 26 October 2014 # # Author: # # John Burkardt # from i4vec_print import i4vec_print from r8vec_print import r8vec_print import numpy as np n = 5 print '' print 'R8VEC_PERMUTE_TEST' print ' R8VEC_PERMUTE permutes an R8VEC.' x = np.array([1.1, 2.2, 3.3, 4.4, 5.5], dtype=np.float64) p = np.array([1, 3, 4, 0, 2], dtype=np.int32) r8vec_print(n, x, ' Original array X[]:') i4vec_print(n, p, ' Permutation vector P[]:') x = r8vec_permute(n, p, x) r8vec_print(n, x, ' Permuted array X[P[*]]:') # # Terminate. # print '' print 'R8VEC_PERMUTE_TEST:' print ' Normal end of execution.' return
def r8vec_variance_test(): #*****************************************************************************80 # ## R8VEC_VARIANCE_TEST tests R8VEC_VARIANCE. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 02 March 2015 # # Author: # # John Burkardt # import platform from r8vec_print import r8vec_print from r8vec_uniform_ab import r8vec_uniform_ab print('') print('R8VEC_VARIANCE_TEST') print(' Python version: %s' % (platform.python_version())) print(' R8VEC_VARIANCE computes the variance of an R8VEC.') n = 10 r8_lo = -5.0 r8_hi = +5.0 seed = 123456789 a, seed = r8vec_uniform_ab(n, r8_lo, r8_hi, seed) r8vec_print(n, a, ' Input vector:') value = r8vec_variance(n, a) print('') print(' Value = %g' % (value)) # # Terminate. # print('') print('R8VEC_VARIANCE_TEST:') print(' Normal end of execution.') return
def line_grid_test01 ( ): #*****************************************************************************80 # ## LINE_GRID_TEST01 uses simple parameters. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 24 April 2015 # # Author: # # John Burkardt # from r8vec_print import r8vec_print n = 11 a = -1.0 b = +1.0 c = 1 print '' print 'LINE_GRID_TEST01' print ' Create a grid using LINE_GRID.' print ' Use simple parameters.' print ' Number of grid points N = %d' % ( n ) print '' print ' N C A B' print '' print ' %4d %4d %8.4f %8.4f' % ( n, c, a, b ) x = line_grid ( n, a, b, c ) r8vec_print ( n, x, ' Grid points:' ) # # Terminate. # print '' print 'LINE_GRID_TEST01:' print ' Normal end of execution.' return
def complete_symmetric_poly_test ( ): #*****************************************************************************80 # ## COMPLETE_SYMMETRIC_POLY_TEST tests COMPLETE_SYMMETRIC_POLY. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 27 January 2015 # # Author: # # John Burkardt # import numpy as np from r8vec_print import r8vec_print print '' print 'COMPLETE_SYMMETRIC_POLY_TEST' print ' COMPLETE_SYMMETRIC_POLY evaluates a complete symmetric' print ' polynomial in a given set of variables X.' n = 5 x = np.array ( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ) r8vec_print ( n, x, ' Variable vector X:' ) print '' print ' N\\R 0 1 2 3 4 5' print '' for nn in range ( 0, n + 1 ): print ' %2d' % ( nn ), for rr in range ( 0, 6 ): value = complete_symmetric_poly ( nn, rr, x ) print ' %6d' % ( value ), print '' print '' print 'COMPLETE_SYMMETRIC_POLY_TEST:' print ' Normal end of execution.' return
def moler2_null_left_test ( ): #*****************************************************************************80 # ## MOLER2_NULL_LEFT_TEST tests MOLER2_NULL_LEFT. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 08 March 2015 # # Author: # # John Burkardt # from r8mat_is_null_left import r8mat_is_null_left from r8mat_print import r8mat_print from r8vec_print import r8vec_print print '' print 'MOLER2_NULL_LEFT_TEST' print ' MOLER2_NULL_LEFT returns a left null vector of the MOLER2 matrix.' print '' m = 5 n = 5 a = moler2 ( ) r8mat_print ( m, n, a, ' MOLER2 matrix A:' ) x = moler2_null_left ( ) r8vec_print ( m, x, ' Left null vector X:' ) value = r8mat_is_null_left ( m, n, a, x ) print '' print ' ||x\'*A||/||x|| = %g' % ( value ) print '' print 'MOLER2_NULL_LEFT_TEST' print ' Normal end of execution.' return
def r8vec_max_test ( ): #*****************************************************************************80 # ## R8VEC_MAX_TEST tests R8VEC_MAX. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 15 January 2015 # # Author: # # John Burkardt # import platform from r8vec_print import r8vec_print from r8vec_uniform_ab import r8vec_uniform_ab print ( '' ) print ( 'R8VEC_MAX_TEST' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' R8VEC_MAX computes the maximum entry in an R8VEC.' ) n = 10 a_lo = - 10.0 a_hi = + 10.0 seed = 123456789 a, seed = r8vec_uniform_ab ( n, a_lo, a_hi, seed ) r8vec_print ( n, a, ' Input vector:' ) value = r8vec_max ( n, a ) print ( '' ) print ( ' Max = %g' % ( value ) ) # # Terminate. # print ( '' ) print ( 'R8VEC_MAX_TEST:' ) print ( ' Normal end of execution.' ) return
def line_grid_test01(): # *****************************************************************************80 # ## LINE_GRID_TEST01 uses simple parameters. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 24 April 2015 # # Author: # # John Burkardt # from r8vec_print import r8vec_print n = 11 a = -1.0 b = +1.0 c = 1 print "" print "LINE_GRID_TEST01" print " Create a grid using LINE_GRID." print " Use simple parameters." print " Number of grid points N = %d" % (n) print "" print " N C A B" print "" print " %4d %4d %8.4f %8.4f" % (n, c, a, b) x = line_grid(n, a, b, c) r8vec_print(n, x, " Grid points:") # # Terminate. # print "" print "LINE_GRID_TEST01:" print " Normal end of execution." return
def r8vec_uniform_ab_test(): #*****************************************************************************80 # ## R8VEC_UNIFORM_AB_TEST tests R8VEC_UNIFORM_AB. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 29 October 2014 # # Author: # # John Burkardt # import numpy as np import platform from r8vec_print import r8vec_print n = 10 a = -1.0 b = +5.0 seed = 123456789 print('') print('R8VEC_UNIFORM_AB_TEST') print(' Python version: %s' % (platform.python_version())) print(' R8VEC_UNIFORM_AB computes a random R8VEC.') print('') print(' %g <= X <= %g' % (a, b)) print(' Initial seed is %d' % (seed)) v, seed = r8vec_uniform_ab(n, a, b, seed) r8vec_print(n, v, ' Random R8VEC:') # # Terminate. # print('') print('R8VEC_UNIFORM_AB_TEST:') print(' Normal end of execution.') return
def r8vec_product_test ( ): #*****************************************************************************80 # ## R8VEC_PRODUCT_TEST tests R8VEC_PRODUCT. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 20 March 2015 # # Author: # # John Burkardt # from r8vec_print import r8vec_print from r8vec_uniform_ab import r8vec_uniform_ab print '' print 'R8VEC_PRODUCT_TEST' print ' R8VEC_PRODUCT computes the product of the entries in an R8VEC.' n = 10 a_lo = - 10.0 a_hi = + 10.0 seed = 123456789 a, seed = r8vec_uniform_ab ( n, a_lo, a_hi, seed ) r8vec_print ( n, a, ' Input vector:' ) value = r8vec_product ( n, a ) print '' print ' Product of entries = %g' % ( value ) # # Terminate. # print '' print 'R8VEC_PRODUCT_TEST:' print ' Normal end of execution.' return
def r8vec_min_test ( ): #*****************************************************************************80 # ## R8VEC_MIN_TEST tests R8VEC_MIN. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 15 January 2015 # # Author: # # John Burkardt # from r8vec_print import r8vec_print from r8vec_uniform_ab import r8vec_uniform_ab print '' print 'R8VEC_MIN_TEST' print ' R8VEC_MIN computes the minimum entry in an R8VEC.' n = 10 a_lo = - 10.0 a_hi = + 10.0 seed = 123456789 a, seed = r8vec_uniform_ab ( n, a_lo, a_hi, seed ) r8vec_print ( n, a, ' Input vector:' ) value = r8vec_min ( n, a ) print '' print ' Min = %g' % ( value ) # # Terminate. # print '' print 'R8VEC_MIN_TEST:' print ' Normal end of execution.' return
def r8vec_product_test(): #*****************************************************************************80 # ## R8VEC_PRODUCT_TEST tests R8VEC_PRODUCT. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 20 March 2015 # # Author: # # John Burkardt # from r8vec_print import r8vec_print from r8vec_uniform_ab import r8vec_uniform_ab print '' print 'R8VEC_PRODUCT_TEST' print ' R8VEC_PRODUCT computes the product of the entries in an R8VEC.' n = 10 a_lo = -10.0 a_hi = +10.0 seed = 123456789 a, seed = r8vec_uniform_ab(n, a_lo, a_hi, seed) r8vec_print(n, a, ' Input vector:') value = r8vec_product(n, a) print '' print ' Product of entries = %g' % (value) # # Terminate. # print '' print 'R8VEC_PRODUCT_TEST:' print ' Normal end of execution.' return
def r8vec_asum_test ( ): #*****************************************************************************80 # ## R8VEC_ASUM_TEST tests R8VEC_ASUM. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 24 January 2015 # # Author: # # John Burkardt # from r8vec_print import r8vec_print from r8vec_uniform_ab import r8vec_uniform_ab print '' print 'R8VEC_ASUM_TEST' print ' R8VEC_ASUM sums the absolute values of the entries in an R8VEC.' n = 10 a_lo = - 10.0 a_hi = + 10.0 seed = 123456789 a, seed = r8vec_uniform_ab ( n, a_lo, a_hi, seed ) r8vec_print ( n, a, ' Input vector:' ) value = r8vec_asum ( n, a ) print '' print ' Sum of absolute values of entries = %g' % ( value ) # # Terminate. # print '' print 'R8VEC_ASUM_TEST:' print ' Normal end of execution.' return
def r8vec_amin_test ( ): #*****************************************************************************80 # ## R8VEC_AMIN_TEST tests R8VEC_AMIN. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 16 January 2015 # # Author: # # John Burkardt # from r8vec_print import r8vec_print from r8vec_uniform_ab import r8vec_uniform_ab print '' print 'R8VEC_AMIN_TEST' print ' R8VEC_AMIN computes the minimum absolute entry in an R8VEC.' n = 10 a_lo = - 10.0 a_hi = + 10.0 seed = 123456789 a, seed = r8vec_uniform_ab ( n, a_lo, a_hi, seed ) r8vec_print ( n, a, ' Input vector:' ) value = r8vec_amin ( n, a ) print '' print ' Min Abs = %g' % ( value ) # # Terminate. # print '' print 'R8VEC_AMIN_TEST:' print ' Normal end of execution.' return
def r8vec_asum_test(): #*****************************************************************************80 # ## R8VEC_ASUM_TEST tests R8VEC_ASUM. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 24 January 2015 # # Author: # # John Burkardt # from r8vec_print import r8vec_print from r8vec_uniform_ab import r8vec_uniform_ab print '' print 'R8VEC_ASUM_TEST' print ' R8VEC_ASUM sums the absolute values of the entries in an R8VEC.' n = 10 a_lo = -10.0 a_hi = +10.0 seed = 123456789 a, seed = r8vec_uniform_ab(n, a_lo, a_hi, seed) r8vec_print(n, a, ' Input vector:') value = r8vec_asum(n, a) print '' print ' Sum of absolute values of entries = %g' % (value) # # Terminate. # print '' print 'R8VEC_ASUM_TEST:' print ' Normal end of execution.' return
def r8vec_normal_ab_test ( ): #*****************************************************************************80 # ## R8VEC_NORMAL_AB_TEST tests R8VEC_NORMAL_AB. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 04 March 2015 # # Author: # # John Burkardt # from r8vec_print import r8vec_print import numpy as np print '' print 'R8VEC_NORMAL_AB_TEST' print ' R8VEC_NORMAL_AB returns a vector of Normal AB values' n = 10 mu = 15.0 sigma = 0.25 seed = 123456789 print '' print ' Mean = %g' % ( mu ) print ' Standard deviation = %g' % ( sigma ) print ' SEED = %d' % ( seed ) r, seed = r8vec_normal_ab ( n, mu, sigma, seed ) r8vec_print ( n, r, ' Vector:' ) print '' print 'R8VEC_NORMAL_AB_TEST:' print ' Normal end of execution.' return
def r8vec_uniform_ab_test ( ): #*****************************************************************************80 # ## R8VEC_UNIFORM_AB_TEST tests R8VEC_UNIFORM_AB. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 29 October 2014 # # Author: # # John Burkardt # from r8vec_print import r8vec_print import numpy as np n = 10 a = -1.0 b = +5.0 seed = 123456789 print '' print 'R8VEC_UNIFORM_AB_TEST' print ' R8VEC_UNIFORM_AB computes a random R8VEC.' print '' print ' %g <= X <= %g' % ( a, b ) print ' Initial seed is %d' % ( seed ) v, seed = r8vec_uniform_ab ( n, a, b, seed ) r8vec_print ( n, v, ' Random R8VEC:' ) # # Terminate. # print '' print 'R8VEC_UNIFORM_AB_TEST:' print ' Normal end of execution.' return
def r8mat_house_form_test(): #*****************************************************************************80 # ## R8MAT_HOUSE_FORM_TEST tests R8MAT_HOUSE_FORM. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 16 February 2015 # # Author: # # John Burkardt # import numpy as np from r8mat_print import r8mat_print from r8vec_print import r8vec_print n = 5 v = np.array((0.0, 0.0, 1.0, 2.0, 3.0)) print '' print 'R8MAT_HOUSE_FORM_TEST' print ' R8MAT_HOUSE_FORM forms a Householder' print ' matrix from its compact form.' r8vec_print(n, v, ' Compact vector form V:') h = r8mat_house_form(n, v) r8mat_print(n, n, h, ' Householder matrix H:') print '' print 'R8MAT_HOUSE_FORM_TEST' print ' Normal end of execution.' return
def r8mat_house_form_test ( ): #*****************************************************************************80 # ## R8MAT_HOUSE_FORM_TEST tests R8MAT_HOUSE_FORM. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 16 February 2015 # # Author: # # John Burkardt # import numpy as np from r8mat_print import r8mat_print from r8vec_print import r8vec_print n = 5 v = np.array ( ( 0.0, 0.0, 1.0, 2.0, 3.0 ) ) print '' print 'R8MAT_HOUSE_FORM_TEST' print ' R8MAT_HOUSE_FORM forms a Householder' print ' matrix from its compact form.' r8vec_print ( n, v, ' Compact vector form V:' ) h = r8mat_house_form ( n, v ) r8mat_print ( n, n, h, ' Householder matrix H:' ) print '' print 'R8MAT_HOUSE_FORM_TEST' print ' Normal end of execution.' return
def r8vec_norm_l2_test ( ): #*****************************************************************************80 # ## R8VEC_NORM_L2_TEST tests R8VEC_NORM_L2. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 02 January 2015 # # Author: # # John Burkardt # from r8vec_print import r8vec_print from r8vec_uniform_ab import r8vec_uniform_ab print '' print 'R8VEC_NORM_L2_TEST' print ' R8VEC_NORM_L2 computes the L2 norm of an R8VEC.' n = 10 a_lo = - n a_hi = + n seed = 123456789 a, seed = r8vec_uniform_ab ( n, a_lo, a_hi, seed ) r8vec_print ( n, a, ' Input vector:' ) a_norm = r8vec_norm_l2 ( n, a ) print '' print ' L2 norm = %g' % ( a_norm ) # # Terminate. # print '' print 'R8VEC_NORM_L2_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 r8vec_amax_test(): #*****************************************************************************80 # ## R8VEC_AMAX_TEST tests R8VEC_AMAX. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 16 January 2015 # # Author: # # John Burkardt # from r8vec_print import r8vec_print from r8vec_uniform_ab import r8vec_uniform_ab print '' print 'R8VEC_AMAX_TEST' print ' R8VEC_AMAX computes the maximum absolute value entry in an R8VEC.' n = 10 a_lo = -10.0 a_hi = +10.0 seed = 123456789 a, seed = r8vec_uniform_ab(n, a_lo, a_hi, seed) r8vec_print(n, a, ' Input vector:') value = r8vec_amax(n, a) print '' print ' Max Abs = %g' % (value) print '' print 'R8VEC_AMAX_TEST:' print ' Normal end of execution.' return
def r8vec_variance_test ( ): #*****************************************************************************80 # ## R8VEC_VARIANCE_TEST tests R8VEC_VARIANCE. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 02 March 2015 # # Author: # # John Burkardt # from r8vec_print import r8vec_print from r8vec_uniform_ab import r8vec_uniform_ab print '' print 'R8VEC_VARIANCE_TEST' print ' R8VEC_VARIANCE computes the variance of an R8VEC.' n = 10 r8_lo = - 5.0 r8_hi = + 5.0 seed = 123456789 a, seed = r8vec_uniform_ab ( n, r8_lo, r8_hi, seed ) r8vec_print ( n, a, ' Input vector:' ) value = r8vec_variance ( n, a ) print '' print ' Value = %g' % ( value ) print '' print 'R8VEC_VARIANCE_TEST:' print ' Normal end of execution.' return
def r8vec_max_test ( ): #*****************************************************************************80 # ## R8VEC_MAX_TEST tests R8VEC_MAX. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 15 January 2015 # # Author: # # John Burkardt # from r8vec_print import r8vec_print from r8vec_uniform_ab import r8vec_uniform_ab print '' print 'R8VEC_MAX_TEST' print ' R8VEC_MAX computes the maximum entry in an R8VEC.' n = 10 a_lo = - 10.0 a_hi = + 10.0 seed = 123456789 a, seed = r8vec_uniform_ab ( n, a_lo, a_hi, seed ) r8vec_print ( n, a, ' Input vector:' ) value = r8vec_max ( n, a ) print '' print ' Max = %g' % ( value ) print '' print 'R8VEC_MAX_TEST:' print ' Normal end of execution.' return
def r8vec_nint_test ( ): #*****************************************************************************80 # ## R8VEC_NINT_TEST tests R8VEC_NINT. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 06 December 2014 # # Author: # # John Burkardt # from r8vec_print import r8vec_print from r8vec_uniform_ab import r8vec_uniform_ab print '' print 'R8VEC_NINT_TEST' print ' R8VEC_NINT rounds an R8VEC.' n = 5 x1 = -5.0 x2 = +5.0 seed = 123456789 a, seed = r8vec_uniform_ab ( n, x1, x2, seed ) r8vec_print ( n, a, ' Vector A:' ) a = r8vec_nint ( n, a ) r8vec_print ( n, a, ' Rounded vector A:' ) # # Terminate. # print '' print 'R8VEC_NINT_TEST:' print ' Normal end of execution.' return
def r8vec_copy_test ( ): #*****************************************************************************80 # ## R8VEC_COPY_TEST tests R8VEC_COPY. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 28 October 2014 # # Author: # # John Burkardt # from r8vec_print import r8vec_print import numpy as np n1 = 5; a1 = np.array ( [ 91.1, 31.2, 71.3, 51.4, 31.5 ] ) print '' print 'R8VEC_COPY_TEST' print ' R8VEC_COPY copies an R8VEC.' r8vec_print ( n1, a1, ' Array 1:' ); a2 = r8vec_copy ( n1, a1 ); r8vec_print ( n1, a2, ' Array 2:' ); # # Terminate. # print '' print 'R8VEC_COPY_TEST' print ' Normal end of execution.' return
def r8vec_uniform_01_test ( ): #*****************************************************************************80 # ## R8VEC_UNIFORM_01_TEST tests R8VEC_UNIFORM_01. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 29 October 2014 # # Author: # # John Burkardt # from r8vec_print import r8vec_print import numpy as np n = 10 seed = 123456789 print '' print 'R8VEC_UNIFORM_01_TEST' print ' R8VEC_UNIFORM_01 computes a random R8VEC.' print '' print ' Initial seed is %d' % ( seed ) v, seed = r8vec_uniform_01 ( n, seed ) r8vec_print ( n, v, ' Random R8VEC:' ) print '' print 'R8VEC_UNIFORM_01_TEST:' print ' Normal end of execution.' return
def r8vec_normal_01_test ( ): #*****************************************************************************80 # ## R8VEC_NORMAL_01_TEST tests R8VEC_NORMAL_01. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 04 March 2015 # # Author: # # John Burkardt # from r8vec_print import r8vec_print import numpy as np n = 10 seed = 123456789 print '' print 'R8VEC_NORMAL_01_TEST' print ' R8VEC_NORMAL_01 returns a vector of Normal 01 values' print '' print ' SEED = %d' % ( seed ) r, seed = r8vec_normal_01 ( n, seed ) r8vec_print ( n, r, ' Vector:' ) print '' print 'R8VEC_NORMAL_01_TEST:' print ' Normal end of execution.' return