Lagrange Interpolation Calculator

JJ Ben-Joseph headshot JJ Ben-Joseph

What this Lagrange Interpolation Calculator does

This calculator constructs the unique polynomial that passes exactly through a set of data points using the Lagrange interpolation formula. You enter sample points (x, y), choose a value of x, and the tool:

This is useful in numerical methods, physics and engineering labs, computer graphics, and for learning how polynomial interpolation works in practice.

Reminder: what Lagrange interpolation is

Suppose you have n + 1 distinct data points (x0,y0),(x1,y1),,(xn,yn). There exists a unique polynomial P(x) of degree at most n such that:

P(x_i) = y_i for every index i = 0, 1, …, n.

Lagrange interpolation expresses this polynomial as a sum of Lagrange basis polynomials that are constructed directly from the x-values of your data. Each basis polynomial is equal to 1 at one data point and 0 at all the others, so their weighted sum reproduces all the y-values exactly.

Lagrange interpolation formulas

The interpolating polynomial is written as

P(x) = ∑i=0n yi Li(x),

where the Lagrange basis polynomials are

Li(x) = ∏j=0, j ≠ in (x − xj)/(xi − xj).

Each Li(x) satisfies Li(xi) = 1 and Li(xk) = 0 for all k ≠ i, so the sum P(x) = ∑ yiLi(x) passes exactly through all points.

The same idea in MathML form is:

P (x) = i=0 n yi Li (x) Li (x) = j=0 n , ji xxj xixj

The calculator implements these products numerically. For a moderate number of points this is efficient and avoids solving a separate linear system for the coefficients.

How to enter data into the calculator

To use the Lagrange interpolation calculator effectively, follow these steps:

  1. List your data points.
    • Enter one point per line in the format x,y.
    • You may use integers or decimals (for example 0,1, 1.5,2.75).
    • The x-values must all be distinct (no duplicates).
  2. Choose an evaluation x-value.
    • Enter the value of x where you want to evaluate the interpolating polynomial.
    • This can be inside the range of your data (interpolation) or outside (extrapolation), but see the limitations below.
  3. Click the Interpolate button.
    • The script parses your points and constructs the Lagrange basis polynomials.
    • It forms P(x) = ∑ yiLi(x) and evaluates it at the chosen x.
    • If any point is invalid or there are duplicate x-values, an error message is shown instead of a result.

For numerical stability and interpretability, many practical problems work well with between 3 and 10 points. Very high-degree interpolating polynomials can behave unpredictably.

Interpreting the results

After running the calculator, you will typically see:

You can check consistency in several ways:

Worked example

Consider three data points:

We want the polynomial P(x) of degree at most 2 that passes through all three points, and we will evaluate it at x = 0.5.

Step 1: Enter the data

In the data points field, type:

0,1
1,2
2,0
  

Then set the evaluation x-value to 0.5 and click Interpolate.

Step 2: Form the Lagrange basis polynomials

For three points we have indices i = 0, 1, 2:

The polynomial is then

P(x) = 1 × L0(x) + 2 × L1(x) + 0 × L2(x).

Substituting the expressions for L0 and L1 and simplifying gives:

P(x) = -½x2 + &frac32;x + 1.

Step 3: Evaluate at x = 0.5

Now compute:

P(0.5) = -½(0.5)2 + &frac32;(0.5) + 1 = -0.125 + 0.75 + 1 = 1.625.

The calculator will display this value as the interpolated result at x = 0.5. It will also show the symbolic polynomial, which you can compare with the analytic expression above.

When to use Lagrange interpolation vs. other approaches

Lagrange interpolation is one of several ways to construct a curve through data points. The table below contrasts it with a few common alternatives at a high level.

Method Main idea Typical use cases Key advantages Main limitations
Lagrange interpolation Single global polynomial passes exactly through all points. Small data sets; teaching polynomial interpolation; analytical work. Explicit formula; no need to solve linear systems; easy to evaluate for moderate n. Can oscillate for many points; extrapolation can be unstable.
Newton interpolation Builds polynomial using divided differences in an incremental form. When points are added one at a time; numerical algorithms courses. Efficient updates for new points; good for stepwise computation. Still a single high-degree polynomial; similar instability for large n.
Piecewise linear interpolation Connects consecutive data points with straight line segments. Simple approximations; quick visualizations; monotone data. Very easy to implement; no overshoot between points. Not smooth at data points; no single global formula.
Cubic splines Piecewise cubic polynomials joined with smoothness conditions. Engineering and graphics; smooth curve fitting for many points. Smooth, well-behaved curves; less oscillation than high-degree polynomials. Requires solving a system; more complex than Lagrange form.

This calculator focuses specifically on the Lagrange form, which is especially suitable for education, small sets of experimental data, and situations where you want a clear analytical expression for the interpolating polynomial.

Assumptions, limitations, and good practices

The Lagrange interpolation implemented here rests on several important assumptions:

Keep these practical limitations in mind:

Some guidelines for using this calculator responsibly:

Typical application scenarios

This Lagrange interpolation calculator can support a range of tasks:

By understanding both the capabilities and the limitations described above, you can use the Lagrange Interpolation Calculator as a precise and insightful tool for fitting polynomials to data points.

Enter one point per line, such as 0,1 or 1.5,2.

Enter points and value.

Embed this calculator

Copy and paste the HTML below to add the Lagrange Interpolation Calculator - Fit Polynomials to Data Points to your website.