Matlab required In Matlab %Here is the my_divd function.. function f = my_divdif
ID: 663111 • Letter: M
Question
Matlab required
In Matlab
%Here is the my_divd function..
function f = my_divdif(n,x,f)
% function f = my_divdif(n,x,f)
% Computes diagonal of divided difference table
% Inputs:
% n = order of table (needs n+1 interpolation points & values)
% x = vector of interpolation points
% f = vector of function values
for i = 1:n
for j = (n+1):-1:(i+1)
f(j) = (f(j)-f(j-1)) / (x(j)-x(j-i));
end
end
%Here is the other one needed
function p = my_interp(n,d,x,t)
% function p = my_interp(n,d,x,t)
% Computes value of interpolating polynomial at t
% Inputs:
% n = order of polynomial
% d = diagonal of divided difference table (returned by my_divdif)
% x = vector of interpolation points
% t = where we want to evaluate the interpolating polynomial
p = d(n+1);
for k = n:-1:1
p = d(k) + (t-x(k)).*p;
end
should be done with 5 equally spaced interpolation points in [0,1], and the maximum error should be computed using 101 equally spaced points in the interval [0,1].
Write a function (using the provided my_divdif and my_interp functions) that computes the divided difference table dd and maximum error maxerr for interpolating cos.x exp(x) for 0xx: function [da,max err] = pa3f1()Explanation / Answer
we can calculate interpolation error using interp2 matlab function
t = 0:0.001:1; % vectoe
x = cos(t)(Exp(t));% our function
r = 4; %number of decimal points want
y = interp1(x,r); %interpolation calculating
e = x - y(1:r:end); %calculating error
disp(e) %displaying error