Linear interpolation

Description

Given the values of a known function y=f(x)y = f(x) at a sequence of ordered points x0,x1,,xnx_0, x_1, \cdots, x_n, find f(x)f(x) for arbitrary xx. When x0xxnx_0 \le x \le x_n, the problem is called interpolation. When x<x0x \lt x_0 or x>xnx \gt x_n, the problem is called extrapolation.

The easiest way to interpolate, is connecting two points of a curve with a straight line that can be built with two points (x0,f(x0))(x_0, f(x_0)) and (x1,f(x1))(x_1, f(x_1)) and the line equation becomes:

f(x1)f(x0)x1x0=f(x)f(x0)xx0\dfrac{f(x_1) - f(x_0)}{x_1 - x_0} = \dfrac{f(x) - f(x_0)}{x - x_0} \\
f(x)=f(x0)+f(x1)f(x0)x1x0(xx0)f(x) = f(x_0) + \dfrac{f(x_1) - f(x_0)}{x_1 - x_0}(x - x_0)

Then we solve for f(x)f(x) and we can get all the values from x0x_0 to x1x_1, but if the function is not a line, an error should be introduced and if we know the real value of f(x)f(x), the percentage error is:

ep=f(xreal)f(xinterpolated)f(xreal)e_p = \dfrac{f(x_{real}) - f(x_{interpolated})}{f(x_{real})}

Calculator