function [I] = reimann_prosegisi(f,a,b,n) 
% sinartisi poy ypologizei tin timi enos olokliromatos athroisamta reimann
% i sinartisi dexete to xeiristirio tin sinartisis kathos kai ta akra 
% oloklirosis kathos kai ton arithmo toy diamerismoy toy pedioy orismoy 
% sto opoio i sinartisi einai sinexis ( a ~ b kai akra oloklirosis)
% isxyei b - a / n (blepe paroysiasi protoy mathimatos matlab)
%  f(x) sto diasthma [a,b] me n upodiasthmata. 
% 
% f = @(x) 1./(25+x.^2);
% 
%for i = 1 : 100 ,reimann_prosegisi(@sin,0,pi,i),pause(.3),end
x=linspace(a,b,n+1); 
d = x(2)-x(1)/2;
Y=feval(f,x); 
Yleft=Y(1:n); 
I=sum(diff(x).*Yleft); 
% Draw area
xnew=linspace(a,b,1001); 
ynew=feval(f,xnew); 
hf =plot(xnew,ynew); xlabel('x'); ylabel('y'); hold on
%set(hf,'linew',6)
for i=1:n 
 xx(1)=x(i); yy(1)=0; 
 xx(2)=x(i+1); yy(2)=0; 
 xx(3)=x(i+1); yy(3)=feval(f,xx(1)); 
 xx(4)=x(i); yy(4)=feval(f,xx(1)); 
 fill(xx,yy,[0 1 0]) 
end

aa = title('Graph of Sine and Cosine Between -2\pi and 2\pi');
set(aa,'String',[' Prosegisi Riemann  SE: ' num2str(i) ' ATHROISMATA = ' num2str(I) ])
plot(xnew,ynew); 
plot(x,Y,'ro') 
hold off
set(gca,'color',[.8 .8 .8])