generating polynomial using newton divided difference
Show older comments
Hi good day y'all, i'm making a code for newton divided difference but i'm having a hard time generating the right polynomial, can someone please help me? thank you so much.
y=[1 2 3 4];
x=[4.4 4.3 2 5];
n=size(x,2);
DD=zeros(n,n);
DD(:,1)=y';
for j=2:n
for i=1:(n-j+1)
num=DD(i+1,j-1)-DD(i,j-1);
den = (x(i+j-1)-x(i));
DD(i,j)=num./den;
end
end
array2table(DD)
n=length(x);
a(1)=x(1);
for k=1:n-1
d(k,1)=(y(k+1)-y(k))/(x(k+1)-x(k));
end
for j=2:n-1
for k=1:n-j
d(k,j)=(d(k+1,j-1)-d(k,j-1))/(x(k+j)-x(k));
end
end
%
for j=2:n
a(j)=d(1,j-1);
end
yn=vpa(x);
d=vpa(d);
a=vpa(a);
clear x
syms x
%
Df(1)=vpa(1);
c(1)=a(1);
for j=2:n
Df(j)=(x-yn(j-1)).*Df(j-1);
c(j)=a(j).*Df(j);
end
format short
f=simplify(sum(c))
Accepted Answer
More Answers (0)
Categories
Find more on Polynomials in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!