Numerical MethodsUnit 313 min read

Interpolation & Curve Fitting: Methods, Errors & Applications

Unit 3 of Numerical Methods covers polynomial interpolation (Lagrange, Newton), spline methods, curve fitting (least squares), error analysis, and real-world applications in engineering. Learn how to approximate functions, fit data, and solve practical problems like traffic flow modeling or sensor calibration.

TAKEAWAYS:

  • Interpolation approximates unknown values between known data points using polynomials (Lagrange, Newton) or splines.
  • Curve fitting minimizes error between data and a model (linear, polynomial, exponential) via least squares.
  • Error analysis compares exact vs. approximate solutions (truncation, rounding errors).
  • Spline methods (cubic, B-splines) balance smoothness and accuracy for complex datasets.
  • Real-world uses: Traffic route optimization (NTC), sensor calibration (industrial IoT), and financial forecasting (NEPSE).
  • Exam focus: Derive formulas, compute interpolants, and compare methods for given data.

1. Introduction: Why Interpolate?

Interpolation estimates values between known data points. For example:

  • Traffic engineers predict vehicle speeds at unmeasured times using speed vs. time data.
  • Finance apps (e.g., NEPSE) estimate stock prices between recorded trades.
  • Medical devices (e.g., ECG sensors) reconstruct heartbeats from sampled signals.

Key Idea: Given points , find a function such that .



2. Polynomial Interpolation Methods

A. Lagrange Interpolation

Definition: Constructs a polynomial of degree passing through all points:

Worked Example 1: Find displacement at s and s for the table:

(s) 0.0 0.5 1.0 1.5 2.0
(cm) 0.0 1.2 2.8 4.8 7.2

Steps:

  1. Lagrange Basis Polynomials: For , compute and sum:
  2. Calculate :
    • Similarly compute others (use a calculator for precision).
  3. Sum: Repeat for : cm (exact, since is a data point).

Visualization:

Advantages:

  • Exact for given data points.
  • Simple to derive for small .

Disadvantages:

  • High-degree polynomials oscillate (Runge’s phenomenon).
  • Computationally expensive for large .

B. Newton’s Divided Differences

Definition: Uses divided differences to build a polynomial incrementally: where are divided differences.

Worked Example 2: Recompute using Newton’s method.

Steps:

  1. Divided Differences Table:

    0.0 0.0
    0.5 1.2 2.4
    1.0 2.8 3.2 1.6
    1.5 4.8 4.8 3.2 3.2
    2.0 7.2 4.8 4.8 3.2
  2. Polynomial:

  3. Evaluate at : Substitute and compute (use Horner’s method for efficiency):

Advantages:

  • Efficient for adding new data points (incremental).
  • Avoids recomputing the entire polynomial.

Disadvantages:

  • Still suffers from high-degree oscillations.


3. Error Analysis

Interpolation Error: For a function , the error is: Key Insight: Error depends on:

  1. The derivative (higher derivatives = larger error).
  2. The spacing of (uneven spacing increases error).

Example: For interpolated at , the error at is: Since , .



4. Spline Interpolation

Problem: Polynomial interpolation fails for large due to oscillations. Solution: Use piecewise polynomials (splines).

A. Cubic Splines

Definition: A piecewise cubic polynomial where:

  1. for all .
  2. and are continuous.
  3. on each subinterval .

Natural Spline: .

Worked Example 3: Fit a cubic spline to the displacement data.

Steps:

  1. Set up equations for continuity and smoothness:
  2. Boundary conditions:
    • , .
  3. Solve for coefficients (use matrix methods or software).

Advantages:

  • Smoother than high-degree polynomials.
  • Local control (changing one point only affects nearby segments).

Disadvantages:

  • More complex to compute than Lagrange/Newton.


5. Curve Fitting (Least Squares)

Problem: Data has noise; interpolation overfits. Solution: Find a function that minimizes the sum of squared errors:

A. Linear Least Squares

For , solve:

Worked Example 4: Fit a line to noisy displacement data:

(s) 0.0 0.5 1.0 1.5 2.0
(cm) 0.0 1.1 2.9 4.7 7.0

Steps:

  1. Compute sums:
  2. Solve: So, .

Visualization:

Advantages:

  • Robust to noise.
  • Works for linear/nonlinear models.

Disadvantages:

  • No guarantee of passing through any data point.

B. Polynomial Least Squares

Extend to higher-degree polynomials by solving a normal equations system: where is the Vandermonde matrix.



6. Applications in Engineering

A. Traffic Flow Modeling (NTC)

Problem: Predict vehicle speeds at unmeasured times using speed vs. time data. Method: Cubic splines to smooth speed profiles and avoid oscillations. Example: Given speeds at minutes, fit a spline to estimate speed at minutes.

