points = [0.32,0.73,0.97,1.13,1.52,1.57,2.02,2.52,2.96,3.40,3.79] data =[1.377,2.075,2.637,3.095,4.572,4.806,7.538,12.428,19.297,29.964,44.256] x1 = [1.96,2.14,3.12,3.14,3.15,4.12,5.12,6.14,7.32,7.50,7.80] x=1.96 def method(x,points,data): if len(data) == 1: return data[0] else: A = method(x,points[1:],data[1:])*(x - points[0])/(points[-1] - points[0]) B = method(x,points[:-1],data[:-1])*(x - points[-1])/(points[0] - points[-1]) #print (A+B) return A+B print(method(x,points,data)) 

The function works correctly on single points (point x), but I would like to be able to specify a list of points (list x1) for the further construction of the graph for the calculated points. That is, it is necessary that he alternately input the numbers from the x1 list into the method and make calculations there.

All attempts failed.

  • one
    And what exactly is the problem? - Vladimir Martyanov
  • Well, I need that would be something like this. for s in x1: s = method (x1, points, data) I don’t figure out how to do this. - Dariys
  • That's the way to do it. - Vladimir Martyanov
  • TypeError: unsupported operand type (s) for -: 'list' and 'float' - Dariys
  • You suggest to guess what exactly you did and where exactly got such an error? - Vladimir Martyanov

1 answer 1

To get the list of function values ​​for a given list of parameters:

 y1 = [method(x, point, data) for x in x1]