10-12-2016, 08:12 PM
This is a one-line program, to find an interpolated value using a polynomial interpolation function to a set of data points.
Example 1: Find the interpolated value y at x=1.5, given the data points (0,3), (1,5) and (2,9)
Executing: Polynomial_Interpolation([[0,3],[1,5],[2,9]],1.5), we get: 6.75 (parabolic interpolation through 3 points)
Example 2: Find the interpolated value y at x=1.5, given the data points (1,5) and (2,9)
Executing: Polynomial_Interpolation([[1,5],[2,9]],1.5), we get: 7 (linear interpolation through 2 points)
PHP Code:
EXPORT Polynomial_Interpolation(data,x)
// data:[[x1,y1], x:value → interpolated value y
// [x2,y2]
// .......
// [xn,yn]]
BEGIN
POLYEVAL(polynomial_regression(data,rowDim(data)-1),x);
END;
Example 1: Find the interpolated value y at x=1.5, given the data points (0,3), (1,5) and (2,9)
Executing: Polynomial_Interpolation([[0,3],[1,5],[2,9]],1.5), we get: 6.75 (parabolic interpolation through 3 points)
Example 2: Find the interpolated value y at x=1.5, given the data points (1,5) and (2,9)
Executing: Polynomial_Interpolation([[1,5],[2,9]],1.5), we get: 7 (linear interpolation through 2 points)