clear;
f=inline('cos(x)');
x0=0;y0=0;xe=pi;n=101;
x=linspace(x0,xe,n);
y=zeros(1,n);
dx=(xe-x0)/(n-1);
y(1)=y0;
for k=2:n
    y(k)=y(k-1)+feval(f,x(k-1))*dx;
end
yy=sin(x);
plot(x,yy,'o-',x,y,'*-');grid('on');
title(['Division Number= ',num2str(n-1)]);
xlabel('x');ylabel('y');