Skip to content

Instantly share code, notes, and snippets.

@nkapliev
Created February 26, 2016 13:44
Show Gist options
  • Save nkapliev/c8d9e8ec7b7c7a161b69 to your computer and use it in GitHub Desktop.
Save nkapliev/c8d9e8ec7b7c7a161b69 to your computer and use it in GitHub Desktop.
integration :: (Double -> Double) -> Double -> Double -> Double
integration f a b | a == b = 0
| otherwise = coeff * dx * ((f begin + f end) / 2 + helper (begin + dx) 0 (numberOfSteps - 1))
where
begin = min a b
end = max a b
numberOfSteps = 1000
coeff = if end == a then (-1) else 1
dx = (end - begin) / numberOfSteps
helper x sum n | n == 0 = sum
| otherwise = helper (x + dx) (sum + f x) (n - 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment