Created
January 17, 2014 02:55
-
-
Save acomminos/8467657 to your computer and use it in GitHub Desktop.
Haskell Riemann Sums
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data RiemannType = LeftSum | RightSum | MidSum | |
riemann :: RiemannType -> (Float -> Float) -> Float -> Float -> Float -> Float | |
riemann rt f a b n = dx * foldr (\l -> \r -> (f $ a + (l * dx)) + r) 0 range | |
where | |
range = case rt of | |
LeftSum -> [0..n-1] | |
RightSum -> [1..n] | |
MidSum -> [0.5..n-0.5] | |
dx = (b-a)/n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment