Newton uses a polynomial for the interpolation of yp that can be calculated in a recursive procedure. The basic formulation of this polynomial is:
We first have to calculate |XkXk-1| terms. From this the |XkXk-1Xk-2|…terms and so on. Even though we only need the value on the very top of each column for b0 to b4, we have to calculate all the elements. But in a recursive function it becomes quite simple
void
CalcElements(double[]
x, int
order, int step)
{
int i;
double[] xx;
if (order >= 1)
{
xx = new double[order];
for (i = 0; i < order-1; i++)
{
xx[i] = (x[i + 1] - x[i]) / (x_k[i + step] - x_k[i]);
}
b[step - 1] = x[0];
CalcElements(xx, order - 1, step + 1);
}
{
int i;
double[] xx;
if (order >= 1)
{
xx = new double[order];
for (i = 0; i < order-1; i++)
{
xx[i] = (x[i + 1] - x[i]) / (x_k[i + step] - x_k[i]);
}
b[step - 1] = x[0];
CalcElements(xx, order - 1, step + 1);
}
}
Now one yp interpolation value can be calculated like:
for (i = 1;
i <
order; i++)
{
tempYp = b[i];
for (k = 0; k < i; k++)
{
tempYp = tempYp * (xp - x_k[k]);
}
yp = yp + tempYp;
}
{
tempYp = b[i];
for (k = 0; k < i; k++)
{
tempYp = tempYp * (xp - x_k[k]);
}
yp = yp + tempYp;
}
There we have
If we now have a look at 3 supporting points, things become a bit more complicate:
The therm
Now if xp = x3 we get
For other approaches see Polynomial interpolation, Lagrange interpolation, Newton Gregory interpolation, Interpolation by Chebychev polynomials