Problem 3 needs to be done before completing 4. Write a MATLAB function, called
ID: 3861497 • Letter: P
Question
Problem 3 needs to be done before completing 4.
Write a MATLAB function, called Newton_poly that inputs a set of data points (x; y) =(datx, daty), a set x of numbers at which to interpolate, and outputs the polynomial interpolant, y, evaluated at x using Newton polynomial interpolation. Your function header should look something like: function y = Newton_poly(x, datx, daty) Use the code you developed in Problem 3 to interpolate the function f(x) = 1/a + x^2 using the data points datx=-5:1:5. Interpolate at the points x=-5:0.001:5. Plot the results and compare them to what you got in problem 2(b). Explain why you get what you get.Explanation / Answer
3)
Algorithm :
function p = newtonPoly(a,y,x)
n = length(y);
p = a(n);
for k = 1:n-1;
p = a(n-k) + (x - y(n-k))*p;
end
MATLAB PROGRAM:
function y = Newton_poly(x, datx, daty)
n=length(datx)-1;
% Initialize difference table
d=datx;
for i=1:n
for j=n+1:-1:i+1,
d(j)=(d(j-1)-d(j))/(x(j-1)-x(j));
end
% use nested multiplication to evaluate the
% polynomial at daty
y=d(i+1);
for j=i:-1:1,
y=d(j)+(daty-x(j))*y;
end
% display coefficients
% polynomial, and value at daty
disp(sprintf('Degree %d:',i))
fprintf(' ')
fprintf('Coefficients=')
fprintf(' ')
Coefficients=d(1:i+1);
disp(Coefficients)
fprintf('Value=')
fprintf(' ')
Value=y;
disp(Value)
end
4) Please provide the result of 2(b) , so that we can compare and provide you the correct output.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.