
from numpy import asarray

def neville(xData,yData,x):  #The following function implements Neville’s 
    m = len(xData)              #method; it returns Pn(x):
    y = yData.copy()
    for k in range(1,m):
        y[0:m-k] = ((x - xData[k:m])*y[0:m-k] + \
         (xData[0:m-k] - x)*y[1:m-k+1])/ \
         (xData[0:m-k] - xData[k:m])
    return y[0]


#Asarray ensures that the array is protected during copying of the array.
    
yData = asarray( [ 4,3.9,3.8,3.7 ] )  
xData = asarray( [ -0.06634,-0.02724, 0.01282,0.05383 ] )

print (neville(xData,yData, 0)) 


"""
X is unknown. Since Y is given as 0, the order (name) of the matrices 
is changed in order not to change the formula.
"""



