#! /usr/bin/env python # def shepard_basis_1d ( nd, xd, p, ni, xi ): #*****************************************************************************80 # ## SHEPARD_BASIS_1D evaluates a 1D Shepard basis function. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 03 July 2015 # # Author: # # John Burkardt # # Reference: # # Donald Shepard, # A two-dimensional interpolation function for irregularly spaced data, # ACM '68: Proceedings of the 1968 23rd ACM National Conference, # ACM, pages 517-524, 1969. # # Parameters: # # Input, integer ND, the number of data points. # # Input, real XD(ND,1), the data points. # # Input, integer K, the index of the desired basis function, # 1 <= K <= ND. # # Input, real P, the power. # # Input, integer NI, the number of interpolation points. # # Input, real XI(NI,1), the interpolation points. # # Output, real BK(NI,ND), the basis function at the interpolation points. # import numpy as np bk = np.zeros ( [ ni, nd ] ) w = np.zeros ( nd ) for i in range ( 0, ni ): if ( p == 0.0 ): for j in range ( 0, nd ): w[j] = 1.0 / float ( nd ) else: z = -1 for j in range ( 0, nd ): w[j] = abs ( xi[i] - xd[j] ) if ( w[j] == 0.0 ): z = j if ( z != -1 ): for j in range ( 0, nd ): w[j] = 0.0 w[z] = 1.0 else: for j in range ( 0, nd ): w[j] = 1.0 / w[j] ** p s = np.sum ( w ) for j in range ( 0, nd ): w[j] = w[j] / s for j in range ( 0, nd ): bk[i,j] = w[j] return bk def shepard_basis_1d_test ( ): #*****************************************************************************80 # ## SHEPARD_BASIS_1D_TEST tests SHEPARD_BASIS_1D. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 02 July 2015 # # Author: # # John Burkardt # import numpy as np import platform from r8mat_print import r8mat_print nd = 4 ni = 21 p = 2.0 xd = np.array ( [ 0.0, 2.0, 5.0, 10.0 ] ) print ( '' ) print ( 'SHEPARD_BASIS_1D_TEST:' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' SHEPARD_BASIS_1D evaluates the Shepard 1D basis' ) print ( ' functions.' ) print ( '' ) print ( ' Using power P = %g' % ( p ) ) x_min = 0.0 x_max = 10.0 xi = np.linspace ( x_min, x_max, ni ) lb = shepard_basis_1d ( nd, xd, p, ni, xi ) r8mat_print ( ni, nd, lb, ' The Shepard basis functions:' ) # # Terminate. # print ( '' ) print ( 'SHEPARD_BASIS_1D_TEST:' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) shepard_basis_1d_test ( ) timestamp ( )