Lagrange interpolation provides an explicit formula for the polynomial that exactly fits a given set of data points. If we have points , there exists a unique polynomial of degree at most such that for each . The Lagrange form expresses this polynomial as a sum of basis polynomials, each weighted by a data value.
This calculator allows you to input any number of points and automatically constructs the interpolating polynomial. It also evaluates the polynomial at a specified -value, making it useful for estimating intermediate values or understanding the shape of the fitted curve.
The polynomial is written as , where each basis function is defined as . Each equals one at and zero at all other data abscissas, ensuring passes through all points. Because the formula uses only ratios of differences, it can be evaluated directly without solving linear systems.
In practice, building the basis polynomials from scratch for each evaluation can be computationally intense for many points. However, for small data sets typically encountered in educational settings, the explicit formula provides clarity and simplicity.
Interpolation appears whenever we wish to estimate values of a function between known samples. In physics, experimental measurements at discrete settings may require interpolation to compare with theory. In computer graphics, interpolation generates smooth curves and surfaces through control points. In numerical methods, Lagrange interpolation underlies polynomial integration rules and spectral methods for solving differential equations.
While polynomial interpolation can oscillate wildly for large numbers of points—a phenomenon known as Runge's phenomenon—using a moderate number of well-chosen points often yields excellent approximations. The Lagrange form is particularly transparent, making it an ideal teaching tool.
Enter points one per line in the format x,y
. For example, entering 0,1
and 1,3
specifies the points (0,1) and (1,3). The order does not matter. After entering all points, specify the -value where you want the polynomial evaluated. Press "Interpolate" to see both the symbolic expression and the computed value.
The script parses the points, constructs the basis polynomials symbolically using math.js
, and combines them to produce . It simplifies the result when possible and evaluates the polynomial at the desired . Errors are displayed if the input cannot be parsed or if duplicate -values appear.
Suppose we have points (0,1), (1,2), and (2,0). The Lagrange polynomial becomes . Simplifying yields . Evaluating at gives . The calculator performs these steps automatically.
Joseph-Louis Lagrange formulated this interpolation method in the eighteenth century while studying celestial mechanics. Though simpler approaches like Newton's divided differences often prove more efficient for large data sets, the Lagrange form elegantly demonstrates the existence of the interpolating polynomial. It remains a cornerstone of numerical analysis education and provides insight into polynomial approximation theory.
Because the polynomial grows in degree as the number of points increases, errors can amplify rapidly outside the range of the data. Interpolation is safest within the convex hull of the points. Additionally, rounding errors may become significant when points are closely spaced. For large data sets, piecewise methods like splines or specialized algorithms like barycentric interpolation offer improved stability.
Try adding more points or evaluating the polynomial at different values to see how the interpolant behaves. Notice how the basis polynomials each contribute a single "bump" centered on one data point. By visualizing these contributions, you gain intuition about how polynomial curves weave through the data. The Lagrange approach also extends to higher dimensions and serves as a stepping stone to finite element methods and other powerful techniques.
In summary, Lagrange interpolation provides a direct path from discrete samples to a smooth polynomial curve. This calculator makes the process interactive and accessible, encouraging experimentation and deeper understanding of approximation theory.
Calculate Bessel functions of the first kind for integer orders using a series expansion.
Compute the matrix exponential of a 2x2 matrix using a power series.
Compute Möbius transformations of complex numbers.