#! /usr/bin/env python # def vandermonde_value_1d ( nd, cd, ni, xi ): #*****************************************************************************80 # ## VANDERMONDE_VALUE_1D evaluates a Vandermonde interpolant. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 03 July 2015 # # Author: # # John Burkardt # # Parameters: # # Input, integer ND, the number of data values. # # Input, real CD(ND,1), the polynomial coefficients. # CD(I) is the coefficient of X^(I-1). # # Input, integer NI, the number of interpolation points. # # Input, real XI(NI,1), the interpolation points. # # Output, real YI(NI,1), the interpolation values. # import numpy as np yi = np.zeros ( ni ) for j in range ( 0, ni ): yi[j] = cd[nd-1] for i in range ( nd - 2, -1, -1 ): yi[j] = yi[j] * xi[j] + cd[i] return yi def vandermonde_value_1d_test ( ): #*****************************************************************************80 # ## VANDERMONDE_VALUE_1D_TEST tests VANDERMONDE_VALUE_1D. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 03 July 2015 # # Author: # # John Burkardt # import numpy as np import platform from r8poly_print import r8poly_print from r8vec2_print import r8vec2_print print ( '' ) print ( 'VANDERMONDE_VALUE_1D_TEST' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' VANDERMONDE_VALUE_1D evaluates a Vandermonde interpolant.' ) nd = 5 cd = np.array ( [ 24.0, -50.0, +35.0, -10.0, 1.0 ] ) r8poly_print ( nd - 1, cd, ' The Vandermonde interpolant:' ) ni = 16 x_lo = 0.0 x_hi = 5.0 xi = np.linspace ( x_lo, x_hi, ni ) yi = vandermonde_value_1d ( nd, cd, ni, xi ) r8vec2_print ( ni, xi, yi, ' Vandermonde interpolant values:' ) # # Terminate. # print ( '' ) print ( 'VANDERMONDE_VALUE_1D_TEST:' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) vandermonde_value_1d_test ( ) timestamp ( )