% finds a polynomial P so that P(x(i)) = y(i) 
% and returns the coefficients c and the values of P
% at yi(k) = P(xi(k)) 
function [yi, c]=myinterp(x,y,xi)
yi=zeros(size(xi));
n=max(size(x));
c=zeros(n);
c(1)=y(1);
for k=2:n
    pr=1;
    for i=1:k-1
        pr = pr*(x(k)-x(i));
    end
    c(k)=(y(k)-myeval(x(k),k-1,c,x))/pr;
end
for i=1:max(size(xi))
    yi(i) = myeval(xi(i),n,c,x);
end
