All problems
Lagrange Interpolation Value
Problem
Evaluate the Lagrange interpolating polynomial through the given points at x.
points is a list of [x_i, y_i] pairs and the result is sum over i of y_i times the product over j != i of (x - x_j) / (x_i - x_j). A single point returns its y value everywhere.
Hint
Each basis polynomial equals 1 at its own node and 0 at every other node.
Test cases
case 1
in: [[[0,1],[1,3]],2]
expected: 5
case 2
in: [[[0,0],[1,1],[2,4]],3]
expected: 9
case 3
in: [[[0,0],[1,1],[2,4]],0.5]
expected: 0.25
case 4
in: [[[-1,1],[1,1]],0]
expected: 1
case 5
in: [[[2,5]],7]
expected: 5
Starter codePython
def lagrange_interpolate(points, x):
# Your code here
pass5 test cases · run your code against them in the editor