clear format long x = [0.6 0.7 0.8 0.9]; e = [cos(0.6) cos(0.7) cos(0.8) cos(0.9)]; y = e - x; n = size(x)(2); Q = zeros(n); Q(:,1) = x'; z = 0; for i = 1:n-1 for j = 1:i Q(i+1,j+1) = ( ((z-y(i-j+1))*Q(i+1,j)) - ((z-y(i+1))*Q(i,j)) ) / ( y(i+1) - y(i+1-j) ); end end f = @(x) cos(x) - x f(Q(n,n)) Q(n,n)