Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Develop a function that creates an interpolated polynomial from a data set using

ID: 3682167 • Letter: D

Question

Develop a function that creates an interpolated polynomial from a data set using Newton’s divided difference method and an m-file that calls this function and plots both the data and the fitted curve. DO not use any internal interpolation functions, additionally, do not use any internal summing functions i.e. sum

1. The function should take in three variables, a data set (x,y) a variable indicating which order model the data should be fit to, and a average indicating which data points should be used.

2. The output argument should be in interpolated function a. You may choose the output this as just coefficients or as a function

3. An additional m file should call the function and then plot the data and the interpolated curve

4. Present examples for zero through third order polynomial. Note that your code should also be able to create higher order polynomials.

I need the matlab version of this as soon as possible :-)

Explanation / Answer

Hi below i have written an example code for your reference,

function v = pchiptx(x,y,u)

%PCHIPTX Textbook piecewise cubic Hermite interpolation.

% v = pchiptx(x,y,u) finds the shape-preserving piecewise

% P(x), with P(x(j)) = y(j), and returns v(k) = P(u(k)).

% % See PCHIP, SPLINETX.

% First derivatives

h = diff(x);

delta = diff(y)./h;

d = pchipslopes(h,delta);

% Piecewise polynomial coefficients

n = length(x);

c = (3*delta - 2*d(1:n-1) - d(2:n))./h; b = (d(1:n-1) - 2*delta + d(2:n))./h.^2;

% Find subinterval indices k so that x(k) <= u < x(k+1) k = ones(size(u));

for j = 2:n-1 k(x(j) <= u) = j;

end

% Evaluate interpolant

s = u - x(k);

v = y(k) + s.*(d(k) + s.*(c(k) + s.*b(k)));