7 - Interpolation

Updated 4 Oct 2026

Problem Definition

  • Problem: For given data (ti,yi),i=1,…,n(t_i, y_i), i = 1, \ldots, n, with t1<t2<…<tnt_1 < t_2 < \ldots < t_n, we seek (want to find) a function f:R→Rf : \mathbb{R} \to \mathbb{R} such that
    f(ti)=yi,i=1,…,n\boxed{f(t_i) = y_i, \quad i = 1, \ldots, n}
  • ff is called an interpolating function or an interpolant for the given data


Visual representation: scattered data points → smooth curve that passes through all points

Which Interpolant to Use?

  • For a given set of data points, there are infinitely many functions that interpolate it
  • Choose the simplest one! (unless we have additional requirements...)
    • แล้วอะไรที่ simplest ล่ะ ก็ polynomial ไงงง

Polynomial Interpolation

  • Look for polynomial ff that interpolates the data
  • Advantages:
    • Simplest and most common interpolation
    • Continuous and differentiable
    • Easy to evaluate
    • Easy to compute its derivatives and antiderivatives

Monomial Basis

  • To interpolate nn data points, we choose to use a polynomial of degree n−1n - 1

  • Polynomials in monomial basis:
    pn−1(t)=x1+x2t+x3t2+…+xntn−1\boxed{p_{n-1}(t) = x_1 + x_2 t + x_3 t^2 + \ldots + x_n t^{n-1}}

  • xix_i's are coefficients to be determined

  • Often written as:
    pn−1(t)=∑j=1nxjϕj(t)p_{n-1}(t) = \sum_{j=1}^n x_j \phi_j(t)
    where ϕj(t)=tj−1\phi_j(t) = t^{j-1} are the monomial basis functions

Finding Coefficients of Polynomial Interpolant in Monomial Basis

  • Data points: (t1,y1),(t2,y2),…,(tn,yn)(t_1, y_1), (t_2, y_2), \ldots, (t_n, y_n)

  • Want pn−1(t)p_{n-1}(t) satisfying pn−1(ti)=yip_{n-1}(t_i) = y_i for all ii

  • System of equations:

    • pn−1(t1)=x1+x2t1+x3t12+…+xnt1n−1=y1p_{n-1}(t_1) = x_1 + x_2 t_1 + x_3 t_1^2 + \ldots + x_n t_1^{n-1} = y_1
    • pn−1(t2)=x1+x2t2+x3t22+…+xnt2n−1=y2p_{n-1}(t_2) = x_1 + x_2 t_2 + x_3 t_2^2 + \ldots + x_n t_2^{n-1} = y_2
    • ⋮\vdots
    • pn−1(tn)=x1+x2tn+x3tn2+…+xntnn−1=ynp_{n-1}(t_n) = x_1 + x_2 t_n + x_3 t_n^2 + \ldots + x_n t_n^{n-1} = y_n
  • In matrix form:

    1 & t_1 & t_1^2 & \cdots & t_1^{n-1} \\ 1 & t_2 & t_2^2 & \cdots & t_2^{n-1} \\ \vdots & \vdots & \vdots & \ddots & \vdots \\ 1 & t_n & t_n^2 & \cdots & t_n^{n-1} \end{bmatrix} \begin{bmatrix} x_1 \\ x_2 \\ \vdots \\ x_n \end{bmatrix} = \begin{bmatrix} y_1 \\ y_2 \\ \vdots \\ y_n \end{bmatrix}$$

จาก Matrix Form ข้างบน จะ Solve ยังไง เราเรียนมา 5 แบบ:

  1. Forward Subtitution 2 - Systems of Linear Equations — ไม่ได้เพราะไม่ใช่ Triangular
  2. Backward Substitution
  3. Plain GE (Should not be used anymore)
  4. GEPP
  5. Cholesky 6 - More on Solving Linear Systems ใช้อันไหนดีล่ะ?!!

The Method for Finding Coefficients

  • Solve Ax=yAx = y for xx where:
    • AA is the Vandermonde matrix
    • xx is the unknown vector of coefficients
    • yy is the right-hand side vector
  • Algorithm: Use Gaussian Elimination with Partial Pivoting (GEPP)

Important Theorem

ก่อนที่จะใช้ GEPP ได้ต้องเช็คว่าเป็น Non-sigular ก่อน โชคดีที่มี theorem นี้

