Jump to content

Lagrange polynomial: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
removed as out of place, unreferenced, and totally unexplained.
MathFacts (talk | contribs)
m rvv
Line 4: Line 4:


[[Image:Lagrange polynomial.svg|thumb|This image shows, for four points (<font color=#b30000>(&minus;9,&nbsp;5)</font>, <font color=#0000b3>(&minus;4,&nbsp;2)</font>, <font color=#00b300>(&minus;1,&nbsp;&minus;2)</font>, <font color=#b3b300>(7,&nbsp;9)</font>), the (cubic) interpolation polynomial <font color=#000000>''L''(''x'')</font> (in black), which is the sum of the ''scaled'' basis polynomials <font color=#b30000>y<sub>0</sub>''ℓ''<sub>0</sub>(''x'')</font>, <font color=#0000b3>y<sub>1</sub>''ℓ''<sub>1</sub>(''x'')</font>, <font color=#00b300>y<sub>2</sub>''ℓ''<sub>2</sub>(''x'')</font> and <font color=#b3b300>y<sub>3</sub>''ℓ''<sub>3</sub>(''x'')</font>. The interpolation polynomial passes through all four control points, and each ''scaled'' basis polynomial passes through its respective control point and is 0 where ''x'' corresponds to the other three control points.]]
[[Image:Lagrange polynomial.svg|thumb|This image shows, for four points (<font color=#b30000>(&minus;9,&nbsp;5)</font>, <font color=#0000b3>(&minus;4,&nbsp;2)</font>, <font color=#00b300>(&minus;1,&nbsp;&minus;2)</font>, <font color=#b3b300>(7,&nbsp;9)</font>), the (cubic) interpolation polynomial <font color=#000000>''L''(''x'')</font> (in black), which is the sum of the ''scaled'' basis polynomials <font color=#b30000>y<sub>0</sub>''ℓ''<sub>0</sub>(''x'')</font>, <font color=#0000b3>y<sub>1</sub>''ℓ''<sub>1</sub>(''x'')</font>, <font color=#00b300>y<sub>2</sub>''ℓ''<sub>2</sub>(''x'')</font> and <font color=#b3b300>y<sub>3</sub>''ℓ''<sub>3</sub>(''x'')</font>. The interpolation polynomial passes through all four control points, and each ''scaled'' basis polynomial passes through its respective control point and is 0 where ''x'' corresponds to the other three control points.]]




==Definition==
==Definition==
Line 82: Line 84:


</source>
</source>

==Equidistant interpolation==

For the case where the distance between interpolation poles is equal 1 and the poles are situated in the points k=0,1,2,3,... the interpolating approximation <math>\sigma(x)</math> of function <math>f(x)</math> is as follows:

For equidistant poles Lagrange interpolation formula is as follows:

<math>
\sigma(x)=\lim_{N\to\infty}C_x^{N+1}\sum_{k=0}^N\frac{(-1)^{N-k}\,C_N^k (N+1)}{x-k}f(k)
</math>


==Usage==
==Usage==

Revision as of 23:14, 17 February 2010

In numerical analysis, a Lagrange polynomial, named after Joseph Louis Lagrange, is the interpolating polynomial for a given set of data points in the Lagrange form. It was first discovered by Edward Waring in 1779 and later rediscovered by Leonhard Euler in 1783.

Notice that, for any given set of data points, there is only one polynomial (of least possible degree) that interpolates these points. Thus, it is more appropriate to call it "the Lagrange form of the interpolation polynomial" rather than "the Lagrange interpolation polynomial".

This image shows, for four points ((−9, 5), (−4, 2), (−1, −2), (7, 9)), the (cubic) interpolation polynomial L(x) (in black), which is the sum of the scaled basis polynomials y00(x), y11(x), y22(x) and y33(x). The interpolation polynomial passes through all four control points, and each scaled basis polynomial passes through its respective control point and is 0 where x corresponds to the other three control points.


Definition

Given a set of k + 1 data points

where no two xj are the same, the interpolation polynomial in the Lagrange form is a linear combination

of Lagrange basis polynomials

Note how, assuming no two are the same (and they must be, or the dataset doesn't make sense), , so this expression is always well-defined.

Proof

For L(x) to properly interpolate the data, the function we are looking for has to be a polynomial function L(x) of degree less than or equal to k and where for each datapoint j

If this statement holds for all j we say the polynomial is a solution to the interpolation problem.

Proof:

  1. In there are k terms in the product and each term contains one x, so L(x) (which is a sum of these k-degree polynomials) must also be a k-degree polynomial.

Watch what happens if we expand this product. Because the product skips , If then all terms are (except where but that case is impossible as pointed out in the definition section---if you tried to write out that term you'd find that and since , , contrary to ). Also if then since doesn't preclude it, one term in the product will be for , i.e. , zeroing the entire product. So

where is the Kronecker delta. So:

Thus the function L(x) is a polynomial with degree at most k and where , Q.E.D.

Additionally, the interpolating polynomial is unique, as shown by the unisolvence theorem at Polynomial interpolation.

Main idea

Solving an interpolation problem leads to a problem in linear algebra where we have to solve a matrix. Using a standard monomial basis for our interpolation polynomial we get the Vandermonde matrix. By choosing another basis, the Lagrange basis, we get the much simpler identity matrix = δi,j which we can solve instantly: the Lagrange basis inverts the Vandermonde matrix.

Implementation in C++

Note : "pos" and "val" arrays are of size "degree".

double lagrangeInterpolatingPolynomial (double pos[], double val[], int degree, double desiredPos)  {
   double retVal = 0;

   for (int i = 0; i < degree; ++i) {
      double weight = 1;

      for (int j = 0; j < degree; ++j) {
         // The i-th term has to be skipped
         if (j != i) {
            weight *= (desiredPos - pos[j]) / (pos[i] - pos[j]);
         }
      }

      retVal += weight * val[i];
   }

   return retVal;
}

Equidistant interpolation

For the case where the distance between interpolation poles is equal 1 and the poles are situated in the points k=0,1,2,3,... the interpolating approximation of function is as follows:

For equidistant poles Lagrange interpolation formula is as follows:

Usage

Example 1

The tangent function and its interpolant

Find an interpolation formula for ƒ(x) = tan(x) given this set of known values:

The basis polynomials are:

Thus the interpolating polynomial then is



you can use MatLab(R) polyfit(x,y,n) function where n is the polynomial degree you want,
in the above example
x=[-1.5 -0.75 0.75 1.5];
y=[-14.1014 -0.931596 0.931596 14.1014];
n=3

polyfit(x,y,n)

ans =

   4.8348    0.0000   -1.4775   -0.0000

Example 2

We wish to interpolate ƒ(x) = x2 over the range 1 ≤ x ≤ 3, given these three points:

The interpolating polynomial is:

Example 3

We wish to interpolate ƒ(x) = x3 over the range 1 ≤ x ≤ 3, given these 3 points:

The interpolating polynomial is:

Notes

Example of Lagrange polynomial interpolation divergence.

The Lagrange form of the interpolation polynomial shows the linear character of polynomial interpolation and the uniqueness of the interpolation polynomial. Therefore, it is preferred in proofs and theoretical arguments. Uniqueness can also be seen from the invertibility of the Vandermonde matrix, due to the non-vanishing of the Vandermonde determinant.

But, as can be seen from the construction, each time a node xk changes, all Lagrange basis polynomials have to be recalculated. A better form of the interpolation polynomial for practical (or computational) purposes is the barycentric form of the Lagrange interpolation (see below) or Newton polynomials.

Lagrange and other interpolation at equally spaced points, as in the example above, yield a polynomial oscillating above and below the true function. This behaviour tends to grow with the number of points, leading to a divergence known as Runge's phenomenon; the problem may be eliminated by choosing interpolation points at Chebyshev nodes.

The Lagrange basis polynomials can be used in numerical integration to derive the Newton–Cotes formulas.

Barycentric interpolation

Using the quantity

we can rewrite the Lagrange basis polynomials as

or, by defining the barycentric weights[1]

we can simply write

which is commonly referred to as the first form of the barycentric interpolation formula.

The advantage of this representation is that the interpolation polynomial may now be evaluated as

which, if the weights have been pre-computed, requires only operations (evaluating and the weights ) as opposed to for evaluating the Lagrange basis polynomials individually.

The barycentric interpolation formula can also easily be updated to incorporate a new node by dividing each of the , by and constructing the new as above.

We can further simplify the first form by first considering the barycentric interpolation of the constant function :

Dividing by does not modify the interpolation, yet yields

which is referred to as the second form or true form of the barycentric interpolation formula. This second form has the advantage that need not be evaluated for each evaluation of .

Finite fields

The Lagrange polynomial can also be computed in finite fields. This has applications in cryptography, such as in Shamir's Secret Sharing scheme.

See also

References

  1. ^ Jean-Paul Berrut, Lloyd N. Trefethen (2004). "Barycentric Lagrange Interpolation". SIAM Review. 46 (3): 501–517. doi:10.1137/S0036144502417715.

External links

  1. ^ Zachary Battles, Lloyd N. Trefethen (2004). "An Extension of MATLAB to Continuous Functions and Operators". SIAM J. Sci. Comput. 25 (5): 1743–1770. doi:10.1137/S1064827503430126.