Lagrange Interpolation Calculator
Enter points and value.

Purpose of Lagrange Interpolation

Lagrange interpolation provides an explicit formula for the polynomial that exactly fits a given set of data points. If we have n points (x0,y0), \ldots, (xn,yn), there exists a unique polynomial P of degree at most n such that Pxi=yi for each i. 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 x-value, making it useful for estimating intermediate values or understanding the shape of the fitted curve.

The Lagrange Formula

The polynomial is written as Px=i0nyiLix, where each basis function Li is defined as jj\ne ix-xjxi-xj. Each Li equals one at xi and zero at all other data abscissas, ensuring P 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.

Applications

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.

Using the Calculator

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 x-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 P. It simplifies the result when possible and evaluates the polynomial at the desired x. Errors are displayed if the input cannot be parsed or if duplicate x-values appear.

Example

Suppose we have points (0,1), (1,2), and (2,0). The Lagrange polynomial becomes Px=(x-1)(x-2)2+2(x-0)(x-2)-1+0(x-0)(x-1)2. Simplifying yields Px=x^2-x+1. Evaluating at x=1.5 gives 1.5^2-1.5+1=2.75. The calculator performs these steps automatically.

Historical Context

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.

Practical Considerations

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.

Exploring Further

Try adding more points or evaluating the polynomial at different x 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.

Related Calculators

Bessel Function Calculator - Evaluate J_n(x)

Calculate Bessel functions of the first kind for integer orders using a series expansion.

Bessel function calculator Jn special functions

Matrix Exponential Calculator - e^A for 2x2 matrices

Compute the matrix exponential of a 2x2 matrix using a power series.

matrix exponential calculator expm 2x2

Möbius Transformation Calculator - Explore Complex Mappings

Compute Möbius transformations of complex numbers.

Möbius transformation calculator complex analysis