hw 6 p6 Divided difference tables allow you yo build a table which calculates th
ID: 3348358 • Letter: H
Question
hw 6 p6
Divided difference tables allow you yo build a table which calculates the coefficients of an interpolating polynomial for you using a recursive technique. It's useful in that you can add to the table as you add more sample points.
(d) [4.1168, Code in MATLAB. Using the data points xSample = 4.46908] , , and the function f(x)-?2.3-7x2+sin(x) build and show the Divided Difference table. 4.19236, 4.20967, (e) Code in MATLAB. Construct your interpolating polynomial P3(x) and evaluate at x4.3. (f) Code in MATLAB. Construct a lower degree polynomial P2() by removing the last sample point and evaluate your new polynomial at x - 4.15Explanation / Answer
clc;
clear all;
% Newton interpolation
%
% [f a d] = newtoninter(x, y, p)
%
% Input arguments ([]s are optional):
% x (vector) of size 1xN which contains the interpolation nodes.
% y (vector) of size 1xN which contains the function values at x
% p (vector) of size 1xP which contains points to be interpolated.
%
% Output arguments ([]s are optional):
% f (vector) of size 1xP. The result of interpolation respect to p.
% [a] (vector) of size 1xN which is leading coefficients genereated by
% divided difference method.
% [d] (matrix) of size NxN (triangular) which is the result of the
% divided difference method
%
% Example
% >> x=[0,1/2,1,2,3]
% >> y=[1,2,5, -1,-3 ];
% >> [f a d]= newtninter(x, y, 5)
x=[4.1168 4.19236 4.20967 4.46908];
y=pi*x.^3-7*x.^2+sin(x)
p=4.3
n = length(x);
%%% Table
d(:,1)=y';
for j=2:n
for i=j:n
d(i,j)= ( d(i-1,j-1)-d(i,j-1)) / (x(i-j+1)-x(i));
end
end
d
a = diag(d)';
Df(1,:) = repmat(1, size(p));
c(1,:) = repmat(a(1), size(p));
for j = 2 : n
Df(j,:)=(p - x(j-1)) .* Df(j-1,:); %Interpolation polynomial
c(j,:) = a(j) .* Df(j,:);
end
f=sum(c)% value at p
%%% solution
y =
99.7301 107.5875 109.4402 139.6377
p =
4.3000
d =
99.7301 0 0 0
107.5875 103.9879 0 0
109.4402 107.0301 32.7580 0
139.6377 116.4084 33.8910 3.2163
f =
119.4324
>>
clc;
clear all;
% Newton interpolation
%
% [f a d] = newtoninter(x, y, p)
%
% Input arguments ([]s are optional):
% x (vector) of size 1xN which contains the interpolation nodes.
% y (vector) of size 1xN which contains the function values at x
% p (vector) of size 1xP which contains points to be interpolated.
%
% Output arguments ([]s are optional):
% f (vector) of size 1xP. The result of interpolation respect to p.
% [a] (vector) of size 1xN which is leading coefficients genereated by
% divided difference method.
% [d] (matrix) of size NxN (triangular) which is the result of the
% divided difference method
%
% Example
% >> x=[0,1/2,1,2,3]
% >> y=[1,2,5, -1,-3 ];
% >> [f a d]= newtninter(x, y, 5)
x=[4.1168 4.19236 4.20967];
y=pi*x.^3-7*x.^2+sin(x)
p=4.15
n = length(x);
%%% Table
d(:,1)=y';
for j=2:n
for i=j:n
d(i,j)= ( d(i-1,j-1)-d(i,j-1)) / (x(i-j+1)-x(i));
end
end
d
a = diag(d)';
Df(1,:) = repmat(1, size(p));
c(1,:) = repmat(a(1), size(p));
for j = 2 : n
Df(j,:)=(p - x(j-1)) .* Df(j-1,:); %Interpolation polynomial
c(j,:) = a(j) .* Df(j,:);
end
f=sum(c)% value at p
%%%solution
y =
99.7301 107.5875 109.4402
p =
4.1500
d =
99.7301 0 0
107.5875 103.9879 0
109.4402 107.0301 32.7580
f =
103.1365
>>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.