Newton Function Interpolation
Overview
The newton interpolation method constructs a polynomial to fit a set of given points. It constructs the function
iteratively. Starting from a set of points
{% (x_0, y_0),(x_1, y_1), ... ,(x_{n-1}, y_{n-1}) %}
Then, Newton constructs a polynomial as follows.
{% p(x) = a_0 + a_1(x-x_0) + a_2(x-x_0)(x-x_1) + ... + a_n(x-x_0)...(x-x_{n-1}) %}
The polynomial is designed to be able to calculate the coefficients (the a's) successively. For instance,
plugging {% x_0 %} into the polyomial, we get
{% p(x_0) = a_0 %}
Because we know the value of the function at {% x_0 %}, we can assign that value to {% a_0 %}.
{% p(x_1) = f(x_0) + a_1(x_1 - x_0) %}
Newton Module
the newton.mjs module includes two methods for performing a Newton interpolation. The known points of the
function are represented as an array of arrays. (The first number is the x value, the second is the y value).
The coefficients method returns the coefficents as an array. The interpolate method takes the computed coefficients, the original points,
and an x value and returns the interpolated y value.
let nw = await import('/lib/approximation/interpolation/v1.0.0/newton.mjs');
let points = [[0,0],[1,2], [2,1], [3,2.5]];
let coef = nw.coefficients(points);
let int1 = nw.interpolate(coef,points,3)
Try it!