The Lagrange polynomial of degree m is defined as:
The interpolation happens like
At the sampled points, the accuracy will be perfect. But at points inbetween, the accuracy of the constructed polynomial may suffer, especially for higher degree interpolations.
The runge phenomena is a manifesation of this innaccuracy, when we interpolate functions that grow with sucessive differentiation, we open ourselves up to this error, because the high order terms get large. This error appears at the boundrys, and it has been shown that using nodes with an asymptotic density to the boundrys, such as chebyshev nodes, will effectively solve this problem.
Chebyshev nodes can be constructed like:
for , the result is on an interval of
Here is a simple matlab function doing a lagrange interpolation for on
to
function y2 = lagrange(x,y,x2) for m=1:numel(x2) y2(m) = 0; for j=1:numel(x) l = 1; for k=1:numel(x) if k ~= j l = l*(x2(m)-x(k))/(x(j)-x(k)); end end y2(m) = y2(m) + l*y(j); end end