Thursday, March 23, 2023

Curve fitting using Newton divide-difference interpolation method on matlab

 Newton divided difference interpolation method

Newton's divided difference interpolation method is a numerical technique for finding a polynomial function that passes through a given set of data points. The polynomial function can be used to approximate the behavior of a given function or to interpolate data values between the given points.

The method involves constructing a set of divided differences based on the given data points. Divided differences are defined recursively in terms of lower-order differences until a table of all divided differences is generated. The coefficients of the polynomial function are then determined from the first row of the table.




% Curve fitting using the Newton-Divide difference method
% Input data points
x = [1 2 4 7];
y = [0 4 2 3];
% Number of data points
n = length(x);
% Initialize divided difference table
f = zeros(n);
% Assign y values to the first column of the divided difference table
f(:,1) = y';
% Calculate divided differences
for j = 2:n
for i = j:n
f(i,j) = (f(i,j-1) - f(i-1,j-1))/(x(i)-x(i-j+1));
end
end
% Polynomial coefficients are the diagonal elements of the divided difference table
coeffs = diag(f);
% Calculate polynomial function
syms t;
polynomial = coeffs(1);
for i = 2:n
term = 1;
for j = 1:i-1
term = term*(t-x(j));
end
polynomial = polynomial + coeffs(i)*term;
end
% Display polynomial function and polynomial coefficients
disp("Polynomial function:");
disp(polynomial);
disp("Polynomial coefficients:");
disp(coeffs);




=========================================================================
>>newton_divided_difference
Polynomial function:
4*t - (5*(t - 1)*(t - 2))/3 + (29*(t - 1)*(t - 2)*(t - 4))/90 - 4

Polynomial coefficients:
0
4.0000
-1.6667
0.3222

No comments:

Post a Comment