Theorem: The Vandermonde matrix is nonsingular if the tit_i's are all distinct.

Conclusion:

  • Consider interpolating nn points with polynomial of degree n−1n - 1
  • If all tit_i's are distinct, then polynomial interpolant exists and is unique
  • Note: Interpolating with n−2n - 2 or lower degree polynomials may not be possible

Example 1

Find polynomial interpolant using monomial basis for: (−2,−27),(0,−1),(1,0)(-2, -27), (0, -1), (1, 0)

อย่าลืม - Data points: (t1,y1),(t2,y2),…,(tn,yn)(t_1, y_1), (t_2, y_2), \ldots, (t_n, y_n)

Solution:

  • Three points, so n=3n = 3
  • Use polynomial of degree 2: p2(t)=x1+x2t+x3t2p_2(t) = x_1 + x_2 t + x_3 t^2
    • Degree จะเป็น n−1=3−1=2n-1=3-1=2
  • System to solve: 1 & t_1 & t_1^2 \\ 1 & t_2 & t_2^2 \\ 1 & t_3 & t_3^2 \end{bmatrix} \begin{bmatrix} x_1 \\ x_2 \\ x_3 \end{bmatrix} = \begin{bmatrix} y_1 \\ y_2 \\ y_3 \end{bmatrix}$$ $$\begin{bmatrix} 1 & -2 & 4 \\ 1 & 0 & 0 \\ 1 & 1 & 1 \end{bmatrix} \begin{bmatrix} x_1 \\ x_2 \\ x_3 \end{bmatrix} = \begin{bmatrix} -27 \\ -1 \\ 0 \end{bmatrix}$$
  • Solution: x=[−15−4]x = \begin{bmatrix} -1 \\ 5 \\ -4 \end{bmatrix}
  • Interpolating polynomial: p2(t)=−1+5t−4t2\boxed{p_2(t) = -1 + 5t - 4t^2}

  • Verification:
    • p2(−2)=−1+5(−2)−4(−2)2=−1−10−16=−27p_2(-2) = -1 + 5(-2) - 4(-2)^2 = -1 - 10 - 16 = -27 ✅
    • p2(0)=−1p_2(0) = -1 ✅
    • p2(1)=−1+5−4=0p_2(1) = -1 + 5 - 4 = 0 ✅

Example 2 (Exercise)

Data points: (−2,4),(0,0),(1,3),(2,0),(3,−1)(-2, 4), (0, 0), (1, 3), (2, 0), (3, -1)

Solution:

  • Five points, so n=5n = 5

  • Use polynomial of degree 4: p4(t)=x1+x2t+x3t2+x4t3+x5t4p_4(t) = x_1 + x_2 t + x_3 t^2 + x_4 t^3 + x_5 t^4

  • System matrix:

    1 & -2 & 4 & -8 & 16 \\ 1 & 0 & 0 & 0 & 0 \\ 1 & 1 & 1 & 1 & 1 \\ 1 & 2 & 4 & 8 & 16 \\ 1 & 3 & 9 & 27 & 81 \end{bmatrix} \begin{bmatrix} x_1 \\ x_2 \\ x_3 \\ x_4 \\ x_5 \end{bmatrix} = \begin{bmatrix} 4 \\ 0 \\ 3 \\ 0 \\ -1 \end{bmatrix}$$
  • Solution: x=[05.6667−1.5−1.66670.5]x = \begin{bmatrix} 0 \\ 5.6667 \\ -1.5 \\ -1.6667 \\ 0.5 \end{bmatrix}

  • Interpolating polynomial: p4(t)=5.6667t−1.5t2−1.6667t3+0.5t4\boxed{p_4(t) = 5.6667t - 1.5t^2 - 1.6667t^3 + 0.5t^4}

Polynomial Interpolation in MATLAB

>> t = [-2 0 1 2 3];
>> y = [4 0 3 0 -1];
>> p = polyfit(t,y,4)
 
p =
    0.5000   -1.6667   -1.5000    5.6667   -0.0000
  • The returned interpolant is p(1)xn+p(2)xn−1+…+p(n+1)p(1)x^n + p(2)x^{n-1} + \ldots + p(n+1)
    • ที่ได้ออกมาจะ reverse กับ vector ที่เราทำข้างบน แค่จำไว้ แต่ผลลัพธ์เหมือนกันนั่นแหละ
  • Note: You must specify the correct degree for the interpolant, otherwise polyfit() returns something else

