Lagrange Interpolation Calculator

Use this Lagrange Interpolation Calculator to enter values, adjust options, and review results in a compact responsive workspace.

Results are calculated automatically as you enter data.

Points as x,y pairs
Point X Y

Interpolation graph

Drag a point to update the polynomial in real time.

Polynomial and prediction

Polynomial -
Predicted y at x -
Maximum degree -
Stability -

Construction steps

Each basis polynomial is expanded and added to the final curve.

▼ See explanations and tips below ▼

What Is Lagrange Polynomial Interpolation?

Lagrange polynomial interpolation is a way to build a polynomial from known coordinate points. If you have \(n+1\) points,

$$ (x_0,y_0), (x_1,y_1), \ldots, (x_n,y_n) $$

and every \(x\)-value is different, Lagrange interpolation creates one polynomial \(P(x)\) of degree at most \(n\) that passes through all of them:

$$ P(x_i)=y_i \quad \text{for every } i=0,1,\ldots,n $$

The purpose is not to find a trend line or a smoothed curve. The purpose is to find the exact polynomial curve that matches the supplied points. Once that polynomial is known, you can evaluate it at another \(x\)-value to estimate or verify a corresponding \(y\)-value.

Interpolation is usually most meaningful between the smallest and largest known \(x\)-values. Evaluating the polynomial outside that range is extrapolation, which can be much less reliable even when the polynomial exactly matches every entered point.


Why Lagrange Interpolation Matters

Lagrange interpolation is useful because it gives a direct formula for the interpolating polynomial without first solving a full system of equations. It works with unevenly spaced \(x\)-values, which makes it more flexible than formulas that assume equal spacing.

Students often use it to understand polynomial interpolation, basis polynomials, and the idea of a curve being forced through known data points. Technical users may use it to reconstruct a simple polynomial model from sample values, test numerical methods, compare interpolation methods, or visualize how a polynomial behaves between points.

It is also a helpful reminder that “passing through every point” is not always the same as “making the best prediction.” A high-degree interpolating polynomial can oscillate strongly between points, especially when many equally spaced points are used.


Key Terms to Know

  • Point or node: A known coordinate pair \((x_i,y_i)\) used to build the interpolation polynomial.
  • Distinct \(x\)-values: Each input \(x_i\) must be unique. If two points have the same \(x\) but different \(y\)-values, they do not define an ordinary function value at that \(x\).
  • Lagrange basis polynomial: A special polynomial \(L_i(x)\) that equals \(1\) at its own node \(x_i\) and \(0\) at the other input nodes.
  • Interpolating polynomial: The final polynomial \(P(x)\) formed by combining all basis polynomials.
  • Degree: The highest power of \(x\) with a nonzero coefficient after the polynomial is simplified.
  • Interpolation: Estimating a value within the range of known \(x\)-values.
  • Extrapolation: Estimating a value outside the range of known \(x\)-values.
  • Barycentric form: A numerically efficient way to evaluate the same interpolating polynomial.
  • Numerical conditioning: How sensitive a calculation is to small changes or rounding errors in the input values.

How Lagrange Interpolation Works

Lagrange interpolation starts by building one basis polynomial for each input point. For the point \((x_i,y_i)\), the basis polynomial is

$$ L_i(x)=\prod_{\substack{j=0\\j\ne i}}^n \frac{x-x_j}{x_i-x_j} $$

This formula is designed so that \(L_i(x_i)=1\). At every other input node \(x_j\), one factor in the numerator becomes \(0\), so \(L_i(x_j)=0\) when \(j\ne i\).

The interpolating polynomial is then the weighted sum of the basis polynomials:

$$ P(x)=\sum_{i=0}^{n} y_iL_i(x) $$

Each \(y_i\) scales its own basis polynomial. When \(x=x_i\), all the other basis terms become \(0\), while \(L_i(x_i)=1\), so the final result is \(P(x_i)=y_i\).

For numerical evaluation, the same polynomial can be written in barycentric form. One common version uses weights

$$ w_i=\frac{1}{\displaystyle\prod_{\substack{j=0\\j\ne i}}^n(x_i-x_j)} $$

and evaluates, for \(x\) not equal to one of the input nodes,

$$ P(x)=\frac{\displaystyle\sum_{i=0}^{n}\frac{w_i y_i}{x-x_i}}{\displaystyle\sum_{i=0}^{n}\frac{w_i}{x-x_i}} $$

When the evaluation value \(x\) is exactly one of the input \(x_i\) values, the interpolated value should be the matching \(y_i\) value. Returning that value directly also avoids division by zero in the barycentric expression. A nearby value is still a different input and should be evaluated normally; display rounding is not a reason to merge two distinct nodes.


Examples of Lagrange Interpolation in Practice

Example 1: Two Points Produce a Line

Suppose the known points are \((0,2)\) and \((3,8)\). With two points, the interpolating polynomial has degree at most \(1\), so it is a line.

The basis polynomials are

$$ L_0(x)=\frac{x-3}{0-3}=\frac{3-x}{3} $$

and

$$ L_1(x)=\frac{x-0}{3-0}=\frac{x}{3} $$

