CS计算机代考程序代写 clear all

clear all

xpoints=[0 2 4 7 9 10]
ypoints=[0 5 8 10 2 4]

n=length(xpoints)-1; %order of polynomial
b=NewtonIntCoeff(xpoints,ypoints,n);

xint=0:0.1:10;

yint=NewtonIntEval(b,xpoints,n,xint);

hold off
plot(xpoints,ypoints,’ko’,’MarkerSize’,20,’MarkerFaceColor’,’r’)
hold on
plot(xint,yint,’b-‘,’Linewidth’,4)
xlabel(‘x’)
ylabel(‘y’)

function b=NewtonIntCoeff(x,y,n)
fd=zeros(n+1,n+1);
for i=1:n+1
fd(i,1)=y(i);
end

for j=2:n+1
for i=1:n-j+2
fd(i,j)=(fd(i+1,j-1)-fd(i,j-1))/(x(i+j-1)-x(i));
end
end
b=fd(1,:);
end

function yint=NewtonIntEval(b,xpoints,n,xint)
yint=b(1)*ones(1,length(xint));
xterm=ones(1,length(xint));
for i=2:n+1
xterm=xterm.*(xint-xpoints(i-1));
yint=yint+b(i)*xterm;
end
end