Problem Definition
- Problem: For given data (ti,yi),i=1,…,n, with t1<t2<…<tn, we seek (want to find) a function f:R→R such that
f(ti)=yi,i=1,…,n
- f 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 f 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 n data points, we choose to use a polynomial of degree n−1
-
Polynomials in monomial basis:
pn−1(t)=x1+x2t+x3t2+…+xntn−1
-
xi's are coefficients to be determined
-
Often written as:
pn−1(t)=∑j=1nxjϕj(t)
where ϕj(t)=tj−1 are the monomial basis functions
Finding Coefficients of Polynomial Interpolant in Monomial Basis
-
Data points: (t1,y1),(t2,y2),…,(tn,yn)
-
Want pn−1(t) satisfying pn−1(ti)=yi for all i
-
System of equations:
- pn−1(t1)=x1+x2t1+x3t12+…+xnt1n−1=y1
- pn−1(t2)=x1+x2t2+x3t22+…+xnt2n−1=y2
- ⋮
- pn−1(tn)=x1+x2tn+x3tn2+…+xntnn−1=yn
-
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 แบบ:
- Forward Subtitution 2 - Systems of Linear Equations — ไม่ได้เพราะไม่ใช่ Triangular
- Backward Substitution
- Plain GE (Should not be used anymore)
- GEPP
- Cholesky 6 - More on Solving Linear Systems ใช้อันไหนดีล่ะ?!!
The Method for Finding Coefficients
- Solve Ax=y for x where:
- A is the Vandermonde matrix
- x is the unknown vector of coefficients
- y 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 ti's are all distinct.
Conclusion:
- Consider interpolating n points with polynomial of degree n−1
- If all ti's are distinct, then polynomial interpolant exists and is unique
- Note: Interpolating with n−2 or lower degree polynomials may not be possible
Example 1
Find polynomial interpolant using monomial basis for: (−2,−27),(0,−1),(1,0)
อย่าลืม - Data points: (t1,y1),(t2,y2),…,(tn,yn)
Solution:
- Three points, so n=3
- Use polynomial of degree 2: p2(t)=x1+x2t+x3t2
- Degree จะเป็น n−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
- Interpolating polynomial: p2(t)=−1+5t−4t2