Polynomial Evaluation

  • Question: How to evaluate a polynomial pn−1(t)=x1+x2t+x3t2+…+xntn−1p_{n-1}(t) = x_1 + x_2 t + x_3 t^2 + \ldots + x_n t^{n-1} at a given point efficiently?

Horner's Method

  • Standard form: p(t)=2−t+3t2−4t3p(t) = 2 - t + 3t^2 - 4t^3

  • Horner's form:

    • p(t)=2+t(−1+3t−4t2)p(t) = 2 + t(-1 + 3t - 4t^2)
    • p(t)=2+t(−1+t(3−4t))p(t) = 2 + t(-1 + t(3 - 4t)) — Factor it out!!!
  • General transformation:
    pn−1(t)=x1+x2t+x3t2+…+xntn−1(1)p_{n-1}(t) = x_1 + x_2 t + x_3 t^2 + \ldots + x_n t^{n-1} \quad (1)
    ↓\downarrow
    pn−1(t)=x1+t(x2+t(x3+t(⋯(xn−1+xnt)⋯ )))(2)\boxed{p_{n-1}(t) = x_1 + t(x_2 + t(x_3 + t(\cdots(x_{n-1} + x_n t)\cdots)))} \quad (2)

  • Computational complexity:

    • Evaluating (1): O(n)O(n) additions and O(n2)O(n^2) multiplications
    • Evaluating (2): O(n)O(n) additions and O(n)O(n) multiplications

Exercise 3: Horner's Rule Examples

1. 5t4−3t3+4t2−t+15t^4 - 3t^3 + 4t^2 - t + 1

  • Reorder: 1−t+4t2−3t3+5t41 - t + 4t^2 - 3t^3 + 5t^4
  • Horner's form: 1+t(−1+t(4+t(−3+5t)))\boxed{1 + t(-1 + t(4 + t(-3 + 5t)))}

2. 4t5−3t3+2t4t^5 - 3t^3 + 2t

  • Fill missing terms: 0+2t+0t2−3t3+0t4+4t50 + 2t + 0t^2 - 3t^3 + 0t^4 + 4t^5
  • Horner's form: t(2+t2(−3+4t2))\boxed{t(2 + t^2(-3 + 4t^2))}

Product Notation

  • Sigma notation (∑\sum): terms are added together
    ∑i=110i2=12+22+32+…+102\sum_{i=1}^{10} i^2 = 1^2 + 2^2 + 3^2 + \ldots + 10^2

  • Pi notation (∏\prod): terms are multiplied together
    ∏i=110i2=12⋅22⋅32⋯102\prod_{i=1}^{10} i^2 = 1^2 \cdot 2^2 \cdot 3^2 \cdots 10^2

  • Example: ∏j=47ej=e4⋅e5⋅e6⋅e7\prod_{j=4}^7 e^j = e^4 \cdot e^5 \cdot e^6 \cdot e^7

Lagrange Interpolation

ย้อนกลับไป pn−1(t)=x1+x2t+x3t2+…+xntn−1p_{n-1}(t) = x_1 + x_2 t + x_3 t^2 + \ldots + x_n t^{n-1} คือ Monomial Basis มาดูการเขียนแบบอื่น หรือ basis แบบอื่นบ้างนะ

Lagrange Basis Functions

  • Definition: The Lagrange basis functions (a.k.a. fundamental polynomials) are:
    lj(t)=∏k=1,k≠jn(t−tk)∏k=1,k≠jn(tj−tk),j=1,…,n\boxed{l_j(t) = \frac{\prod_{k=1,k \neq j}^n (t - t_k)}{\prod_{k=1,k \neq j}^n (t_j - t_k)}, \quad j = 1, \ldots, n}

  • Expanded form:

    • l1(t)=(t−t2)(t−t3)(t−t4)⋯(t−tn)(t1−t2)(t1−t3)(t1−t4)⋯(t1−tn)l_1(t) = \frac{(t - t_2)(t - t_3)(t - t_4)\cdots(t - t_n)}{(t_1 - t_2)(t_1 - t_3)(t_1 - t_4)\cdots(t_1 - t_n)}
    • l2(t)=(t−t1)(t−t3)(t−t4)⋯(t−tn)(t2−t1)(t2−t3)(t2−t4)⋯(t2−tn)l_2(t) = \frac{(t - t_1)(t - t_3)(t - t_4)\cdots(t - t_n)}{(t_2 - t_1)(t_2 - t_3)(t_2 - t_4)\cdots(t_2 - t_n)}
    • l3(t)=(t−t1)(t−t2)(t−t4)⋯(t−tn)(t3−t1)(t3−t2)(t3−t4)⋯(t3−tn)l_3(t) = \frac{(t - t_1)(t - t_2)(t - t_4)\cdots(t - t_n)}{(t_3 - t_1)(t_3 - t_2)(t_3 - t_4)\cdots(t_3 - t_n)}
    • ⋮\vdots
    • ln(t)=(t−t1)(t−t2)(t−t3)⋯(t−tn−1)(tn−t1)(tn−t2)(tn−t3)⋯(tn−tn−1)l_n(t) = \frac{(t - t_1)(t - t_2)(t - t_3)\cdots(t - t_{n-1})}{(t_n - t_1)(t_n - t_2)(t_n - t_3)\cdots(t_n - t_{n-1})}

