ThisCalculator

Everyday

Lagrange Polynomial Interpolation Calculator

Updated · Standard formula, shown below

The calculator for this page is switched off while it is checked. The formula is below, and the worked example in the article shows how to use it by hand.

Lagrange Polynomial Interpolation Calculator

A Lagrange polynomial interpolation calculator finds the unique polynomial of degree at most n−1 that passes through n supplied data points, then evaluates it at a value you choose. Enter the x- and y-coordinates of each point and the target x-value; the result is the interpolated y-value, with the polynomial available as supporting output.

Formula

The Lagrange interpolation formula is P(x) = Σᵢ yᵢLᵢ(x), where Lᵢ(x) = Πⱼ≠ᵢ (x − xⱼ)/(xᵢ − xⱼ). In these expressions, n is the number of data points; xᵢ is the x-coordinate of point i; yᵢ is its y-coordinate; x is the input at which the polynomial is evaluated; and P(x) is the estimated output. Coordinates must use consistent units: x and xᵢ share one unit, and y and yᵢ share another. The calculator’s first output is the estimated y-value at xq. Its list inputs represent matching sequences, so the first x value pairs with the first y value, and so on.

Each basis polynomial Lᵢ equals 1 at its own data point xᵢ and 0 at all the other supplied x-coordinates. Consequently, P(xᵢ) = yᵢ for every input point. The formula needs distinct x-values; a repeated x-coordinate makes a denominator zero and does not define ordinary interpolation for conflicting or duplicate entries.

Worked Example

Use the defaults: points (0, 1), (1, 3), and (2, 2), with target xq = 1.5. The basis terms at 1.5 are:

  • L₀ = ((1.5 − 1)(1.5 − 2))/((0 − 1)(0 − 2)) = −0.125.
  • L₁ = ((1.5 − 0)(1.5 − 2))/((1 − 0)(1 − 2)) = 0.75.
  • L₂ = ((1.5 − 0)(1.5 − 1))/((2 − 0)(2 − 1)) = 0.375.

Then P(1.5) = 1(−0.125) + 3(0.75) + 2(0.375) = −0.125 + 2.25 + 0.75 = 2.875. Rounded to the calculator’s two decimal places, the displayed result is 2.88.

When to Use Lagrange Interpolation

Interpolation is useful when a measured or tabulated relationship is known at a finite set of points and an estimate is needed between them. For instance, if a table gives readings at selected times, interpolation can estimate a value at an intermediate time. It also appears in numerical analysis, data fitting demonstrations, and polynomial approximation.

This method is especially convenient when there are only a few points or when a polynomial is needed directly from the data without first solving for coefficients. The data can be irregularly spaced; x-values do not have to be evenly separated. If you need several evaluations using the same points, however, a divided-difference or barycentric implementation may be more efficient than rebuilding the direct formula each time.

How to Enter and Read the Data

  1. Put each x-coordinate in the x list and its corresponding y-coordinate in the same position in the y list.
  2. Choose a target x-value. For interpolation, it is normally between the smallest and largest supplied x-values.
  3. Read the output as the polynomial’s y-value at that target x. Preserve enough precision for later calculations; displayed rounding may hide additional digits.

Use consistent units and scales. If x is time in seconds, every x-coordinate and the target must be in seconds. The y-values can use a different unit, such as meters or degrees, but all y-values must share it. The numerical formula itself does not convert units.

Common Problems and Limits

  • Repeated x-values: The denominator xᵢ − xⱼ becomes zero. Keep only one value per x unless using a separate method designed for derivative data.
  • Mismatched lists: Each coordinate pair must correspond to the same observation. An omitted or reordered value changes the polynomial.
  • Extrapolation: A target outside the data range is extrapolation, not interpolation. The polynomial still returns a number, but that number may be a poor estimate.
  • High-degree oscillation: A polynomial through many points can swing sharply between them, especially near the ends of the interval. More points do not automatically produce a better estimate.
  • Measurement and rounding error: Interpolation passes exactly through the entered numbers, not necessarily through the true underlying relationship. Rounded or noisy inputs can affect the result, and intermediate rounding can add further error.

Lagrange interpolation is not the same as regression. Interpolation is constructed to pass through every supplied point; regression generally chooses a curve that balances errors and may not pass through any individual observation. If measurements contain substantial noise, a regression or smoothing method may be more appropriate.

Choosing a Suitable Method

For a small number of distinct points and one requested estimate, the Lagrange formula is clear and straightforward. For many points, direct evaluation can involve many products and may be numerically sensitive. Barycentric Lagrange interpolation is a commonly used computational form that represents the same interpolating polynomial while often making repeated evaluations more practical. Newton divided differences are another option, particularly when adding points incrementally or when the polynomial’s coefficients are useful.

Before relying on any result, consider whether a polynomial is a sensible model for the quantity. Physical constraints, known discontinuities, or a relationship that changes rapidly may make a single global polynomial unsuitable. A piecewise method, such as a spline, can better represent smooth local behavior while avoiding some high-degree oscillation.

Frequently Asked Questions

What does a Lagrange interpolation calculator calculate?
It constructs the unique polynomial of degree no greater than one less than the number of distinct x-values, then evaluates that polynomial at the target x-value.

Can the x-values be unevenly spaced?
Yes. Lagrange interpolation works with irregularly spaced x-values as long as no two x-values are identical.

Does the polynomial always pass through every entered point?
Yes, in exact arithmetic, provided the x-values are distinct and each x-value is paired with its correct y-value. A displayed result may be rounded, but the defining polynomial reproduces the input points.

Can I use the calculator for extrapolation?
You can evaluate the polynomial outside the supplied x-range, but that is extrapolation. The result is not guaranteed to represent the real relationship and can become inaccurate quickly.

How many points can I use?
A polynomial can be defined from any finite number of points with distinct x-values, but very large sets can be computationally awkward and produce oscillatory or unstable results. For many points, consider a piecewise interpolant or a numerically stable evaluation method.

Related

Formula used
list x | x coordinates | - | 0, 1, 2 | 0
list y | y coordinates | - | 1, 3, 2 | 0
in xq | Target x | - | 1.5
out yq | Interpolated y | - | sum(y_i * product over j != i of ((xq - x_j) / (x_i - x_j))) | 2

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.