Numerical MethodUnit 310 min read
Interpolation & Curve Fitting: Methods, Formulas & Applications
Unit 3 of Numerical Method covers polynomial interpolation (Lagrange, Newton), divided differences, curve fitting (least squares), error analysis, and real-world applications in data science, finance, and engineering—with visual step-by-step solutions and exam-focused strategies.
TAKEAWAYS:
- Interpolation estimates unknown values between known data points using polynomials (Lagrange, Newton), while curve fitting finds the best-fit function (least squares) for noisy data.
- Lagrange’s formula constructs a unique polynomial through points but becomes computationally expensive for large .
- Newton’s divided differences builds polynomials incrementally (forward/backward) and is efficient for unevenly spaced data.
- Least squares minimizes error for overdetermined systems (more data points than parameters) and is used in regression analysis.
- Error bounds (e.g., ) quantify interpolation accuracy.
- Applications span finance (stock trends), engineering (sensor calibration), and logistics (demand forecasting).
1. Introduction to Interpolation
Interpolation estimates a function’s value at an unmeasured point using known data points. It is widely used when:
- Exact solutions are impractical (e.g., experimental data).
- Closed-form functions are unavailable (e.g., stock prices).
Key Definitions
- Interpolation: Exact fitting through given points (error = 0 at ).
- Extrapolation: Predicting values outside the data range (higher error risk).
- Polynomial Interpolation: Uses polynomials of degree for points.
Visual: Data Points and Interpolation
Example 1.1: Given , , , find using linear interpolation. Solution: Linear interpolation formula: For (between and ): Answer: .
2. Lagrange Interpolation
Lagrange’s method constructs a polynomial that passes through all points exactly.
Formula
Advantages:
- Simple to derive for small .
- No need to compute divided differences.
Disadvantages:
- Computationally expensive for large (O).
- Unstable for high-degree polynomials (Runge’s phenomenon).
Worked Example 2.1: Lagrange Interpolation
Given: Find and estimate .
Solution: Simplify each : Combine terms: Estimate at : Visual: Lagrange Basis Polynomials
3. Newton’s Divided Differences
Newton’s method builds the polynomial incrementally using divided differences, avoiding recomputation.
Divided Differences Table
For points : Where:
Newton’s Polynomial
Worked Example 3.1: Newton’s Forward Interpolation
Given: Find using Newton’s forward formula.
Solution: Compute divided differences: Newton’s polynomial: Simplify: Estimate at : Visual: Divided Differences Table
4. Error Analysis
The error in polynomial interpolation is bounded by: Key Observations:
- Error grows with polynomial degree and distance from data points.
- Runge’s Phenomenon: High-degree polynomials oscillate wildly outside data range.
Worked Example 4.1: Error Bound
For at using points (quadratic interpolation), estimate the error.
Solution: Compute (maximum at ): Visual: Error Growth with Degree
5. Curve Fitting (Least Squares)
When data has noise, least squares finds the best-fit curve by minimizing the sum of squared errors:
Linear Least Squares
For , solve:
Polynomial Least Squares
For , use the normal equations: where is the Vandermonde matrix.
Worked Example 5.1: Least Squares Fit
Fit a line to:
Solution: Compute sums: Solve: Best-fit line: .
Visual: Least Squares Fit
In the Real World
eSewa (Nepal):
- Idea Used: Interpolation for demand forecasting.
- How: eSewa uses historical transaction data (e.g., electricity bills, mobile recharges) to predict peak usage times. Lagrange or Newton interpolation estimates demand at unmeasured hours (e.g., 3:30 AM) to optimize server load balancing. For example, if data points show usage at 3 AM (1000 requests) and 4 AM (1500 requests), linear interpolation estimates 1250 requests at 3:30 AM to pre-allocate resources.
Khalti (Digital Payments):
- Idea Used: Least squares for fraud detection.
- How: Khalti’s algorithm fits a quadratic curve to user spending patterns (e.g., ) using least squares. If a transaction deviates >3 standard errors from the predicted value, it flags fraud. For instance, if a user’s usual spending at (days) is but a transaction shows , the system triggers a review.
NTC (Electricity Grid Management):
- Idea Used: Newton’s forward interpolation for power grid stability.
- How: NTC monitors voltage levels at substations (e.g., at hours: V). Using Newton’s divided differences, it predicts voltage at hours to adjust generators and avoid blackouts. For example: This guides technicians to preemptively stabilize the grid.
6. Applications and Comparisons
| Method | Use Case | Pros | Cons |
|---|---|---|---|
| Lagrange Interpolation | Exact fitting (small datasets) | Simple, exact fit | Computationally heavy for |
| Newton’s Interpolation | Unevenly spaced data | Efficient updates, stable | Requires divided differences |
| Least Squares | Noisy data, regression | Minimizes error, robust | Overfitting risk with high degree |
| Spline Interpolation | Smooth curves (e.g., CAD) | Local control, no oscillations | Complex implementation |
Cubic splines used in car design (BMW curves) (Image: Berland, Public domain, via Wikimedia Commons)
7. Algorithms and Pseudocode
Algorithm: Lagrange Interpolation
- For to :
- Compute
- Sum
Algorithm: Newton’s Divided Differences
- Build divided differences table.
- Construct polynomial:
Pseudocode: Least Squares Fit (Linear)
def least_squares(x, y):
n = len(x)
sum_x = sum(x)
sum_y = sum(y)
sum_xy = sum(xi * yi for xi, yi in zip(x, y))
sum_x2 = sum(xi**2 for xi in x)
a = (n * sum_xy - sum_x * sum_y) / (n * sum_x2 - sum_x**2)
b = (sum_y - a * sum_x) / n
return a, b
Exam Tip
For interpolation questions:
- Always verify if the data suggests a low-degree polynomial (e.g., quadratic) before jumping to high-degree Lagrange.
- In Newton’s method, show the divided differences table—examiners love this step-by-step clarity.
For least squares:
- Write the normal equations explicitly. Partial credit is often given for setting up the system correctly.
- If asked to fit a polynomial, use the Vandermonde matrix notation to impress.
Error analysis:
- Recall the error formula and state assumptions (e.g., is bounded). For example:
"Assuming on , the error at is bounded by..."
- Recall the error formula and state assumptions (e.g., is bounded). For example:
Real-world tie-ins:
- Examiners may ask to relate interpolation to a scenario (e.g., "How would Ncell use Newton’s interpolation?"). Prepare 1–2 bullet points per method.
Common pitfalls:
- Extrapolation: Never assume interpolation works outside the data range. State this explicitly.
- Divided differences: Watch the sign alternations in the table—negative values are normal!
- Least squares: Avoid overfitting by justifying your polynomial degree (e.g., "Degree 2 fits better than 3 based on RSS").
Final Visual: Method Comparison
Based on the TU BIT syllabus for Numerical Method (BIT203), unit 3.
Discussion
Loading…