Quadratic interpolator help


The interpolator is implemented in JavaScript running in your browser and so it will not work unless you have JavaScript enabled, as most people do.

The x input values must be unique and the y values must be unique; the same number cannot appear twice in the x column or twice in the y column.

Exactly one box must be empty before clicking the Calculate button.

Interpolation derivation

The quadratic polynomial P(x) fitting three points (x0, y0), (x1, y1), and (x2, y2) is given by

y=\frac{(x - x_1)(x - x_2)}{(x_0 - x_1)(x_0 - x_2)}y_0 + \frac{(x - x_0)(x - x_2)}{(x_1 - x_0)(x_1 - x_2)}y_1 + \frac{(x - x_0)(x - x_1)}{(x_2 - x_0)(x_2 - x_1)}y_2

This is the "Lagrange form" of the interpolator. It's easy to verify that P(xi) = yi. If four x values and three y values are given, the equation above is used to predict the missing y value.

Inverse interpolation

If four y values and three x values are given, the interpolator reverses the role of x and y in the formula above. That is, it treats the y's as inputs and the x's as output. It fits a quadratic polynomial P(y) so that P(yi) = xi and uses that polynomial to predict the missing x value.

Note what inverse interpolation does not do. When solving for a missing x, it does not fit a quadratic polynomial P(x) and then solve for x. Such a process would likely be unstable. If you do want to solve for an x value this way, you are doing root-finding, not interpolation. In that case, you can use the formula above in combination with the quadratic formula.

This means that code in this page does not necessarily perform "round trips." That is if you solve for a missing y value, then erase the corresponding x and solve for it, you might not get back the x you started with.

Interpolation vs regression

Interpolation can be very useful in very clean situations. But if there is any uncertainty or noise in the data, you probably want to use statistical regression rather than interpolation. Quadratic interpolation can magnify the effect of noise. If you would like to do more with data analysis, we would be glad to help.

John D. Cook photo