def trapets integr for in integr call end integr call call end

1
2
3
4
5
6
7
8
9
def trapets(n)
integr = 0.0;
h = (@b - @a)/n;
for i in 1 .. (n - 1)
integr += @f.call(@a + h * i);
end
(integr + (@f.call(@a) + @f.call(@b))/2) * h
end