So the interpolating polynomial is

$$ P(x)=2\left(\frac{3-x}{3}\right)+8\left(\frac{x}{3}\right) $$

Simplifying gives

$$ P(x)=2+2x $$

At \(x=1.5\),

$$ P(1.5)=2+2(1.5)=5 $$

Example 2: A Simple Quadratic

Suppose the known points are \((-1,2)\), \((0,1)\), and \((1,2)\). These points form a symmetric quadratic curve.

The basis polynomials are

$$ L_0(x)=\frac{x(x-1)}{2} $$
$$ L_1(x)=1-x^2 $$
$$ L_2(x)=\frac{x(x+1)}{2} $$

The interpolating polynomial is

$$ P(x)=2L_0(x)+1L_1(x)+2L_2(x) $$

Substituting the basis polynomials gives

$$ P(x)=2\left(\frac{x(x-1)}{2}\right)+(1-x^2)+2\left(\frac{x(x+1)}{2}\right) $$

After simplifying,

$$ P(x)=x^2+1 $$

At \(x=0.5\),

$$ P(0.5)=(0.5)^2+1=1.25 $$

Example 3: A Duplicate \(x\)-Value Problem

Now suppose the points include \((1,2)\) and \((1,5)\). Ordinary polynomial interpolation cannot treat these as two different function values at the same \(x\).

The Lagrange formula would also create a zero denominator because it contains terms like

$$ x_i-x_j $$

If \(x_i=x_j\), that difference is \(0\). For standard Lagrange interpolation, repeated \(x\)-values are undefined unless a different method, such as Hermite interpolation with derivative information, is being used.


How to Interpret the Result

The polynomial \(P(x)\) is the expanded polynomial that passes through the entered points, assuming the \(x\)-values are unique and the input values are valid. The coefficients are determined entirely by the points you enter.

The prediction result is the value of \(P(x)\) at the selected prediction \(x\)-value. Its unit is the same as the \(y\)-values, while the prediction input uses the same unit as the \(x\)-values.

The degree tells you the highest effective power of \(x\) in the displayed polynomial. With \(n+1\) points, the degree is at most \(n\), but it can be lower if leading terms cancel. For example, five points that all lie on \(y=x^2+1\) still describe a degree-\(2\) polynomial, not a degree-\(4\) polynomial.

The basis steps show how each point contributes to the final polynomial. A basis term itself is a dimensionless ratio, but after it is multiplied by \(y_i\), its contribution has the same unit as the \(y\)-values.

The comparison table should show each entered point matching the calculated value \(P(x)\), with deltas near zero after rounding. Small nonzero deltas usually reflect numeric rounding rather than a different mathematical curve.

A stability message of “Good” means the calculator did not detect one of its coded warning conditions. It does not mean the interpolation is guaranteed to be accurate for every purpose, especially for many points, very close \(x\)-values, very wide \(x\)-ranges, or extrapolated predictions.

The graph is a visual aid. It helps you see the curve, the entered points, and the prediction behavior, but it is not a proof that the interpolation is reliable outside the known data range.


Common Mistakes and Misconceptions

  • Using duplicate \(x\)-values: Standard Lagrange interpolation requires every \(x_i\) to be distinct.
  • Using only one point: One point is not enough to define an interpolation curve in this calculator. At least two valid points are needed.
  • Confusing interpolation with regression: Interpolation forces the curve through all points. Regression or least-squares fitting finds a curve that summarizes the data and usually does not pass through every point.
  • Assuming more points always improves the result: More points can create a higher-degree polynomial, and high-degree interpolation can oscillate significantly.
  • Rounding too early: Rounded coefficients can make a polynomial look simpler or less accurate than the full internal calculation.
  • Ignoring scale: Very close \(x\)-values or very wide \(x\)-ranges can amplify numerical error. Rescaling the data can sometimes make numerical work better conditioned.
  • Treating extrapolation like interpolation: A value outside the input \(x\)-range may look reasonable on the graph but can be highly sensitive to the polynomial’s end behavior.
  • Importing multiple pairs on one line: Imported point data must have one \(x,y\) pair on each nonempty line. Rows with missing values or extra columns are rejected, so correct the pasted data rather than expecting fields to be silently discarded.

When to Use Lagrange Interpolation

Use Lagrange interpolation when you need a polynomial that passes exactly through known points and the \(x\)-values are distinct.

It is especially useful for:

  • Learning how polynomial interpolation works.
  • Building an exact interpolating polynomial from a small set of points.
  • Evaluating a polynomial at an \(x\)-value between known points.
  • Checking whether points lie on a simple polynomial curve.
  • Comparing Lagrange interpolation with Newton interpolation, splines, or regression.
  • Visualizing how point placement affects a polynomial curve.

For noisy real-world data, regression, smoothing, or spline methods may be more appropriate than a single polynomial forced through every point.


Limitations and Things to Keep in Mind

Lagrange interpolation is mathematically exact when the input values are exact and the \(x\)-values are distinct. A calculator, however, works with finite decimal numbers and floating-point arithmetic, so displayed results can include rounding effects.

