Last modified: August 18, 2023
This article is written in: πΊπΈ
Linear interpolation
Linear interpolation is one of the most basic and commonly used interpolation methods. The idea is to approximate the value of a function between two known data points by assuming that the function behaves linearly (like a straight line) between these points. Although this assumption may be simplistic, it often provides a reasonable approximation, especially when the data points are close together or the underlying function is relatively smooth.
Conceptual Illustration:
Imagine you have two points on a graph:
Linear interpolation draws a straight line between the two known data points (xi,yi) and (xi+1,yi+1), and then estimates the value at x by following this line.
Mathematical Formulation
Given two known data points (xi,yi) and (xi+1,yi+1), and a target x-value with xiβ€xβ€xi+1, the line connecting these points has a slope Ξ± given by:
Ξ±=yi+1βyixi+1βxi.
To find the interpolated value y at x, start from yi and move along the line for the interval (xβxi):
y=yi+Ξ±(xβxi).
Substituting Ξ±:
y=yi+(xβxi)yi+1βyixi+1βxi.
This formula provides the interpolated y-value directly.
Derivation
I. Slope Calculation:
The slope Ξ± of the line passing through (xi,yi) and (xi+1,yi+1) is:
Ξ±=yi+1βyixi+1βxi.
II. Linear Equation:
A line passing through (xi,yi) with slope Ξ± is:
yβyi=Ξ±(xβxi).
III. Substitution:
Replace Ξ± with its expression:
yβyi=yi+1βyixi+1βxi(xβxi).
IV. Final Formula:
Simplifying:
y=yi+(yi+1βyi)xi+1βxi(xβxi).
Algorithm Steps
I. Identify the interval [xi,xi+1] that contains the target x.
II. Compute the slope:
yi+1βyixi+1βxi.
III. Substitute into the linear interpolation formula:
y=yi+(yi+1βyi)xi+1βxi(xβxi).
The result is the interpolated value y at the desired x.
Example
Given Points: A(β2,0) and B(2,2). Suppose we want to find y at x=1.
I. Compute the slope:
Ξ±=2β02β(β2)=24=0.5.
II. Substitute x=1:
y=0+0.5(1β(β2))=0.5Γ3=1.5.
So, the line passing through (β2,0) and (2,2) gives y=1.5 when x=1.
Advantages
- The method offers simplicity, as the calculation involves straightforward arithmetic, making it easy and quick to apply.
- Minimal data requirements make it practical, needing only two data points to estimate intermediate values.
- It provides a local approximation, working well when the function is nearly linear within the specified interval.
Limitations
- The linear assumption can lead to poor results if the actual relationship between points is not close to linear.
- Linear interpolation uses no derivative information, ignoring the slope or curvature of the function, which could enhance accuracy.
- Accuracy diminishes as the interval between points increases or as the function becomes more non-linear, leading to potential errors in approximation.