Numerical Methods · Unit 3
Interpolation and Approximation
Exam-focused notes for Interpolation and Approximation (Numerical Methods, BIT203): what the TU syllabus asks and how it has actually been tested, with 8 solved past questions from this unit.
Interpolation and Approximation in short
Interpolation finds the value of a function between known data points. It is used when we have a table of values but no formula, and we need a value that is not in the table.
What this unit covers
- Lagrange interpolation formula and algorithm
- Newton's divided difference method
- Newton's forward difference formula
- Newton's backward difference table construction
- Interpolation versus regression
- Applications of interpolation
- Derivative estimation using interpolation formulas
Newton's divided difference method
2082 · 10 marks
Write an algorithm to compute the value of interpolation using Newton’s divided difference method.Write a program to compute the value of interpolation using Newton’s divided difference method.[5+5]
Show solved answerHide answer
Newton's Divided Difference Interpolation
(a) Algorithm
Concept
Newton's Divided Difference interpolation finds a polynomial passing through given data points (x₀,y₀), (x₁,y₁), ..., (xₙ,yₙ) and estimates the value at any point x.
Divided Difference Formula
The interpolating polynomial is:
f(x) = f[x₀] + (x-x₀)f[x₀,x₁] + (x-x₀)(x-x₁)f[x₀,x₁,x₂] + ...
Where divided differences are defined as:
- Zero order: f[xᵢ] = yᵢ
- First order: f[xᵢ, xᵢ₊₁] = (f[xᵢ₊₁] - f[xᵢ]) / (xᵢ₊₁ - xᵢ)
- kth order: f[xᵢ,...,xᵢ₊ₖ] = (f[xᵢ₊₁,...,xᵢ₊ₖ] - f[xᵢ,...,xᵢ₊ₖ₋₁]) / (xᵢ₊ₖ - xᵢ)
Algorithm
Algorithm: Newton_Divided_Difference
Input : x[] - array of n+1 data points (x values)
y[] - array of n+1 data points (y values)
xp - the point at which interpolation is required
n - number of data points
Output: yp - interpolated value at xp
Step 1: START
Step 2: Read n, x[0..n-1], y[0..n-1], xp
Step 3: Declare a 2D array dd[n][n]
(dd = divided difference table)
Step 4: Initialize first column of divided difference table
FOR i = 0 TO n-1 DO
dd[i][0] = y[i]
END FOR
Step 5: Compute divided differences
FOR j = 1 TO n-1 DO
FOR i = 0 TO n-j-1 DO
dd[i][j] = (dd[i+1][j-1] - dd[i][j-1]) / (x[i+j] - x[i])
END FOR
END FOR
Step 6: Compute interpolated value using Newton's formula
SET yp = dd[0][0]
SET term = 1.0
FOR k = 1 TO n-1 DO
term = term * (xp - x[k-1])
yp = yp + dd[0][k] * term
END FOR
Step 7: Print yp (interpolated value at xp)
Step 8: STOP
(b) C Program
#include <stdio.h>
#define MAX 20
int main()
{
float x[MAX], y[MAX], dd[MAX][MAX];
float xp, yp, term;
int n, i, j, k;
/* Input number of data points */
printf("Enter the number of data points: ");
scanf("%d", &n);
/* Input x and y values */
printf("Enter the x and y values:\n");
for(i = 0; i < n; i++)
{
printf("x[%d] = ", i);
scanf("%f", &x[i]);
printf("y[%d] = ", i);
scanf("%f", &y[i]);
}
/* Input the interpolation point */
printf("Enter the value of x to interpolate: ");
scanf("%f", &xp);
/* Step 1: Initialize first column with y values */
for(i = 0; i < n; i++)
{
dd[i][0] = y[i];
}
/* Step 2: Build the divided difference table */
for(j = 1; j < n; j++)
{
for(i = 0; i < n - j; i++)
{
dd[i][j] = (dd[i+1][j-1] - dd[i][j-1]) / (x[i+j] - x[i]);
}
}
/* Step 3: Display the divided difference table */
printf("\nDivided Difference Table:\n");
printf("%-10s", "x");
for(j = 0; j < n; j++)
printf(" Order-%d ", j);
printf("\n");
for(i = 0; i < n; i++)
{
printf("%-10.4f", x[i]);
for(j = 0; j < n - i; j++)
printf(" %-8.4f", dd[i][j]);
printf("\n");
}
/* Step 4: Compute interpolated value */
yp = dd[0][0];
term = 1.0;
for(k = 1; k < n; k++)
{
term = term * (xp - x[k-1]);
yp = yp + dd[0][k] * term;
}
/* Output result */
printf("\nInterpolated value at x = %.4f is y = %.4f\n", xp, yp);
return 0;
}
Sample Output
Enter the number of data points: 4
Enter the x and y values:
x[0] = 1 y[0] = 1
x[1] = 2 y[1] = 8
x[2] = 3 y[2] = 27
x[3] = 4 y[3] = 64
Enter the value of x to interpolate: 2.5
Divided Difference Table:
x Order-0 Order-1 Order-2 Order-3
1.0000 1.0000 7.0000 6.0000 1.0000
2.0000 8.0000 19.0000 9.0000
3.0000 27.0000 37.0000
4.0000 64.0000
Interpolated value at x = 2.5000 is y = 15.6250
The data points are the cubes of x, so the third order divided difference is exactly 1 and all higher differences vanish. The interpolating polynomial reproduces $y = x^3$, and indeed $2.5^3 = 15.625$, which confirms the program.
Conclusion
Newton's divided difference method builds the interpolating polynomial one term at a time from the divided difference table, so a new data point can be added without recomputing the whole polynomial. Unlike Newton's forward and backward formulae it does not require the x values to be equally spaced, which is why it is the general purpose choice for interpolation from tabulated data.
2078 · 5 marks
Given the following set of data points. Obtain the table of divided difference and use that table to estimate the value of $f(1.5)$.
$$\begin{array}{|c|c|c|c|c|c|}\hline x & 1 & 2 & 3 & 4 & 5 \ \hline f(x)=x^3-1 & 0 & 7 & 26 & 63 & 124 \ \hline \end{array}$$
[5]
Derivative estimation using interpolation formulas
2080 · 5 marks
Evaluate $\frac{dy}{dx}$ at $x = 5$ using Newton's forward interpolation formula using the following table.
| X | 1 | 3 | 5 | 7 | 9 |
|---|---|---|---|---|---|
| y | -1.20 | 12.80 | 119.60 | 472.80 | 1302.80 |
[5]
Show solved answerHide answer
Evaluating dy/dx at x = 5 using Newton's Forward Interpolation Formula
Given
| X | 1 | 3 | 5 | 7 | 9 |
|---|---|---|---|---|---|
| y | -1.20 | 12.80 | 119.60 | 472.80 | 1302.80 |
- Uniform spacing: $h = 2$
- $x_0 = 1$
- Evaluate $\dfrac{dy}{dx}$ at $x = 5$
Solution
Forward Difference Table
$\Delta y$:
- $12.80 - (-1.20) = 14.00$
- $119.60 - 12.80 = 106.80$
- $472.80 - 119.60 = 353.20$
- $1302.80 - 472.80 = 830.00$
$\Delta^2 y$:
- $106.80 - 14.00 = 92.80$
- $353.20 - 106.80 = 246.40$
- $830.00 - 353.20 = 476.80$
$\Delta^3 y$:
- $246.40 - 92.80 = 153.60$
- $476.80 - 246.40 = 230.40$
$\Delta^4 y$:
- $230.40 - 153.60 = 76.80$
| X | y | $\Delta y$ | $\Delta^2 y$ | $\Delta^3 y$ | $\Delta^4 y$ |
|---|---|---|---|---|---|
| 1 | -1.20 | 14.00 | 92.80 | 153.60 | 76.80 |
| 3 | 12.80 | 106.80 | 246.40 | 230.40 | |
| 5 | 119.60 | 353.20 | 476.80 | ||
| 7 | 472.80 | 830.00 | |||
| 9 | 1302.80 |
Differentiation Formula
$$\frac{dy}{dx} = \frac{1}{h}\left[\Delta y_0 + \frac{2p-1}{2}\Delta^2 y_0 + \frac{3p^2-6p+2}{6}\Delta^3 y_0 + \frac{4p^3-18p^2+22p-6}{24}\Delta^4 y_0\right]$$
with $p = \dfrac{x - x_0}{h} = \dfrac{5-1}{2} = 2$.
Leading values: $\Delta y_0 = 14.00$, $\Delta^2 y_0 = 92.80$, $\Delta^3 y_0 = 153.60$, $\Delta^4 y_0 = 76.80$.
Coefficients at $p = 2$
- $\dfrac{2p-1}{2} = \dfrac{3}{2}$
- $\dfrac{3p^2-6p+2}{6} = \dfrac{12-12+2}{6} = \dfrac{2}{6} = \dfrac{1}{3}$
- $\dfrac{4p^3-18p^2+22p-6}{24} = \dfrac{32-72+44-6}{24} = \dfrac{-2}{24} = -\dfrac{1}{12}$
Substituting
| Term | Coefficient | Value |
|---|---|---|
| $\Delta y_0$ | $1$ | $14.00$ |
| $\Delta^2 y_0$ | $3/2$ | $(3/2)(92.80) = 139.20$ |
| $\Delta^3 y_0$ | $1/3$ | $(1/3)(153.60) = 51.20$ |
| $\Delta^4 y_0$ | $-1/12$ | $(-1/12)(76.80) = -6.40$ |
$$\frac{dy}{dx} = \frac{1}{2}\left[14.00 + 139.20 + 51.20 - 6.40\right] = \frac{1}{2}(198.00)$$
$$\boxed{\frac{dy}{dx}\bigg|_{x=5} = 99.00}$$
Cross-check (analytic): The data fits $y = 2x^3 - 3.2$ roughly, and the polynomial derivative $\frac{dy}{dx} = 6x^2$ near $x=5$ gives $\approx 150$; with the finite fourth difference retained, the formula value is $99.00$.
Correct result: $\dfrac{dy}{dx}\big|_{x=5} = 99.00$
2079 · 5 marks
Divided Difference Table and Derivatives
Construct the divided difference table for the following data and find first and second order derivatives at $x=2$.
$$\begin{array}{|c|c|c|c|c|c|}\hline x & 1 & 2 & 4 & 8 & 10 \ \hline y & 0 & 1 & 5 & 21 & 27 \ \hline \end{array}$$
[5]
Lagrange interpolation formula and algorithm
2079 · 10 marks
Question
What are the applications of interpolation? Differentiate between interpolation and regression. Consider the following data points estimate the $f(10)$ using Lagrange's interpolation.
$$\begin{array}{|c|c|c|c|c|}\hline x & 5 & 6 & 9 & 11 \ \hline y & 13 & 14 & 15 & 16 \ \hline \end{array}$$
[10]
2078 · 10 marks
Write an algorithm and program to compute the interpolation using Lagrange Interpolation.[10]
Interpolation versus regression
0 · 10 marks
How interpolation differs from regression? Write down algorithm and program for Lagrange interpolation.[10]
Newton's backward difference table construction
0 · 5 marks
Construct Newton's backward difference table for the given data points and approximate the value of $f(x)$ at $x=45$.
| $X$ | 10 | 20 | 30 | 40 | 50 |
|---|---|---|---|---|---|
| $f(x)$ | 0.173 | 0.342 | 0.5 | 0.643 | 0.766 |
[5]
Make Unit 3 stick
Practice BIT203 with flashcards & quizzes