Lagrange_interp_poly_val.py

#function [y] = Lagrange_interp_poly_val(a,x)
#  Accompanying program for the text
#
#     Classical and Modern Numerical Analysis:
#     Theory, Methods and Practice
#  by Azmy S. Ackleh, Edward J. Allen,
#     R. Baker Kearfott, and Padmanabhan Seshaiyer
#
#     (Taylor and Francis / CRC Press, 2009)
#
#     [y] = Lagrange_interp_poly_val(a,x)
#
#  returns the value of the Lagrange interpolating polynomial with
#  coefficients a (computed by Lagrange_interp_poly_coeffs.m) in y.
#  If x is a vector, then, upon return, y will contain the vector of
#  evaluations of Runge's function at corresponding components of x.
#  In such a case, y will be a row vector if x is a row vector, and y will
#  be a column vector if x is a column vector.

def Lagrange_interp_poly_val(a,x):
        n = a.shape[0]
        y = a[0]
        for i in range(1,n):
                y += a[i]*x**i
        return y