Matlab code requires The second function, called poly value, should read in the
ID: 3801465 • Letter: M
Question
Matlab code requires
The second function, called poly value, should read in the table of divided difference values generated by the function divdiff, the x-vector, and a vector t. The output of the function are the values of Newton's polynomial computed at points given in the vector t. This means, your file poly value. m should start with the following few lines: function v = poly value(a, x, t) % input: a = Newton's divided differences % x = the points for the data set to interpolate, % same as in divdiff. % t = the points where the polynomial should be evaluated % output: v = value of polynomial at the points in tExplanation / Answer
Matlab function polyvalue.m
function v = polyvalue(a,x,t)
% input: a= newton's divided difference
% x= the points for the data set to interpolate,
% same as in divdiff.
% t= the points where the polynomial should be evaluated
% output: v= values of the polynomial at the points in t
Pts = length(t);
N = length(x);
for j = 1:Pts % loop for each t
Prod = 1;
y = a(1,1); % First term in the summation term
for k = 1:N-1
Prod = (t(j)-x(k))*Prod;% Creating the product terms (x-x0)(x-x1)...
y = y+a(1,k+1)*Prod; % Summ of each terms a_i*Prod_i
end
v(j) = y;
end
end
Testing the function
>> x
x =
0 1 2 3 4
>> y
y =
1.0000 2.2500 3.7500 4.2500 5.8100
>> t
t =
1.2000 2.4000 3.0000
>> a
a =
1.0000 1.2500 0.1250 -0.2083 0.1379
2.2500 1.5000 -0.5000 0.3433 0
3.7500 0.5000 0.5300 0 0
4.2500 1.5600 0 0 0
5.8100 0 0 0 0
>> v = polyvalue(a,x,t)
v =
2.6177 4.0288 4.2500
>>