- Verification:
- p2(−2)=−1+5(−2)−4(−2)2=−1−10−16=−27 ✅
- p2(0)=−1 ✅
- p2(1)=−1+5−4=0 ✅
Example 2 (Exercise)
Data points: (−2,4),(0,0),(1,3),(2,0),(3,−1)
Solution:
-
Five points, so n=5
-
Use polynomial of degree 4: p4(t)=x1+x2t+x3t2+x4t3+x5t4
-
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
-
Interpolating polynomial: p4(t)=5.6667t−1.5t2−1.6667t3+0.5t4

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)
- ที่ได้ออกมาจะ 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−1 at a given point efficiently?
Horner's Method
-
Standard form: p(t)=2−t+3t2−4t3
-
Horner's form:
- p(t)=2+t(−1+3t−4t2)
- p(t)=2+t(−1+t(3−4t)) — Factor it out!!!
-
General transformation:
pn−1(t)=x1+x2t+x3t2+…+xntn−1(1)
↓
pn−1(t)=x1+t(x2+t(x3+t(⋯(xn−1+xnt)⋯)))(2)
-
Computational complexity:
- Evaluating (1): O(n) additions and O(n2) multiplications
- Evaluating (2): O(n) additions and O(n) multiplications
Exercise 3: Horner's Rule Examples
1. 5t4−3t3+4t2−t+1
- Reorder: 1−t+4t2−3t3+5t4
- Horner's form: 1+t(−1+t(4+t(−3+5t)))
2. 4t5−3t3+2t
- Fill missing terms: 0+2t+0t2−3t3+0t4+4t5
- Horner's form: t(2+t2(−3+4t2))
Product Notation
-
Sigma notation (∑): terms are added together
∑i=110i2=12+22+32+…+102
-
Pi notation (∏): terms are multiplied together
∏i=110i2=12⋅22⋅32⋯102
-
Example: ∏j=47ej=e4⋅e5⋅e6⋅e7
Lagrange Interpolation
ย้อนกลับไป pn−1(t)=x1+x2t+x3t2+…+xntn−1 คือ Monomial Basis มาดูการเขียนแบบอื่น หรือ basis แบบอื่นบ้างนะ
Lagrange Basis Functions
-
Definition: The Lagrange basis functions (a.k.a. fundamental polynomials) are:
lj(t)=∏k=1,k=jn(tj−tk)∏k=1,k=jn(t−tk),j=1,…,n
-
Expanded form:
- l1(t)=(t1−t2)(t1−t3)(t1−t4)⋯(t1−tn)(t−t2)(t−t3)(t−t4)⋯(t−tn)
- l2(t)=(t2−t1)(t2−t3)(t2−t4)⋯(t2−tn)(t−t1)(t−t3)(t−t4)⋯(t−tn)
- l3(t)=(t3−t1)(t3−t2)(t3−t4)⋯(t3−tn)(t−t1)(t−t2)(t−t4)⋯(t−tn)
- ⋮
- ln(t)=(tn−t1)(tn−t2)(tn−t3)⋯(tn−tn−1)(t−t1)(t−t2)(t−t3)⋯(t−tn−1)
Properties of Lagrange Basis Functions
- Each lj(t) is a polynomial of degree n−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=j: lj(tj)=∏k=1,k=jn(tj−tk)∏k=1,k=jn(tj−tk)=1
- For i=j: lj(ti)=∏k=1,k=jn(tj−tk)(ti−t1)(ti−t2)⋯(ti−ti)⋯(ti−tn)=0 (due to (ti−ti)=0)
- General representation: Any polynomial with degree n−1 can be written as:
pn−1(t)=j=1∑nxjlj(t)
Finding Coefficients of Polynomial Interpolant in Lagrange Basis
Setup
- Data points: (t1,y1),(t2,y2),…,(tn,yn)
- Want: pn−1(t) satisfying pn−1(ti)=yi for all i
- Write: pn−1(t)=j=1∑nxjlj(t)
System of Equations
- pn−1(t1)=x1l1(t1)+x2l2(t1)+…+xnln(t1)=y1
- pn−1(t2)=x1l1(t2)+x2l2(t2)+…+xnln(t2)=y2
- ⋮
- pn−1(tn)=x1l1(tn)+x2l2(tn)+…+xnln(tn)=yn
Key Property of Lagrange Basis Functions
lj(ti)={10if i=jif i=j
for i,j=1,…,n
Solution
-
Due to the orthogonal property of Lagrange basis functions:
- x1l1(t1)+x2l2(t1)+…+xnln(t1)=x1=y1
- x1l1(t2)+x2l2(t2)+…+xnln(t2)=x2=y2
- ⋮
- x1l1(tn)+x2l2(tn)+…+xnln(tn)=xn=yn
-
Therefore: xi=yi for all i
-
Final form: pn−1(t)=y1l1(t)+y2l2(t)+…+ynln(t)
Example 4: Lagrange Interpolation
Problem
Find the Lagrange interpolant of the data points (−2,−27),(0,−1),(1,0).
Solution
- Data points: (−2,−27),(0,−1),(1,0)
- 3 data points → use polynomial of degree 2
- p2(t)=y1l1(t)+y2l2(t)+y3l3(t)
- p2(t)=−27l1(t)−l2(t) (since y3=0)
Lagrange Basis Functions
l1(t)=(t1−t2)(t1−t3)(t−t2)(t−t3)=(−2−0)(−2−1)t(t−1)=6t(t−1)
l2(t)=(t2−t1)(t2−t3)(t−t1)(t−t3)=(0+2)(0−1)(t+2)(t−1)=−2(t+2)(t−1)
Final Result
p2(t)=−27⋅6t(t−1)−−2(t+2)(t−1)
p2(t)=−627t(t−1)+21(t+2)(t−1)
Converting to Monomial Basis
p2(t)=−627t2+627t+21t2+21t−1
p2(t)=−4t2+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).
Solution
- 4 data points → use polynomial of degree 3
- p3(t)=y1l1(t)+y2l2(t)+y3l3(t)+y4l4(t)
- p3(t)=2l1(t)−l3(t)+l4(t) (since y2=0)
Calculations
l1(t)=(−1−1)(−1−3)(−1−4)(t−1)(t−3)(t−4)=−40(t−1)(t−3)(t−4)
l3(t)=(3+1)(3−1)(3−4)(t+1)(t−1)(t−4)=−8(t+1)(t−1)(t−4)
l4(t)=(4+1)(4−1)(4−3)(t+1)(t−1)(t−3)=15(t+1)(t−1)(t−3)
Final Result
p3(t)=−201(t−1)(t−3)(t−4)+81(t+1)(t−1)(t−4)+151(t+1)(t−1)(t−3)
Newton Interpolation
มา Newton Basis บ้างละ55555
Newton Basis Functions
-
Can write a polynomial with degree n−1 as:
pn−1(t)=j=1∑nxjπj(t)
-
Newton basis functions:
πj(t)=k=1∏j−1(t−tk)
- π1(t)=1 (Newton บอกให้เป็น 1 นะ!)
- π2(t)=(t−t1)
- π3(t)=(t−t1)(t−t2)
- π4(t)=(t−t1)(t−t2)(t−t3)
- ⋮
- πn(t)=(t−t1)(t−t2)⋯(t−tn−1)
Finding Newton Interpolant
pn−1(t)=x1+x2(t−t1)+x3(t−t1)(t−t2)+…+xn(t−t1)(t−t2)⋯(t−tn−1)
Solving for Coefficients
- For pn−1(t1): x1=y1
- For pn−1(t2): x1+x2(t2−t1)=y2
- For pn−1(t3): x1+x2(t3−t1)+x3(t3−t1)(t3−t2)=y3
- And so on...
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