#! /usr/bin/env python # def w_quadrature_rule ( n ): #*****************************************************************************80 # ## W_QUADRATURE_RULE: quadrature rule for W(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 w_quadrature_rule_test ( ): #*****************************************************************************80 # ## W_QUADRATURE_RULE_TEST tests W_QUADRATURE_RULE. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 16 July 2015 # # Author: # # John Burkardt # import numpy as np import platform from r8vec2_print import r8vec2_print from w_moment import w_moment print ( '' ) print ( 'W_QUADRATURE_RULE_TEST:' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' W_QUADRATURE_RULE computes the quadrature rule' ) print ( ' associated with W(n,x)' ) n = 7 x, w = w_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 = w_moment ( e ) print ( ' %2d %14g %14g' % ( e, q, q_exact ) ) # # Terminate. # print ( '' ) print ( 'W_QUADRATURE_RULE_TEST:' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) w_quadrature_rule_test ( ) timestamp ( )