This calculator displays most numeric outputs to a limited number of decimal places, treats extremely small values as zero, omits polynomial terms whose coefficients are very close to zero, and trims near-zero leading coefficients when reporting degree. These choices make the output easier to read, but they also mean the displayed polynomial may be a rounded version of the internal calculation.

Duplicate \(x\)-values are not supported. Fewer than two valid points cannot produce an interpolation result. Decimal and negative values are supported, but symbolic expressions, exact fractions, \(\text{NaN}\), and infinity are not active coordinate values.

Large point sets can be numerically delicate. The calculator warns when more than \(8\) points are used, when adjacent sorted \(x\)-values are closer than \(10^{-4}\), or when the rendered \(x\)-range is very wide. These warnings point to possible numerical instability, not necessarily an input error.

The graph’s viewing range may be adjusted to include the points and sampled curve values. The curve sample count affects graph smoothness and is limited to a supported range, so the graph is an approximation of the drawn curve rather than a separate mathematical result.

This method is not Hermite interpolation, cubic spline interpolation, least-squares regression, or a smoothing method. It does not use derivative constraints and does not choose a best-fit curve.

The calculator may evaluate a prediction outside the entered point range, but that is extrapolation. For important decisions involving engineering, safety, finance, scientific reporting, legal obligations, or official records, double-check the result and use an appropriate professional method or review process.


How to Use This Calculator

  1. Enter at least two valid \(x\)-\(y\) point pairs, or import point pairs with one pair per line.
  2. Add or delete point rows to choose the set of points included in the interpolation.
  3. Adjust the graph bounds if you need a different viewing window.
  4. Enter the prediction \(x\)-value where you want \(P(x)\) evaluated.
  5. Adjust the curve sample count if you want a smoother or simpler graph within the supported range.
  6. Use an example preset if you want to start from a sample quadratic, cubic, or oscillating point set.
  7. Review the polynomial, prediction, degree, stability message, basis steps, comparison table, and graph.
  8. Copy the polynomial or prediction when needed, or download the graph image for reference.

Frequently Asked Questions

How many points are needed for Lagrange interpolation?

At least two valid points are needed in this calculator. Two points produce a line, three points can produce a quadratic, and \(n+1\) points produce a polynomial of degree at most \(n\).


Why do the \(x\)-values have to be unique?

The formula divides by differences such as \(x_i-x_j\). If two \(x\)-values are the same, the denominator becomes zero. Also, a standard function cannot assign two different \(y\)-values to the same \(x\)-value.


Is the displayed polynomial exact?

The mathematical interpolating polynomial is exact for exact input data. The displayed calculator result is rounded and based on floating-point arithmetic, so very small numerical differences or simplified-looking coefficients may appear.


Why is the degree lower than the number of points minus one?

The maximum degree for \(n+1\) points is \(n\), but the actual simplified polynomial can have a lower degree. This happens when the points lie on a lower-degree polynomial or when leading coefficients cancel to near zero.


Is Lagrange interpolation the same as regression?

No. Lagrange interpolation passes through every entered point. Regression or least-squares fitting usually looks for a curve that minimizes overall error and may not pass exactly through any particular point.


Why can many points make interpolation unstable?

A larger point set can produce a high-degree polynomial. High-degree polynomial interpolation can be sensitive to rounding, point spacing, and endpoint behavior, and it may oscillate between points.


Can I use the prediction outside the known \(x\)-range?

You can evaluate the polynomial outside the point range, but that is extrapolation. Extrapolated values can change dramatically with small changes in the input points, so they should be interpreted carefully.


Sources and References

Books and Open Textbooks

  1. Tobin A. Driscoll and Richard J. Braun. Fundamentals of Numerical Computation: Julia Edition. Society for Industrial and Applied Mathematics, 2022. Sections 9.1 “Polynomial interpolation,” 9.2 “The barycentric formula,” and 9.3 “Stability of polynomial interpolation.” Polynomial interpolation, barycentric formula, and stability section. Accessed June 29, 2026.
  2. Jeffrey R. Chasnov. Numerical Methods. LibreTexts / Hong Kong University of Science and Technology source content. Section 5.1 “Polynomial Interpolation.” LibreTexts edition. Accessed June 29, 2026.
  3. Qingkai Kong, Timmy Siauw, and Alexandre M. Bayen. Python Programming and Numerical Methods: A Guide for Engineers and Scientists. Elsevier / Academic Press, 2021. Chapter 17.4 “Lagrange Polynomial Interpolation.” Online companion chapter. Accessed June 29, 2026.

Online and Journal Sources

  1. Eric W. Weisstein and Branden Archer. “Lagrange Interpolating Polynomial.” MathWorld—A Wolfram Resource. MathWorld page. Accessed June 29, 2026.
  2. Nicholas J. Higham. “The Numerical Stability of Barycentric Lagrange Interpolation.” IMA Journal of Numerical Analysis, vol. 24, no. 4, 2004, pp. 547–556. DOI: 10.1093/imanum/24.4.547. University of Manchester Research Explorer summary. Accessed June 29, 2026.