function [c]=lagrangecoeff(x,y)
%Calculate coefficients of Lagrange's interpolating polynomial using products of differences
n=length(x);
% x -> column vector of values along x-axis
% y -> coulmn vector of values along y-axis
% c -> Lagrange interpolating coefficients for polynomial fit to data

c=y;
d=diag(eye(n));
for j=1:n
   for i=1:n
      if(i~=j)
         d(j)=d(j)*(x(j)-x(i));
      end
   end
   c(j)=c(j)/d(j);
end
