function value = cc_weight ( order, i ) %% CC_WEIGHT returns the I-th Clenshaw Curtis weight. % % Licensing: % % This code is distributed under the GNU LGPL license. % % Modified: % % 14 March 2007 % % Author: % % John Burkardt % % Parameters: % % Input, integer ORDER, the order of the rule. % % Input, integer I, the index of the desired weight. 1 <= I <= ORDER. % % Output, real VALUE, the I-th weight in the % Clenshaw-Curtis rule of order ORDER. % if ( order < 1 ) fprintf ( 1, '\n' ); fprintf ( 1, 'CC_WEIGHT - Fatal error!\n' ); fprintf ( 1, ' ORDER < 1.\n' ); error ( 'CC_WEIGHT - Fatal error!' ); end if ( order == 1 ) value = 2.0; return end value = 1.0; for j = 1 : floor ( order - 1 ) / 2 if ( 2 * j == ( order - 1 ) ) b = 1.0; else b = 2.0; end angle = ( 2 * j * ( i - 1 ) ) * pi / ( order - 1 ); value = value - b * cos ( angle ) / ( 4 * j * j - 1 ); end if ( i == 1 ) value = value / ( order - 1 ); elseif ( i <= order - 1 ) value = 2.0 * value / ( order - 1 ); elseif ( i == order ) value = value / ( order - 1 ); end return end