Created
September 20, 2010 06:01
-
-
Save jonsterling/587482 to your computer and use it in GitHub Desktop.
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
| import Prelude | |
| import Control.Applicative | |
| -- These are some sketchy implementations of integral approximations. | |
| -- They work, but are probably in need of refactoring. | |
| -- I repeat: I SUCK at Haskell, so this is really gross. | |
| midApp n a b f = h * (foldl (+) 0 vals) where | |
| h = (b - a)/n | |
| vals = [midF i | i <- [1..n]] where | |
| midF i = let x = (*h) in f $ (x (i - 1) + x i) / 2 | |
| simpApp n a b f = h/3 * (foldl (+) 0 vals) where | |
| h = (b - a)/(fromIntegral n) | |
| vals = (val <$> [0,n]) ++ (vals' odd 4) ++ (vals' even 2) where | |
| val i = f $ (fromIntegral i) * h | |
| vals' p m = (*m) <$> val <$> filter p [1..n-1] | |
| trapApp n a b f = h/2 * (foldl (+) 0 vals) where | |
| h = (b - a)/(fromIntegral n) | |
| vals = (val <$> [0,n]) ++ ((*2) <$> val <$> [1..n-1]) where | |
| val i = f $ (fromIntegral i) * h |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment