Polynomial Interpolation Slides_6312510

Chapter Objectives

  • Evaluate polynomial coefficients.

  • Interpolate using Python’s polyfit and polyval functions.

  • Perform interpolation with Newton’s and Lagrange polynomials.

  • Solve inverse interpolation problems by recasting them as roots problems.

  • Understand the dangers of extrapolation.

  • Recognize the oscillation issues with higher-order polynomials.

Polynomial Interpolation

  • Definition: Polynomial interpolation uses a polynomial to fit a curve through a set of data points exactly.

  • Key Concept: The polynomial must pass through each of the given data points, which distinguishes it from other fitting methods where exact matching is not required.

  • Characteristics:

    • If there are n data points, an (n−1)th order polynomial perfectly fits those points.

    • To find polynomial coefficients, construct a system of linear equations solvable by linear algebra techniques.

Example of Polynomial Interpolation

  • Data Points: (1, 2), (2, 3), (3, 5)

  • Polynomial Form: Find ax^2 + bx + c

  • Process:

    • Construct and solve a linear system using methods like Gaussian elimination or matrix inversion.

    • The system of equations guarantees that the polynomial fits all points exactly.

Solving More Complex Interpolations

  • Given Data Points: (1, 1), (2, 8), (3, 27), (4, 64) to fit a cubic polynomial

  • Polynomial Form: Find ax^3 + bx^2 + cx + d

Determining Coefficients

  • Polynomial interpolation results in as many basis functions as data points (n).

  • Coefficients can be determined precisely through linear algebra or using Python's NumPy functionalities polyfit and polyval.

Python NumPy Example

import numpy as np
T = np.array([300., 400., 500.])
rho = np.array([0.616, 0.525, 0.457])
coef = np.polyfit(T, rho, 2)
print(coef)  # Output example: [1.150e-06, -1.715e-03, 1.027e+00]
dens = np.polyval(coef, 350.)
print('{0:7.5g}'.format(dens))  # Predict density at 350 °C

Newton Interpolating Polynomials

  • Overview: Another way to structure polynomial interpolation is through Newton's interpolating polynomial, which has several key features:

    • Provides a unique polynomial for n+1 points.

    • Can be expressed in various formats such as Newton and Lagrange forms.

Types of Interpolation

  • Linear Interpolation: Simplest method, connecting two data points.

  • Quadratic Interpolation: Improves estimates using three points, allowing for curvature.

Newton’s Divided-Difference Interpolation

  • Divided differences allow for polynomial expressions at higher orders through incremental additions.

  • The general formula for (n−1)th order involves terms from the previous polynomial order plus one extra term using divided differences.

Comparing Polynomial and Newton Interpolation

  • Polynomial Interpolation: Fits all data points in a single step — provides a polynomial in standard form.

  • Newton Interpolation: Builds polynomial incrementally and is flexible for adding new data without recalculating from scratch.

Example Analysis

Linear Interpolation for ln(2)

  1. Interpolating between ln(1) = 0 and ln(6) = 1.791759.

  2. Using smaller intervals such as ln(1) to ln(4) reduces error in estimation.

Quadratic Interpolation to Fit Points

  • Using known points, fit a second-order polynomial to improve estimates.

# Illustrative implementation for the Newton Interpolating Polynomial
def Newtint(x, y, xx):
    n = len(x)
    if len(y) != n: return 'x and y must be of same length'
    b = np.zeros((n, n))
    b[:,0] = np.transpose(y)
    for j in range(1, n):
        for i in range(n - j):
            b[i,j] = (b[i+1,j-1] - b[i,j-1]) / (x[i+j] - x[i])
    xt = 1
    yint = b[0,0]
    for j in range(n - 1):
        xt = xt * (xx - x[j])
        yint += b[0,j+1] * xt
    return yint
  • Note: Always ensure consistency in the lengths of x and y in the implementation.

Conclusion

  • Polynomial interpolation is a powerful method in numerical analysis, allowing for accurate estimates of intermediate values while understanding the risks of higher-order oscillations and extrapolations.