CSC212 Numerical Method

Numerical MethodUnit 58 min read

Interpolation Techniques: Lagrange, Newton, Spline & Curve Fitting

Unit 5 of Numerical Method covers interpolation fundamentals (Lagrange, Newton’s divided differences), spline methods, error analysis, and comparisons with regression—essential for approximating functions from discrete data points.

TAKEAWAYS:

  • Interpolation vs Regression: Interpolation fits exact data points (error=0 at given x), while regression minimizes overall error (approximate fit).
  • Lagrange vs Newton: Lagrange uses all points in each term; Newton builds a divided-difference table for incremental polynomial construction.
  • Spline Advantages: Piecewise polynomials (e.g., cubic splines) reduce Runge’s phenomenon and overfitting for large datasets.
  • Error Sources: Round-off errors in divided differences and truncation errors from polynomial degree choice.
  • Applications: Meteorology (temperature prediction), engineering (stress analysis), and computer graphics (curve design).
  • Exam Focus: Derive polynomials, compute divided differences, and compare methods—always show intermediate steps.

Core Concepts

1. Definitions and Basics

Interpolation is the process of estimating values of a function at intermediate points using known data points . It assumes the function is smooth between data points.

Extrapolation extends interpolation beyond the given data range—risky due to potential divergence.

Key Assumptions:

  • Data points are exact (no noise).
  • Function is sufficiently smooth (avoids wild oscillations).

Runge's phenomenon polynomial oscillationExample of high-degree polynomial interpolation causing oscillations (Image: CC BY-SA 3.0, via Wikimedia Commons)

2. Lagrange Interpolation

Formula: For points , the Lagrange polynomial is:

Advantages:

  • Simple to derive for small .
  • No need for divided differences.

Disadvantages:

  • Computationally expensive for large (recomputes all terms for each ).
  • Prone to Runge’s phenomenon (oscillations at endpoints for high-degree polynomials).

Worked Example: Given , find .

Steps:

  1. Compute , etc.
  2. Evaluate .
  3. Result: .

Algorithm:

def lagrange_interpolation(x, y, x_query):
    n = len(x)
    result = 0.0
    for i in range(n):
        term = y[i]
        for j in range(n):
            if i != j:
                term *= (x_query - x[j]) / (x[i] - x[j])
        result += term
    return result

3. Newton’s Divided Difference Interpolation

Divided Differences Table: Builds coefficients incrementally:

Polynomial Form:

Advantages:

  • Efficient for adding new points (append to table).
  • Numerically stable for equally spaced data.

Disadvantages:

  • Still suffers from Runge’s phenomenon for high .

Worked Example: For , compute and .

Divided Differences Table:

3.2 22.0
2.7 17.8 -1.6
1.0 14.2 -1.8 0.05

Polynomial: Evaluate at and .

Algorithm:

def newton_interpolation(x, y, x_query):
    n = len(x)
    coeff = y.copy()
    for j in range(1, n):
        for i in range(n-1, j-1, -1):
            coeff[i] = (coeff[i] - coeff[i-1]) / (x[i] - x[i-j])
    result = coeff[n-1]
    for i in range(n-2, -1, -1):
        result = result * (x_query - x[i]) + coeff[i]
    return result

4. Spline Interpolation

Definition: Piecewise polynomials of degree (typically cubic, ) that satisfy:

  1. (interpolation).
  2. Continuity up to derivatives at knots .

Cubic Spline Conditions: Additional constraints:

  • (continuity).
  • (smoothness).

Advantages:

  • Avoids Runge’s phenomenon.
  • Local support (changing one point only affects adjacent splines).

Disadvantages:

  • More complex setup (solving tridiagonal systems).
  • Overkill for small datasets.

Worked Example: Given , find and .

Steps:

  1. Solve for coefficients using natural spline conditions ().
  2. Evaluate splines at and .

Result:

Algorithm Outline:

def cubic_spline_interpolation(x, y, x_query):
    n = len(x)
    h = [x[i+1] - x[i] for i in range(n-1)]
    alpha = [3*(y[i+1] - y[i])/h[i] - 3*(y[i] - y[i-1])/h[i-1] for i in range(1, n-1)]
    # Solve tridiagonal system for M_i (second derivatives)
    # Compute coefficients a_i, b_i, c_i, d_i
    # Evaluate spline at x_query
    pass

5. Interpolation vs Regression

Feature Interpolation Regression
Goal Exact fit at given points. Approximate fit (minimize global error).
Error at Data Points Zero. Non-zero (unless overfitted).
Model Complexity Can overfit (high-degree polynomials). Controlled via regularization.
Use Case Smooth data with known exact values. Noisy data or predictive modeling.
Example Lagrange for temperature at unmeasured times. Linear regression for stock trends.

Least Squares Approximation: Minimizes . Used when data has noise or interpolation is impractical.


6. Error Analysis

Sources of Error:

  1. Truncation Error: Due to polynomial degree . Higher reduces error but risks instability.
  2. Round-off Error: Accumulates in divided differences for large .
  3. Extrapolation Error: Unbounded as moves away from data range.

Mitigation:

  • Use splines for large datasets.
  • Choose such that number of data points.
  • Prefer Newton’s method for incremental updates.

7. Practical Considerations

When to Use Which Method:

  • Lagrange: Small datasets (), simplicity.
  • Newton: Dynamic datasets (easy to update).
  • Splines: Large datasets or oscillatory functions.
  • Regression: Noisy or sparse data.

Example Applications:

  • Meteorology: Interpolating temperature from weather stations.
  • Computer Graphics: Bézier curves (a type of spline).
  • Finance: Estimating bond prices from market data.

Exam Tip

  1. Derive Polynomials Step-by-Step:
    • For Lagrange, show each term.
    • For Newton, build the divided difference table row by row.
  2. Compare Methods:
    • Highlight trade-offs (e.g., Lagrange’s simplicity vs splines’ stability).
  3. Error Analysis:
    • Always mention Runge’s phenomenon for high-degree polynomials.
  4. Code Snippets:
    • Pseudocode (like above) earns partial credit even if not fully implemented.
  5. Graphical Interpretation:
    • Sketch the data points and interpolating curve to justify your answer.

Common Pitfalls:

  • Forgetting to include all terms in Lagrange interpolation.
  • Misaligning divided differences in Newton’s table.
  • Assuming splines are always better (they require more setup).

mindmap
  root((Interpolation Techniques))
    Lagrange
      Formula: Product of terms
      Pros: Simple for small n
      Cons: Runge's phenomenon
    Newton
      Divided Differences
      Pros: Incremental updates
      Cons: Still oscillates
    Splines
      Piecewise Polynomials
      Pros: Smooth, local control
      Cons: Complex setup
    Regression
      Least Squares
      Pros: Handles noise
      Cons: Approximate fit
    Error Analysis
      Truncation vs Round-off
      Mitigation: Choose n wisely

Based on the TU BSc CSIT syllabus for Numerical Method (CSC212), unit 5.

Discussion

Loading…