#! /usr/bin/env python # def pn_polynomial_value ( m, n, x ): #*****************************************************************************80 # ## PN_POLYNOMIAL_VALUE evaluates the normalized Legendre polynomials Pn(n,x). # # Discussion: # # The normalized Legendre polynomials are orthonormal under the inner product # defined as integration from -1 to 1: # # Integral ( -1 <= x <= +1 ) Pn(i,x) * Pn(j,x) dx = delta(i,j) # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 17 March 2016 # # Author: # # John Burkardt # # Reference: # # Milton Abramowitz, Irene Stegun, # Handbook of Mathematical Functions, # National Bureau of Standards, 1964, # ISBN: 0-486-61272-4, # LC: QA47.A34. # # Daniel Zwillinger, editor, # CRC Standard Mathematical Tables and Formulae, # 30th Edition, # CRC Press, 1996. # # Parameters: # # Input, integer M, the number of evaluation points. # # Input, integer N, the highest order polynomial to evaluate. # Note that polynomials 0 through N will be evaluated. # # Input, real X(M,1), the evaluation points. # # Output, real V(M,1:N+1), the values of the Legendre polynomials # of order 0 through N, # import numpy as np from p_polynomial_value import p_polynomial_value v = p_polynomial_value ( m, n, x ); for j in range ( 0, n + 1 ): norm = np.sqrt ( 2.0 / ( 2 * j + 1 ) ) for i in range ( 0, m ): v[i,j] = v[i,j] / norm return v def pn_polynomial_value_test ( ): #*****************************************************************************80 # ## PN_POLYNOMIAL_VALUE_TEST tests PN_POLYNOMIAL_VALUE. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 17 March 2012 # # Author: # # John Burkardt # import numpy as np import platform from pn_polynomial_values import pn_polynomial_values m = 1 xvec = np.zeros ( 1 ) print ( '' ) print ( 'PN_POLYNOMIAL_VALUE_TEST:' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' PN_POLYNOMIAL_VALUE evaluates the normalized Legendre polynomial Pn(n,x).' ) print ( '' ) print ( ' Tabulated Computed' ) print ( ' N X Pn(N,X) Pn(N,X) Error' ) print ( '' ) n_data = 0 while ( True ): n_data, n, x, fx1 = pn_polynomial_values ( n_data ) if ( n_data == 0 ): break xvec[0] = x v = pn_polynomial_value ( m, n, xvec ) fx2 = v[0,n] e = fx1 - fx2 print ( ' %4d %12g %24.16g %24.16g %8g' % ( n, x, fx1, fx2, e ) ) # # Terminate. # print ( '' ) print ( 'PN_POLYNOMIAL_VALUE_TEST' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) pn_polynomial_value_test ( ) timestamp ( )