1) What interpolation guarantees
-
If all \(x_i\) are distinct, there exists exactly one polynomial \(p(x)\) with \(\deg(p)\le n-1\)
such that \(p(x_i)=y_i\) for every \(i\).
-
With many points over a wide interval, the interpolant can oscillate (Runge-type behavior). This is a
property of interpolation, not a “bug”.
2) Lagrange form
Lagrange interpolation writes \(p(x)\) as a sum of basis polynomials \(L_i(x)\) that “pick out” one data point:
\[
p(x)=\sum_{i=0}^{n-1} y_i\,L_i(x),
\qquad
L_i(x)=\prod_{\substack{j=0\\ j\ne i}}^{n-1}\frac{x-x_j}{x_i-x_j}.
\]
Each basis satisfies \(L_i(x_i)=1\) and \(L_i(x_j)=0\) for \(j\ne i\). It’s conceptually clear, but expanding
the product can get large for many points.
3) Newton divided differences
Newton’s form builds the polynomial incrementally, which is convenient if you add points one by one:
\[
p(x)=a_0 + a_1(x-x_0) + a_2(x-x_0)(x-x_1) + \cdots + a_{n-1}\prod_{k=0}^{n-2}(x-x_k).
\]
The coefficients \(a_k\) are the divided differences:
\[
a_0=f[x_0]=y_0,\quad
a_1=f[x_0,x_1],\quad
a_2=f[x_0,x_1,x_2],\ \dots
\]
Divided differences can be computed in a triangular table. This form is efficient and numerically stable for
moderate \(n\).
4) Barycentric form (stable evaluation)
For plotting and fast evaluation, barycentric interpolation is typically more stable than expanding a large polynomial:
\[
p(x)=\frac{\sum_{i=0}^{n-1}\frac{w_i\,y_i}{x-x_i}}{\sum_{i=0}^{n-1}\frac{w_i}{x-x_i}},
\qquad
w_i=\frac{1}{\prod_{\substack{j=0\\ j\ne i}}^{n-1}(x_i-x_j)}.
\]
The calculator can compute these weights and use them for evaluation (while still exporting a simplified polynomial when possible).
5) Error and “how good is it?”
If the underlying function \(f\) is \(n\)-times differentiable on an interval containing the nodes, the interpolation error at a point \(x\)
can be written as:
\[
f(x)-p(x)=\frac{f^{(n)}(\xi)}{n!}\prod_{i=0}^{n-1}(x-x_i),
\quad \text{for some } \xi \text{ between the smallest and largest node.}
\]
- The product \(\prod (x-x_i)\) grows quickly outside the data range, so extrapolation can be unreliable.
- Even inside the range, many equally-spaced points can amplify oscillations; node choice matters.
- If you have an extra “check” point, you can estimate error by comparing the interpolant to that point’s value.
6) Choosing nodes: why Chebyshev points help
A classic way to reduce oscillations on \([-1,1]\) is to use Chebyshev-like nodes (clustered near endpoints):
\[
x_k=\cos\!\left(\frac{(2k+1)\pi}{2n}\right),\quad k=0,1,\dots,n-1.
\]
You don’t always control the nodes (real data), but this explains why “smart spacing” can beat uniform spacing.
7) What the calculator does
- Checks that all \(x_i\) are distinct (duplicate \(x\) values would make the formulas invalid).
- Builds \(p(x)\) using the selected method (Lagrange or Newton) and simplifies the expression when feasible.
- Plots the data points and the interpolating curve; the curve must pass through every input point.
- Can evaluate \(p(x_0)\) at a chosen probe value and show residuals if you supply a comparison value.
Tip: If the graph looks “wild”, try fewer points, a smaller \(x\)-window, or rescale \(x\) (e.g., map your data to \([-1,1]\)).