MTH375: Numerical Computations
Lab # 8 Newton’s divided difference interpolation method
Name Mohammad Faizan Irfan
Registration Number FA21-BEE-086
Class BEE-7A
Instructor Name Dr. Syed Abdul Mannan Kirmani
In-Lab Task
Newton interpolating polynomial Function Definition:
function yint = newtint(x,y,xx)
% Newtint: Newton interpolating polynomial
% yint = Newtint(x,y,xx): Uses an (n − 1)−order Newton
% interpolating polynomial based on n data points (x, y)
% to determine a value of the dependent variable (yint)
% at a given value of the independent variable, xx.
% input:
% x = independent variable
% y = dependent variable
% xx = value of independent variable at which
% interpolation is calculated
% output:
% yint = interpolated value of dependent variable
% compute the finite divided differences in the form of a
% difference table
n = length(x);
if length(y)~=n, error('x and y must be same length'); end
b = zeros(n,n);
% assign dependent variables to the first column of b.
b(:,1) = y(:); % the (:) ensures that y is a column vector.
for j = 2:n
for i = 1:n-j+1
b(i,j) = (b(i+1,j-1)-b(i,j-1))/(x(i+j-1)-x(i));
end
end
% use the finite divided differences to interpolate
syms xx %syms xx for printing the equation, otherwise no need to add this statement
xt = 1;
yint = b(1,1);
for j = 1:n-1
xt = xt*(xx-x(j));
yint = yint+b(1,j+1)*xt;
end
Code Snippet #1: MATLAB Code for Newton interpolating polynomial Function Definition
Newton interpolating polynomial Function Calling:
x = [0 1 2 3];
y = [1 1 0 1];
xx = 1.5;
newtint(x,y,xx)
x = [1 4 6 5];
y = [0 1.386294 1.791759 1.609438];
xx = 2;
newtint(x,y,xx)
Code Snippet #2: MATLAB Code for Newton interpolating polynomial Function Calling
Output:
Figure #1: Shows the output of the Newton interpolating polynomial Function
These codes implement Newton's Interpolation using the newtint function. The function takes three
inputs: x (independent variable data points), y (corresponding dependent variable values), and xx (the
point at which interpolation is required). It builds a difference table to calculate divided differences,
which are coefficients of Newton's polynomial. The polynomial is then constructed incrementally and
evaluated at xx to find the interpolated value (yint). The first example interpolates the value at xx = 1.5
for given data, while the second example interpolates at xx = 2. This technique is efficient for unevenly
spaced data points.
Conclusion:
In this lab, we explored Newton’s divided difference interpolation method, which is a powerful numerical
technique for estimating values of a function at given points using polynomial interpolation. By defining
the newtint function in MATLAB, we computed finite divided differences and built Newton's polynomial
incrementally. The method was tested on two sets of data, demonstrating its ability to handle unevenly
spaced points effectively and interpolate values accurately. This lab highlighted the computational
efficiency and practical importance of Newton's method in numerical computations, providing a deeper
understanding of interpolation techniques for solving real-world problems involving discrete data.