Skip to content

Instantly share code, notes, and snippets.

@glaznaj
Last active February 27, 2016 20:04
Show Gist options
  • Select an option

  • Save glaznaj/c4ab115f2e94ea10995e to your computer and use it in GitHub Desktop.

Select an option

Save glaznaj/c4ab115f2e94ea10995e to your computer and use it in GitHub Desktop.
integration :: (Double -> Double) -> Double -> Double -> Double
integration f a b = h * ((f a + f b) / 2 + sum 0 (n - 1))
where
n = 1000
h = (b - a) / n
sum result 0 = result
sum result iter = sum (result + f (a + iter * h)) (iter - 1)

Реализуйте функцию, находящую значение определённого интеграла от заданной функции f на заданном интервале [a,b] методом трапеций. (Используйте равномерную сетку; достаточно 1000 элементарных отрезков.)

integration :: (Double -> Double) -> Double -> Double -> Double
integration f a b = undefined
GHCi> integration sin pi 0
-2.0

Результат может отличаться от -2.0, но не более чем на 1e-4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment