lib/dydx/integrand.rb in dydx-0.1.0 vs lib/dydx/integrand.rb in dydx-0.1.1

- old
+ new

@@ -8,14 +8,18 @@ def [](a, b, n = 100) f = function a, b = [a, b].map(&:to_f) raise ArgumentError, 'b should be greater than a' if a > b + # HOT FIX: should implement Infinity class + a = - 1000 if a == - Float::INFINITY + b = 1000 if b == Float::INFINITY + h = (b - a) / n sum = 0.0 xi = ->(i){ a + h * i } n.to_i.times do |i| - sum += ( f(xi.(i)) + 4.0 * f(xi.(i) + h / 2.0 ) + f(xi.(i) + h) ) rescue binding.pry + sum += ( f(xi.(i)) + 4.0 * f(xi.(i) + h / 2.0 ) + f(xi.(i) + h) ) end ( h * sum ) / 6.0 end end end