As everybody knows, the formula for Lagrangian interpolation though points , where all the values are distinct, is given by
It is easy to see that this works, as the product is equal to zero if and is equal to one if .
But a method introduced by Gabor Szegö provides a very simple form of Lagrange’s polynomial.
Start with defining
This is obtained immediately from the product rule for arbitrary products, and using the fact that the derivative of each individual term of is one. This means that in particular
because all other terms of contain an term and therefore produce zero for .
This means that the coefficient of in the Lagrangian polynomial can be written as
and so the polynomial can be written as
Here is an example, with and . First, Maxima:
sage: xs = [-2,1,3,4] sage: ys = [-3, -27, -23, 3] sage: pi(x) = prod(x-i for i in xs); pi(x) (x - 4)*(x - 3)*(x - 1)*(x + 2) sage: pid(x) = diff(pi(x),x); sage: P(x) = sum(pi(x)/(x-i)/pid(i)*j for (i,j) in zip(xs,ys)) sage: P(x).collect(x) x^3 - 11*x - 17
And finally, on the TI-nspire CAS calculator:
Note that all the mathematical symbols and programming constructs are available through the calculator’s menus.
Notice that this approach requires no programming with loops or conditions at all – it’s all done with simple sums and products.