Properties of Lagrange Basis Functions

  • Each lj(t)l_j(t) is a polynomial of degree n−1n - 1
  • Key property: 1 & \text{if } i = j \\ 0 & \text{if } i \neq j \end{cases}, \quad i,j = 1, \ldots, n}$$
  • Proof:
    • For i=ji = j: lj(tj)=∏k=1,k≠jn(tj−tk)∏k=1,k≠jn(tj−tk)=1l_j(t_j) = \frac{\prod_{k=1,k \neq j}^n (t_j - t_k)}{\prod_{k=1,k \neq j}^n (t_j - t_k)} = 1
    • For i≠ji \neq j: lj(ti)=(ti−t1)(ti−t2)⋯(ti−ti)⋯(ti−tn)∏k=1,k≠jn(tj−tk)=0l_j(t_i) = \frac{(t_i - t_1)(t_i - t_2)\cdots(t_i - t_i)\cdots(t_i - t_n)}{\prod_{k=1,k \neq j}^n (t_j - t_k)} = 0 (due to (ti−ti)=0(t_i - t_i) = 0)
  • General representation: Any polynomial with degree n−1n - 1 can be written as:
    pn−1(t)=∑j=1nxjlj(t)\boxed{p_{n-1}(t) = \sum_{j=1}^n x_j l_j(t)}

Finding Coefficients of Polynomial Interpolant in Lagrange Basis

Setup

  • Data points: (t1,y1),(t2,y2),…,(tn,yn)(t_1, y_1), (t_2, y_2), \ldots, (t_n, y_n)
  • Want: pn−1(t)p_{n-1}(t) satisfying pn−1(ti)=yip_{n-1}(t_i) = y_i for all ii
  • Write: pn−1(t)=∑j=1nxjlj(t)\boxed{p_{n-1}(t) = \sum_{j=1}^{n} x_j l_j(t)}

System of Equations

  • pn−1(t1)=x1l1(t1)+x2l2(t1)+…+xnln(t1)=y1p_{n-1}(t_1) = x_1 l_1(t_1) + x_2 l_2(t_1) + \ldots + x_n l_n(t_1) = y_1
  • pn−1(t2)=x1l1(t2)+x2l2(t2)+…+xnln(t2)=y2p_{n-1}(t_2) = x_1 l_1(t_2) + x_2 l_2(t_2) + \ldots + x_n l_n(t_2) = y_2
  • ⋮\vdots
  • pn−1(tn)=x1l1(tn)+x2l2(tn)+…+xnln(tn)=ynp_{n-1}(t_n) = x_1 l_1(t_n) + x_2 l_2(t_n) + \ldots + x_n l_n(t_n) = y_n

Key Property of Lagrange Basis Functions

