#! /usr/bin/env python # def rule_adjust ( a, b, c, d, norder, x, w ): #*****************************************************************************80 # ## RULE_ADJUST maps a quadrature rule from [A,B] to [C,D]. # # Discussion: # # Most quadrature rules are defined on a special interval, like # [-1,1] or [0,1]. To integrate over an interval, the abscissas # and weights must be adjusted. This can be done on the fly, # or by calling this routine. # # If the weight function W(X) is not 1, then the W vector will # require further adjustment by the user. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 08 July 2018 # # Author: # # John Burkardt # # Parameters: # # Input, real A, B, the endpoints of the definition interval. # # Input, real C, D, the endpoints of the integration interval. # # Input, integer NORDER, the number of abscissas and weights. # # Input, real X(NORDER), W(NORDER), the abscissas # and weights defined on [A,B]. # # Output, real X_NEW(NORDER), W_NEW(NORDER), the abscissas # and weights, redefined on [C,D]. # x_new = \ ( ( b - x[:] ) * c \ + ( x[:] - a ) * d ) \ / ( b - a ) w_new = ( ( d - c ) / ( b - a ) ) * w[:] return x_new, w_new def rule_adjust_test ( ): #*****************************************************************************80 # ## RULE_ADJUST_TEST tests RULE_ADJUST. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 08 July 2018 # # Author: # # John Burkardt # import numpy as np import platform from r8vec2_print import r8vec2_print print ( '' ) print ( 'RULE_ADJUST_TEST' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' RULE_ADJUST adjusts a quadrature rule from [A,B] to [C,D].' ) n = 7 x = np.zeros ( n ) w = np.zeros ( n ) for i in range ( 0, n ): angle = np.pi * float ( n - i ) / float ( n + 1 ) w[i] = np.pi / float ( n + 1 ) * ( np.sin ( angle ) ) ** 2 x[i] = np.cos ( angle ) r8vec2_print ( n, w, x, ' W, X defined on [-1,+1]' ) a = - 1.0; b = + 1.0; c = 0.0; d = +1.0; [ x_new, w_new ] = rule_adjust ( a, b, c, d, n, x, w ) r8vec2_print ( n, w_new, x_new, ' W, X adjusted to [0,1]' ) # # Terminate. # print ( '' ) print ( 'RULE_ADJUST_TEST' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) rule_adjust_test ( ) timestamp ( )