format long n=4; x = [0.6 0.7 0.8 0.9]; f = [cos(0.6) cos(0.7) cos(0.8) cos(0.9)]; L = ones(1,n); a = 0.739141 for i =1:n for j=1:n if(i!=j) L(i) = L(i) * (a-x(j))/(x(i)-x(j)); end end end s=0 for i=1:n s = s + f(i)*L(i); end s