Lagrange interpolation

For one interpolation point (xp, yp) Lagrange builds one enumerator polynomial and one denominator polynomial per supporting point including the xp value for the interpolation and the x values of the n supporting points. The enumerator divided by the denominator gives a factor Lk. For n supporting points that makes n polynomials L1..Ln.

Interpolation

Please note: In the denominator the term (xi – xk) is allways missing where i = k and in the enumerator (xp – xk) is missing for the same k. That’s an essential detail :-)

Where k runs from 1 to n and xp is the interpolation variable to which the value yp shall be calculated later on.

The interpolation value yp becomes now the sum of all the Lk* yk terms whereas yk is the y value of one supporting point.

Interpolation


Now, if xp becomes x0, x1, x2, x3… one of the (xi - xk) becomes 0 in most of the Lk’s. Except where xp = xk. There Lk becomes 1 and therefore yp becomes yk in this case. That means the interpolation function exactly meets each supporting point.


The interpolation for one interpolation point is made in one loop including the calculation of all the Lk elements and adding the multiplication of Lk * yk together:


for (i = 0; i < order; i++)
  {
                enumerator = 1.0;
                denominator = 1.0;
                /* calculate the Lk elements */
                for (k = 0; k < order; k++)
                {
                    if (k != i)
                    {
                        /* enumerator and denominator for one L element */
                        enumerator = enumerator * (xp - x_k[k]);
                        denominator = denominator * (x_k[i] - x_k[k]);
                     }
                }
                /* put every thing thogether to yp*/
               if (denominator != 0.0)
                    yp = yp + y_k[i] * enumerator / denominator;
                else
                   yp = 0.0;
  }


This loop calculates one yp interpolation value.

For other approaches see Polynomial interpolation, Newton interpolation, Newton Gregory interpolation, Interpolation by Chebychev polynomials


C# Demo Project Lagrange interpolation
  • Lagrange.zip

  • Java Demo Project Lagrange interpolation
  • LagrangePoly.zip