In order to do problem 4, problem 3 needs to be completed. Write a MATLAB functi
ID: 3820551 • Letter: I
Question
In order to do problem 4, problem 3 needs to be completed.
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/1 + 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)
function y = Newton_poly(a,datx,daty)
% Returns value of Newton’s polynomial at x.
n = length(datx);
y = a(n);
for k = 1:n-1;
y = a(n-k) + (x - datx(n-k))*y;
end
4)
Given,
f(x)=1/1+x2
datx=5:1:5
Interpolate at x =5:0,001:5.
datx = [5;1;5];
daty = [0.0384;0.5;0.0384];
a = newtonCoeff(datx,daty);
’ x yInterp yExact’
for x = 5:0.001:5
y = Newton_Poly(a,datx,daty);
yExact = 1/1+x2;
fprintf(’%10.5f’,x,y,yExact)
fprintf(’ ’)
end
The results are:
x yInterp yExact
5.000 0.0384 0.0384
5.001 0.0384467 0.03845
5.000 0.0384 0.0384
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.