# -*- coding: utf-8 -*- import numpy as np x=np.array([0,2,3],float) y=np.array([7,11,28],float) xp=float(input('Enter x:')) #defined yp as 0 for starting.Actually yp is the summation so def interpolate(xp):#It can be written in xp=float(value). #we will use summation loop so the intial value of the summation should #start from zero yp=0 #zip: When calculating xi, it is used to put the x #and y values in order. for xi,yi in zip(x,y): #thanks to prod: can use to xi for loop in this and two variables print(xi,yi) yp +=yi*np.prod((xp-x[x !=xi])/(xi-x [x !=xi])) # martix array multiplication #x !=xi :do not include the calculated term in the formula. return yp #xp=3 print('For x=%.2f,y=%f' % (xp,interpolate(xp)))