#! /usr/bin/env python # def newton_value_1d ( nd, xd, cd, ni, xi ): #*****************************************************************************80 # ## NEWTON_VALUE_1D evaluates a Newton 1D interpolant. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 11 July 2015 # # Author: # # John Burkardt # # Reference: # # Carl deBoor, # A Practical Guide to Splines, # Springer, 2001, # ISBN: 0387953663, # LC: QA1.A647.v27. # # Parameters: # # Input, integer ND, the order of the difference table. # # Input, real XD(ND), the X values of the difference table. # # Input, real CD(ND), the divided differences. # # Input, integer NI, the number of interpolation points. # # Input, real XI(NI), the interpolation points. # # Output, real YI(NI), the interpolation values. # import numpy as np yi = np.zeros ( ni ) for i in range ( 0, ni ): yi[i] = cd[nd-1] for j in range ( 1, nd ): for i in range ( 0, ni ): yi[i] = cd[nd-j-1] + ( xi[i] - xd[nd-j-1] ) * yi[i] return yi def newton_value_1d_test ( ): #*****************************************************************************80 # ## NEWTON_VALUE_1D_TEST tests NEWTON_VALUE_1D. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 11 July 2015 # # Author: # # John Burkardt # import numpy as np from r8vec2_print import r8vec2_print print ( '' ) print ( 'NEWTON_VALUE_1D_TEST' ) print ( ' NEWTON_VALUE_1D evaluates a Newton 1d interpolant.' ) nd = 5 xd = np.array ( [ 0.0, 1.0, 2.0, 3.0, 4.0 ] ) cd = np.array ( [ 24.0, -24.0, +12.0, -4.0, 1.0 ] ) r8vec2_print ( nd, xd, cd, ' The Newton interpolant data:' ) ni = 16 x_lo = 0.0 x_hi = 5.0 xi = np.linspace ( x_lo, x_hi, ni ) yi = newton_value_1d ( nd, xd, cd, ni, xi ) r8vec2_print ( ni, xi, yi, ' Newton interpolant values:' ) # # Terminate. # print ( '' ) print ( 'NEWTON_VALUE_1D_TEST:' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) newton_value_1d_test ( ) timestamp ( )