lj(ti)={1if i=j0if i≠j\boxed{l_j(t_i) = \begin{cases} 1 & \text{if } i = j \\ 0 & \text{if } i \neq j \end{cases}}
for i,j=1,…,ni, j = 1, \ldots, n

Solution

  • Due to the orthogonal property of Lagrange basis functions:

    • x1l1(t1)+x2l2(t1)+…+xnln(t1)=x1=y1x_1 l_1(t_1) + x_2 l_2(t_1) + \ldots + x_n l_n(t_1) = x_1 = y_1
    • x1l1(t2)+x2l2(t2)+…+xnln(t2)=x2=y2x_1 l_1(t_2) + x_2 l_2(t_2) + \ldots + x_n l_n(t_2) = x_2 = y_2
    • ⋮\vdots
    • x1l1(tn)+x2l2(tn)+…+xnln(tn)=xn=ynx_1 l_1(t_n) + x_2 l_2(t_n) + \ldots + x_n l_n(t_n) = x_n = y_n
  • Therefore: xi=yix_i = y_i for all ii

  • Final form: pn−1(t)=y1l1(t)+y2l2(t)+…+ynln(t)\boxed{p_{n-1}(t) = y_1 l_1(t) + y_2 l_2(t) + \ldots + y_n l_n(t)}

Example 4: Lagrange Interpolation

Problem

Find the Lagrange interpolant of the data points (−2,−27),(0,−1),(1,0)(-2, -27), (0, -1), (1, 0).

Solution

  • Data points: (−2,−27),(0,−1),(1,0)(-2, -27), (0, -1), (1, 0)
  • 3 data points → use polynomial of degree 2
  • p2(t)=y1l1(t)+y2l2(t)+y3l3(t)p_2(t) = y_1 l_1(t) + y_2 l_2(t) + y_3 l_3(t)
  • p2(t)=−27l1(t)−l2(t)p_2(t) = -27 l_1(t) - l_2(t) (since y3=0y_3 = 0)

Lagrange Basis Functions

l1(t)=(t−t2)(t−t3)(t1−t2)(t1−t3)=t(t−1)(−2−0)(−2−1)=t(t−1)6l_1(t) = \frac{(t - t_2)(t - t_3)}{(t_1 - t_2)(t_1 - t_3)} = \frac{t(t - 1)}{(-2 - 0)(-2 - 1)} = \frac{t(t - 1)}{6}
l2(t)=(t−t1)(t−t3)(t2−t1)(t2−t3)=(t+2)(t−1)(0+2)(0−1)=(t+2)(t−1)−2l_2(t) = \frac{(t - t_1)(t - t_3)}{(t_2 - t_1)(t_2 - t_3)} = \frac{(t + 2)(t - 1)}{(0 + 2)(0 - 1)} = \frac{(t + 2)(t - 1)}{-2}

Final Result

p2(t)=−27⋅t(t−1)6−(t+2)(t−1)−2p_2(t) = -27 \cdot \frac{t(t - 1)}{6} - \frac{(t + 2)(t - 1)}{-2}
p2(t)=−276t(t−1)+12(t+2)(t−1)p_2(t) = -\frac{27}{6}t(t - 1) + \frac{1}{2}(t + 2)(t - 1)

Converting to Monomial Basis

p2(t)=−276t2+276t+12t2+12t−1p_2(t) = -\frac{27}{6}t^2 + \frac{27}{6}t + \frac{1}{2}t^2 + \frac{1}{2}t - 1
p2(t)=−4t2+5t−1\boxed{p_2(t) = -4t^2 + 5t - 1}

This matches Example 1 (same interpolant as in monomial basis).

Exercise 5: Four Data Points

Problem

Find the Lagrange interpolant of (−1,2),(1,0),(3,−1),(4,1)(-1, 2), (1, 0), (3, -1), (4, 1).

Solution

  • 4 data points → use polynomial of degree 3
  • p3(t)=y1l1(t)+y2l2(t)+y3l3(t)+y4l4(t)p_3(t) = y_1 l_1(t) + y_2 l_2(t) + y_3 l_3(t) + y_4 l_4(t)
  • p3(t)=2l1(t)−l3(t)+l4(t)p_3(t) = 2l_1(t) - l_3(t) + l_4(t) (since y2=0y_2 = 0)

Calculations

l1(t)=(t−1)(t−3)(t−4)(−1−1)(−1−3)(−1−4)=(t−1)(t−3)(t−4)−40l_1(t) = \frac{(t - 1)(t - 3)(t - 4)}{(-1 - 1)(-1 - 3)(-1 - 4)} = \frac{(t - 1)(t - 3)(t - 4)}{-40}

l3(t)=(t+1)(t−1)(t−4)(3+1)(3−1)(3−4)=(t+1)(t−1)(t−4)−8l_3(t) = \frac{(t + 1)(t - 1)(t - 4)}{(3 + 1)(3 - 1)(3 - 4)} = \frac{(t + 1)(t - 1)(t - 4)}{-8}

l4(t)=(t+1)(t−1)(t−3)(4+1)(4−1)(4−3)=(t+1)(t−1)(t−3)15l_4(t) = \frac{(t + 1)(t - 1)(t - 3)}{(4 + 1)(4 - 1)(4 - 3)} = \frac{(t + 1)(t - 1)(t - 3)}{15}

Final Result

p3(t)=−120(t−1)(t−3)(t−4)+18(t+1)(t−1)(t−4)+115(t+1)(t−1)(t−3)p_3(t) = -\frac{1}{20}(t - 1)(t - 3)(t - 4) + \frac{1}{8}(t + 1)(t - 1)(t - 4) + \frac{1}{15}(t + 1)(t - 1)(t - 3)


Newton Interpolation

มา Newton Basis บ้างละ55555

Newton Basis Functions

  • Can write a polynomial with degree n−1n - 1 as:
    pn−1(t)=∑j=1nxjπj(t)\boxed{p_{n-1}(t) = \sum_{j=1}^{n} x_j \pi_j(t)}

  • Newton basis functions:
    πj(t)=∏k=1j−1(t−tk)\boxed{\pi_j(t) = \prod_{k=1}^{j-1} (t - t_k)}

Explicit Forms

  • π1(t)=1\pi_1(t) = 1 (Newton บอกให้เป็น 1 นะ!)
  • π2(t)=(t−t1)\pi_2(t) = (t - t_1)
  • π3(t)=(t−t1)(t−t2)\pi_3(t) = (t - t_1)(t - t_2)
  • π4(t)=(t−t1)(t−t2)(t−t3)\pi_4(t) = (t - t_1)(t - t_2)(t - t_3)
  • ⋮\vdots
  • πn(t)=(t−t1)(t−t2)⋯(t−tn−1)\pi_n(t) = (t - t_1)(t - t_2) \cdots (t - t_{n-1})

Finding Newton Interpolant

General Form

pn−1(t)=x1+x2(t−t1)+x3(t−t1)(t−t2)+…+xn(t−t1)(t−t2)⋯(t−tn−1)p_{n-1}(t) = x_1 + x_2(t - t_1) + x_3(t - t_1)(t - t_2) +\ldots + x_n(t - t_1)(t - t_2) \cdots (t - t_{n-1})

Solving for Coefficients

  • For pn−1(t1)p_{n-1}(t_1): x1=y1x_1 = y_1
  • For pn−1(t2)p_{n-1}(t_2): x1+x2(t2−t1)=y2x_1 + x_2(t_2 - t_1) = y_2
  • For pn−1(t3)p_{n-1}(t_3): x1+x2(t3−t1)+x3(t3−t1)(t3−t2)=y3x_1 + x_2(t_3 - t_1) + x_3(t_3 - t_1)(t_3 - t_2) = y_3
  • And so on...

Matrix Form

1 & 0 & 0 & \cdots & 0 \\ 1 & (t_2 - t_1) & 0 & \cdots & 0 \\ 1 & (t_3 - t_1) & (t_3 - t_1)(t_3 - t_2) & \cdots & 0 \\ \vdots & \vdots & \vdots & \ddots & \vdots \\ 1 & (t_n - t_1) & (t_n - t_1)(t_n - t_2) & \cdots & (t_n - t_1) \cdots (t_n - t_{n-1}) \end{bmatrix} \begin{bmatrix} x_1 \\ x_2 \\ x_3 \\ \vdots \\ x_n \end{bmatrix} = \begin{bmatrix} y_1 \\ y_2 \\ y_3 \\ \vdots \\ y_n \end{bmatrix}$$ ### Key Features - **Lower-triangular system** → solve using ==**forward substitution**== - **Complexity**: Only $O(n^2)$ operations - **Matrix entry**: The $(i,j)$ entry is $\pi_j(t_i)$ ## Example 6: Newton Interpolation ### Problem Use Newton interpolation to interpolate $(-2, -27), (0, -1), (1, 0)$. ### Solution - **Three points** → Newton polynomial of degree 2 - $p_2(t) = x_1 + x_2(t - t_1) + x_3(t - t_1)(t - t_2)$ - $p_2(t) = x_1 + x_2(t + 2) + x_3(t + 2)t$ ### Matrix System $$\begin{bmatrix} 1 & 0 & 0 \\ 1 & (t_2+2) & 0 \\ 1 & (t_3+2) & (t_3+2)t_3 \end{bmatrix} \begin{bmatrix} x_1 \\ x_2 \\ x_3 \end{bmatrix} = \begin{bmatrix} y_1 \\ y_2 \\ y_3 \end{bmatrix}$$ $$\begin{bmatrix} 1 & 0 & 0 \\ 1 & 2 & 0 \\ 1 & 3 & 3 \end{bmatrix} \begin{bmatrix} x_1 \\ x_2 \\ x_3 \end{bmatrix} = \begin{bmatrix} -27 \\ -1 \\ 0 \end{bmatrix}$$ ### Solution by Forward Substitution $$x = \begin{bmatrix} -27 \\ 13 \\ -4 \end{bmatrix}$$ ### Final Result $$p_2(t) = -27 + 13(t + 2) - 4(t + 2)t$$ Converting to monomial form: $$p_2(t) = -27 + 13t + 26 - 4t^2 - 8t = -1 + 5t - 4t^2$$ **Same result as Example 1!** ## Exercise 7: Newton Interpolation (Four Points) ### Problem Use Newton interpolation to interpolate $(-1, 2), (1, 0), (3, -1), (4, 1)$. ### Solution - **Four points** → Newton polynomial of degree 3 - $p_3(t) = x_1 + x_2(t + 1) + x_3(t + 1)(t - 1) + x_4(t + 1)(t - 1)(t - 3)$ ### Matrix System $$\begin{bmatrix} 1 & 0 & 0 & 0 \\ 1 & 2 & 0 & 0 \\ 1 & 4 & 8 & 0 \\ 1 & 5 & 15 & 15 \end{bmatrix} \begin{bmatrix} x_1 \\ x_2 \\ x_3 \\ x_4 \end{bmatrix} = \begin{bmatrix} 2 \\ 0 \\ -1 \\ 1 \end{bmatrix}$$ ### Solution $$x = \begin{bmatrix} 2 \\ -1 \\ 0.125 \\ 0.1417 \end{bmatrix}$$ ### Final Result $$p_3(t) = 2 - (t + 1) + 0.125(t + 1)(t - 1) + 0.1417(t + 1)(t - 1)(t - 3)$$ --- ## Horner's Rule for Newton Polynomials ### Purpose - Efficiently evaluate polynomial in Newton basis - **Reduces complexity** from $O(n^2)$ to $O(n)$ ### Example $$p(t) = 2 + 3(t - 1) - 2(t - 1)(t + 1) + 5(t - 1)(t + 1)(t - 2)$$ **Applying Horner's rule**: $$p(t) = 2 + (t - 1)(3 - 2(t + 1) + 5(t + 1)(t - 2))$$ $$p(t) = 2 + (t - 1)(3 + (t + 1)(-2 + 5(t - 2)))$$ ### General Form $$\boxed{p_{n-1}(t) = x_1 + (t - t_1)(x_2 + (t - t_2)(x_3 + (t - t_3)(\cdots (x_{n-1} + x_n(t - t_{n-1})) \cdots)))}$$ - ก็ Horner’s rule คืออะไรก็ factor out ไงง > [!question] ก็แค่ทำเหมือน Newton แล้ว Factor out ให้เป็น Horner’s Rule แค่นั้นทำไงต่อถึงจะเปลี่ยนได้เป็น $O(n)$? > อันนี้คือ evaluate ที่ค่า ๆ นึง แล้วถ้าใช้ Horner’s Rule เป็น $O(n)$ ## Exercise 8: Horner's Rule Practice ### Problem 1 Rewrite: $2 - 3(t + 2) + 4(t + 2)(t - 1) + (t + 2)(t - 1)(t - 5)$ **Solution**: $$2 + (t + 2)(-3 + (t - 1)(4 + (t - 5)))$$ ### Problem 2 Rewrite: $5(t + 1)(t - 1) - 6(t + 1)(t - 1)(t - 2)(t - 3)$ **Solution**: $$(t + 1)(t - 1)(5 - 6(t - 2)(t - 3))$$ --- ## Interpolating Continuous Functions ### Purpose - Interpolate a complex continuous function $f(t)$ with a simpler polynomial $p_{n-1}(t)$ - **Method**: Interpolate sample points $(t_i, f(t_i))$ — เลือกมาแค่บางจุดแล้วก็ Interpolate on those บางจุด?? - **Key Question**: ==How closely does the interpolant approximate the given function?== ## Error Bound ### Theorem If $f$ is a sufficiently smooth function and $p_{n-1}$ is the polynomial of degree at most $n-1$ that interpolates $f$ at $n$ points $t_1, \ldots, t_n$ (where $t_1 < t_2 < \cdots < t_n$), then: $$\boxed{\max_{t \in [t_1, t_n]} |f(t) - p_{n-1}(t)| \leq \frac{Mh^n}{4n}}$$ where: - $|f^{(n)}(t)| \leq M$ for all $t \in [t_1, t_n]$ (in same domain) - $h = \max\{t_{i+1} - t_i : i = 1, \ldots, n-1\}$ >หาค่า M ยังไง?! ง่าย ๆ ก็แค่ มองฟังก์ชันที่ถูก Diff ครบ n รอบแล้ว แล้วหา Max ในช่วง สุดท้ายเอา x แทนเพื่อหาค่า y ในข้อนี้ 0.6 คือ Max ให้แทนหาค่า y นั่นคือ M จร้า > [!important] Important Note > ⚠️ **Increasing the number of sample points $(n)$ may not decrease the error of the interpolant!** ### Runge's Function Example ![[Pasted image 20250912080752.png|center|500]] - ลองดูสมมติใช้ 6 data point ($p_5(t)$) ก็ดูพอได้นะ - แต่ถ้าใช้ 11 points ($p_{10}(t)$) มันแทบจะตรงแต่ดูขอบ ๆ มันเด้งเลยล่ะ ไม่ดีนะ! >สิ่งเหล่านี้ถูกอธิบายใน Theorem ขึ้นบน! ## Example 9: Error Bound Calculation ### Problem Consider interpolating $e^{2t}$ with a polynomial, using sample points at $t = 0.2, 0.4, 0.6$. Give an (reasonably-tight) upper bound on the error of the polynomial interpolant of degree 2. ### Solution - **Three sample points** → $n = 3$ - $t_1 = 0.2, t_2 = 0.4, t_3 = 0.6$ - $h = \max\{0.4 - 0.2, 0.6 - 0.4\} = 0.2$ — max ของ difference Consecutive $t_i$ ### Finding $M$ - $f'(t) = 2e^{2t}$ - $f''(t) = 4e^{2t}$ - $f'''(t) = 8e^{2t}$ For all $t \in [0.2, 0.6]$: $$|f'''(t)| = 8e^{2t} \leq 8e^{2(0.6)} = 8e^{1.2} \equiv M$$ ### Error Bound $$\frac{Mh^n}{4n} = \frac{8e^{1.2}(0.2)^3}{4(3)} \approx 0.0177$$ ## Exercise 10: Error Bound Practice ### Problem Consider interpolating $\ln t$ with a polynomial, using sample points at $t = 1, 1.1, 1.2, 1.4$. Give an upper bound on the error. ### Solution - $f(t) = \ln t$, $n = 4$ - $h = \max\{1.1 - 1, 1.2 - 1.1, 1.4 - 1.2\} = 0.2$ ### Derivatives - $f'(t) = \frac{1}{t}$ - $f''(t) = -\frac{1}{t^2}$ - $f'''(t) = \frac{2}{t^3}$ - $f^{(4)}(t) = -\frac{6}{t^4}$ ### Finding $M$ For all $t \in [1, 1.4]$: $$|f^{(4)}(t)| = \left|-\frac{6}{t^4}\right| = \frac{6}{t^4} \leq 6 \equiv M$$ ### Error Bound $$\frac{Mh^n}{4n} = \frac{6(0.2)^4}{4(4)} = 0.0006$$ > [!question] อาจารย์บอกว่านักเรียนปีที่แล้ว หา $M$ ผิดยังไงนะ? > --- ## Key Takeaways (GG) ### Lagrange vs Newton Interpolation - **Same polynomial result** but different representations - **Lagrange**: Direct formula using basis functions - **Newton**: Forward substitution with lower triangular system ### Computational Complexity - **Lagrange basis**: $O(n^2)$ for evaluation - **Newton basis**: $O(n^2)$ for setup, $O(n)$ for evaluation with Horner's rule ### Error Considerations - Error depends on smoothness of function ($M$), spacing of points ($h$), and degree ($n$) - **Higher degree doesn't always mean better approximation** - Choice of interpolation points matters significantly