function[P,G]=fun(xx,n)
x=[0.0,0.2,0.4,0.6,0.8,1.0,1.2];
y=[1.0,0.980067,0.921061,0.825336,0.696707,0.540302,0.362358];
t=[1.0,0,0,0,0,0,0];
A=[1.0,0,0,0,0,0,0];
for k=2:n
t(k)=y(k);
for j=(k-1):1
t(j)=(t(j+1)-t(j))/(x(k)-x(j));
continue
end
A(k)=t(1);
continue
end
P=A(n);
for i=n:2
P=P*(xx-x(i-1))+A(i-1);
end
G=abs(P-cos(xx));
x=[0.0,0.2,0.4,0.6,0.8,1.0,1.2];
y=[1.0,0.980067,0.921061,0.825336,0.696707,0.540302,0.362358];
t=[1.0,0,0,0,0,0,0];
A=[1.0,0,0,0,0,0,0];
for k=2:n
t(k)=y(k);
for j=(k-1):1
t(j)=(t(j+1)-t(j))/(x(k)-x(j));
continue
end
A(k)=t(1);
continue
end
P=A(n);
for i=n:2
P=P*(xx-x(i-1))+A(i-1);
end
G=abs(P-cos(xx));