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:

Example Illustration

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

Derivation Illustration

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

Limitations

Table of Contents

    Linear interpolation
    1. Mathematical Formulation
    2. Derivation
    3. Algorithm Steps
    4. Example
    5. Advantages
    6. Limitations