function s = m_quad(fun,a,b,N)
% 
% Pocitame urcity integral z funkce fun na intervalu (a, b) s N kroky
% 
% Priklad volani: m_quad(@sin,0,pi,10)
%                 m_quad(@(r)r.^2+5.*r,0,pi,10) ... anonymni funkce
%
h = (b-a)/N;
s = 0;
for i = 0:N-1
    s = s + (fun(a+i*h) + fun(a+(i+1)*h))/2*h;
end

%  alternativni vektorovy zpusob:
%     h = (b-a)/N;
%     x = linspace(a,b,N+1);
%     s = sum((fun(x(1:end-1)+h/2))*h);
