Writing

Campanula interpolaorumleg. cstef, 29.xi.2024

Lagrange Interpolation Primer

A quick and simple explanation on the concept of polynomial interpolation, here Lagrange's in particular.

7 min readmaths

You may remember, when in High School, being asked to find the equation of a line that goes through two points. The process was straightforward: you would calculate the slope ๐‘Ž and the intercept ๐‘ of the line ๐‘“(๐‘ฅ)=๐‘Ž๐‘ฅ+๐‘.

This is a simple example of polynomial interpolation, where we are trying to find a polynomial that goes through a set of points. While the process is simple for a line, it becomes slightly more complex for higher degree polynomials.

Polynomials

One of the most, if not the most important property of polynomials, is that each one of them can uniquely be described by ๐‘›+1 points for a polynomial of degree ๐‘›, noted ๐‘“(๐‘ฅ)โˆˆโ„™๐‘›.

The most straightforward way of seeing this is by setting an equation for each point ๐ด๐‘–(๐‘ฅ๐‘–,๐‘ฆ๐‘–) we have:

๐‘ƒ๐‘›(๐‘ฅ)=๐‘ข0+๐‘ข1๐‘ฅ+โ€ฆ+๐‘ข๐‘›๐‘ฅ๐‘›=๐‘“(๐‘ฅ){ ๐‘“(๐‘ฅ0)=๐‘ฆ0 ๐‘“(๐‘ฅ1)=๐‘ฆ1 โ€ฆ ๐‘“(๐‘ฅ๐‘›)=๐‘ฆ๐‘›

We can see that we have ๐‘›+1 equations for ๐‘›+1 factors of ๐‘ฅ, noted ๐‘ข๐‘–|0โ‰ค๐‘–โ‰ค๐‘›, which could also be represented with the following Vandermonde matrix equation:

(1๐‘ฅ0๐‘ฅ02โ‹ฏ๐‘ฅ0๐‘›1๐‘ฅ1๐‘ฅ12โ‹ฏ๐‘ฅ1๐‘›โ‹ฎโ‹ฎโ‹ฎโ‹ฑโ‹ฎ1๐‘ฅ๐‘›๐‘ฅ๐‘›2โ‹ฏ๐‘ฅ๐‘›๐‘›)(๐‘ข0๐‘ข1โ‹ฎ๐‘ข๐‘›)=(๐‘ฆ0๐‘ฆ1โ‹ฎ๐‘ฆ๐‘›)

Written as ๐‘‰๐‘ข=๐‘ฆ, we can solve this by inverting ๐‘‰:

๐‘ข=๐‘‰โˆ’1๐‘ฆ

This is doable by applying the Jordan-Gauss algorithm to the augmented matrix ๐‘‰|๐ผ, where ๐ผ is the identity matrix (diagonal filled with 1s), until we only have pivots equal to 1:

(1๐‘ฅ0๐‘ฅ02โ‹ฏ๐‘ฅ0๐‘› 10โ‹ฏ01๐‘ฅ1๐‘ฅ12โ‹ฏ๐‘ฅ1๐‘› 01โ‹ฏ0โ‹ฎโ‹ฎโ‹ฎโ‹ฑโ‹ฎ โ‹ฎโ‹ฎโ‹ฑโ‹ฎ1๐‘ฅ๐‘›๐‘ฅ๐‘›2โ‹ฏ๐‘ฅ๐‘›๐‘› 00โ‹ฏ1)

If you prefer to see this in a graphical way, letโ€™s consider the following example:

We have two points ๐ด0(1,2) and ๐ด1(โˆ’2,โˆ’3). We can represent them as follows:

It is visually obvious that we can only draw a single line that goes through both points.

A line is essentially just ๐‘“(๐‘ฅ)=๐‘Ž๐‘ฅ+๐‘, which is of degree 1. We can guess and deduce we need at least ๐‘›+1 points to describe a polynomial function ๐‘“(๐‘ฅ)โˆˆโ„™๐‘›.

The same goes if we add a third point ๐ด2(0,4):

If we did not add this third point and still tried to find a polynomial ๐‘ƒ2(๐‘ฅ), we would have an infinite number of solutions:

But now the question is: how do we actually find the polynomial that goes through all the points? This is where Lagrange interpolation comes into play.

Lagrange Interpolation

Letโ€™s take ๐ด0(0,1), ๐ด1(1,3), ๐ด2(2,2) and ๐ด3(3,4) to demonstrate this method.

The main principle behind this is to split the wanted function into multiple sub-functions ๐‘™๐‘–(๐‘ฅ), that each contribute to one given point, also called โ€œnodeโ€.

We want to construct ๐‘™๐‘–(๐‘ฅ) so that:

๐‘™๐‘–(๐‘ฅ)={ 1if๐‘ฅ=๐‘ฅ๐‘– 0if๐‘ฅ=๐‘ฅ๐‘—|๐‘—โ‰ ๐‘–

Making a function equal to 0 at a certain point ๐‘ฅ๐‘— is as simple as multiplying it by (๐‘ฅโˆ’๐‘ฅ๐‘—). Based on this property, we can already โ€œguessโ€ ๐‘™1โˆ—(๐‘ฅ):

๐‘™1โˆ—(๐‘ฅ)=(๐‘ฅโˆ’0)(๐‘ฅโˆ’2)(๐‘ฅโˆ’3)
Why does multiplying by

(๐‘ฅโˆ’๐‘ฅ๐‘—) add a root ?

For a function ๐‘“(๐‘ฅ)=(๐‘ฅโˆ’๐‘ฅ๐‘—)โ‹…๐‘”(๐‘ฅ)|๐‘”(๐‘ฅ)โ†โ„[๐‘ฅ], when ๐‘ฅ=๐‘ฅ๐‘—:

๐‘“(๐‘ฅ๐‘—)=(๐‘ฅ๐‘—โˆ’๐‘ฅ๐‘—)โ‹…๐‘”(๐‘ฅ)=0โ‹…๐‘”(๐‘ฅ)=0

Thatโ€™s a good start! But we have a problem: ๐‘™1โˆ—(๐‘ฅ) is not equal to 1 at ๐‘ฅ=1. We can fix this by dividing ๐‘™1โˆ—(๐‘ฅ) by ๐‘™1โˆ—(1):

๐‘™1(๐‘ฅ)=๐‘™1โˆ—(๐‘ฅ)๐‘™1โˆ—(1)=(๐‘ฅโˆ’0)(๐‘ฅโˆ’2)(๐‘ฅโˆ’3)(1โˆ’0)(1โˆ’2)(1โˆ’3)=(๐‘ฅโˆ’0)(๐‘ฅโˆ’2)(๐‘ฅโˆ’3)2

And we effectively have ๐‘™1(1)=1. We can now repeat this process for ๐‘™0(๐‘ฅ), ๐‘™2(๐‘ฅ) and ๐‘™3(๐‘ฅ):

The polynomial ๐‘“(๐‘ฅ)โˆˆโ„™3 is computed by summing all the ๐‘™๐‘–(๐‘ฅ) together and multiplying them by the corresponding ๐‘ฆ๐‘–:

๐‘“(๐‘ฅ)=๐‘ฆ0๐‘™0(๐‘ฅ)+๐‘ฆ1๐‘™1(๐‘ฅ)+๐‘ฆ2๐‘™2(๐‘ฅ)+๐‘ฆ3๐‘™3(๐‘ฅ)=1โ‹…๐‘™0(๐‘ฅ)+3โ‹…๐‘™1(๐‘ฅ)+2โ‹…๐‘™2(๐‘ฅ)+4โ‹…๐‘™3(๐‘ฅ)

And we have our final polynomial which effectively goes through all the points:

Generalizing this process, we can write the function ๐‘“(๐‘ฅ)โˆˆโ„™๐‘›(๐‘ฅ) that goes through ๐‘›+1 points ๐ด๐‘–(๐‘ฅ๐‘–,๐‘ฆ๐‘–):

๐‘“(๐‘ฅ)=โˆ‘๐‘–=0๐‘›๐‘ฆ๐‘–๐‘™๐‘–(๐‘ฅ)=โˆ‘๐‘–=0๐‘›๐‘ฆ๐‘–โˆ๐‘—=0,๐‘—โ‰ ๐‘–๐‘›๐‘ฅโˆ’๐‘ฅ๐‘—๐‘ฅ๐‘–โˆ’๐‘ฅ๐‘—