#! /usr/bin/env python # def v_quadrature_rule ( n ): #*****************************************************************************80 # ## V_QUADRATURE_RULE: quadrature rule for V(n,x). # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 20 July 2015 # # Author: # # John Burkardt # # Parameters: # # Input, integer N, the order of the rule. # # Output, real T(N,1), W(N,1), the points and weights of the rule. # import numpy as np from imtqlx import imtqlx aj = np.zeros ( n ) aj[0] = + 0.5 bj = np.zeros ( n ) for i in range ( 0, n ): bj[i] = 0.5 cj = np.zeros ( n ) cj[0] = np.sqrt ( np.pi ) t, w = imtqlx ( n, aj, bj, cj ) for i in range ( 0, n ): w[i] = w[i] ** 2 return t, w def v_quadrature_rule_test ( ): #*****************************************************************************80 # ## V_QUADRATURE_RULE_TEST tests V_QUADRATURE_RULE. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 14 July 2015 # # Author: # # John Burkardt # import numpy as np import platform from r8vec2_print import r8vec2_print from v_moment import v_moment print ( '' ) print ( 'V_QUADRATURE_RULE_TEST:' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' V_QUADRATURE_RULE computes the quadrature rule' ) print ( ' associated with V(n,x)' ) n = 7 x, w = v_quadrature_rule ( n ) r8vec2_print ( n, x, w, ' X W' ) print ( '' ) print ( ' Use the quadrature rule to estimate:' ) print ( '' ) print ( ' Q = Integral ( -1 <= X <= +1 ) X^E * sqrt(1+x)/sqrt(1-x) dx' ) print ( '' ) print ( ' E Q_Estimate Q_Exact' ) print ( '' ) f = np.zeros ( n ) for e in range ( 0, 2 * n ): if ( e == 0 ): for i in range ( 0, n ): f[i] = 1.0 else: for i in range ( 0, n ): f[i] = x[i] ** e q = np.dot ( w, f ) q_exact = v_moment ( e ) print ( ' %2d %14g %14g' % ( e, q, q_exact ) ) # # Terminate. # print ( '' ) print ( 'V_QUADRATURE_RULE_TEST:' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) v_quadrature_rule_test ( ) timestamp ( )