B. Sensor Calibration (Industrial IoT)

Problem: Calibrate a temperature sensor using known reference points. Method: Polynomial interpolation to map sensor readings to true temperatures. Example: A sensor reads 100, 200, 300 at true temps 20°C, 40°C, 60°C. Interpolate for a reading of 150.

C. Financial Forecasting (NEPSE)

Problem: Estimate stock prices between trading hours. Method: Least squares to fit a trend line to historical closing prices. Example: Fit a line to NEPSE index values at 10 AM, 2 PM, and 4 PM to predict the 1 PM value.



7. Choosing the Right Method

Method Best For Avoid When Error Behavior
Lagrange Small datasets, exact fit needed Large (oscillations) High for uneven spacing
Newton Incremental updates, dynamic data High-degree polynomials Same as Lagrange
Splines Smooth data, large datasets Need exact fit at all points Localized error
Least Squares Noisy data, approximate fit Exact interpolation needed Robust to outliers

8. Exam Tips

  1. Derive Formulas: For Lagrange/Newton, show the general form and steps to compute coefficients.
  2. Error Analysis: Always state the error formula .
  3. Compare Methods: For a given dataset, justify why splines or least squares are better than polynomials.
  4. Numerical Stability: Avoid high-degree polynomials; prefer splines or low-degree fits.
  5. Real-World Context: Relate problems to traffic, finance, or sensor data (e.g., "Predict NEPSE index at 1 PM using least squares").
  6. Graphs: Always sketch the data points and interpolant/curve fit in your answer.

Common Pitfalls:

  • Forgetting to check for oscillations (Runge’s phenomenon).
  • Misapplying boundary conditions in splines.
  • Ignoring error bounds in interpolation.

In the Real World

  1. eSewa/Khalti (Digital Payments):

    • Idea Used: Least Squares Curve Fitting
    • How: eSewa’s fraud detection models fit transaction patterns to a curve (e.g., linear or polynomial) to flag anomalies. For example, if a user’s spending jumps from ₹500/day to ₹5000/day, a least-squares fit to their historical data would show this as a 3σ outlier.
  2. Pathao (Ride-Hailing):

    • Idea Used: Spline Interpolation
    • How: Pathao’s dynamic pricing algorithm uses cubic splines to estimate demand between pickup locations. For instance, if demand is known at 3 locations (A, B, C) along a route, splines smooth the demand curve to predict prices at intermediate points (e.g., between A and B).
  3. NTC (Traffic Management):

    • Idea Used: Polynomial Interpolation + Least Squares
    • How: NTC uses Lagrange interpolation to estimate traffic flow at unmonitored intersections based on sensor data from nearby points. For example, if traffic volume is recorded at 8 AM, 10 AM, and 12 PM, they interpolate the 9 AM volume. Least squares refines this by fitting a trend line to noisy sensor data over weeks.
  4. NEPSE (Stock Exchange):

    • Idea Used: Newton’s Divided Differences
    • How: Analysts use Newton’s interpolation to estimate intra-day stock prices. For example, if NEPSE’s index is recorded at 10 AM (1200), 12 PM (1210), and 2 PM (1230), they compute the polynomial to predict the 11 AM value. This helps traders make split-second decisions.
  5. Bank Loan Interest Calculation (Nabil, Global IME):

    • Idea Used: Polynomial Curve Fitting
    • How: Banks use least-squares polynomial fits to model interest rate trends. For example, if historical interest rates for 1-year loans are known at 5%, 6%, and 7% for years 2020, 2021, and 2022, they fit a quadratic curve to predict the 2023 rate. This helps in setting competitive loan rates.

Worked Example Tied to Real Life

Problem: A Daraz delivery driver records the distance covered (in km) at hourly intervals during a route. Use Newton’s divided differences to estimate the distance covered at t=2.4 hours.

Time (hours) 0.0 1.0 2.0 3.0 4.0
Distance (km) 0.0 5.2 9.8 14.1 18.7

Solution:

  1. Divided Differences Table:

    t f(t) f[·,t] f[·,·,t] f[·,·,·,t] f[·,·,·,·,t]
    0.0 0.0
    1.0 5.2 5.2
    2.0 9.8 4.6 -0.6
    3.0 14.1 4.3 0.1 0.7
    4.0 18.7 4.6 0.3 0.2 -0.5
  2. Newton Polynomial:

  3. Evaluate at t=2.4: Interpretation: The driver has covered approximately 12.8 km after 2.4 hours.

Visualization:

Based on the PU BE Computer (PU) syllabus for Numerical Methods, unit 3.

Discussion

Loading…