% ------------------------
% Unter und Obersumme
% 18.09.12
% HeSe 2012/2013
% --------------

clear all
clc

format long

eps = 5*1e-6;

a = 0
b = pi/2

f = inline('sin(x)')
n = ceil((b-a)/eps*(f(b) - f(a)))
tic
deltax = (b-a)/n;
x = a:deltax:b;
y = f(x);


U_n = deltax*(sum(y) - y(n+1))
O_n = deltax*(sum(y) - y(1))
toc

tic
sum1 = 0.0;
sum2 = 0.0;
for k = 1:n
    sum1 = sum1 + f((k-1)*deltax);
    sum2 = sum2 + f(k*deltax);
end

n
U_n = deltax*sum1
O_n = deltax*sum2
toc