function [c,w]=divdiff(x,y) % Divided difference of data y with respect to the knots in x % % x,y: vectors of equal length % % Output: % c: the divided difference % w: the vector of coefficients for the Newton polynomial % % repeated x-values are allowed if x is increasing % then the data values in y are taken as function, % derivative and higher derivative values, respectively. [x,i]=sort(x); y=y(i); l=length(y); if (l ~= length(x)) error('x and y must have the same dimension.') end %use the spline toolbox to find multiplicities m=myknt2mlt(x); % see description for knt2mlt index=find(m>0); ys=y; %save for derivative values y(index)=y(index-m(index)); % fill function values for k=1:l-1 % for differences when consecutive x-values are different xdiff=(x(k+1:l)-x(1:l-k)); ydiff=diff(y(k:l)); index=find(m(k+1:l)k-1); y(index)=ys(index-m(index)+k); end w=y; c=y(end); function knmult=myknt2mlt(t) % % Berechnung der Vielfachheit eines Knotens in einem % aufsteigend sortierten Knotenvektor % knmult(i) ist die genaue Anzahl der Einträge t(k)=t(i) % mit k