Solve the following in MAT LAB Please add the comments in ea

Solve the following in MAT LAB. Please add the comments in each line and provide the coding window and the command window. Using nested while loops and any necessary if - else statements, create a script that prompts the user to input a series of data points (this needs to be arbitrary; the number of data points could change depending on the order of the polynomial). Create a matrix (A) based off Newton\'s interpolating polynomial. From that matrix, determine the coefficients for the polynomial. You may only use the built-in functions input, DSP, zeros, and ones. Test your code on the following set of points: (1, 3), (4, 8), (7, 10).

Solution

Script for Newton\'s Interpolation.

% x and y are two Row Matrices and p is point of interpolation
%
% Example
% >> x=[1,2,4,7,8]
% >> y=[-9,-41,-189,9,523]
% >> newton_interpolation(x, y, 5)
% OR
% >> a = newton_interpolation(x, y, 5)

n = length(x);
a(1) = y(1);
for k = 1 : n - 1
d(k, 1) = (y(k+1) - y(k))/(x(k+1) - x(k));
end
for j = 2 : n - 1
for k = 1 : n - j
d(k, j) = (d(k+1, j - 1) - d(k, j - 1))/(x(k+j) - x(k));
end
end
d
for j = 2 : n
a(j) = d(1, j-1);
end
Df(1) = 1;
c(1) = a(1);
for j = 2 : n
Df(j)=(p - x(j-1)) .* Df(j-1);
c(j) = a(j) .* Df(j);
end
fp=sum(c)

 Solve the following in MAT LAB. Please add the comments in each line and provide the coding window and the command window. Using nested while loops and any nec

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site