Skip to content

Instantly share code, notes, and snippets.

@akira093
Created March 7, 2013 19:33
Show Gist options
  • Save akira093/5111035 to your computer and use it in GitHub Desktop.
Save akira093/5111035 to your computer and use it in GitHub Desktop.
main :: IO ()
main = mapM_ (print . abs . ((cos x) -) . (myCosTaylor x)) [1 .. 100]
where x = 30
fac :: Integral a => a -> a
fac 0 = 1
fac n = fac (n-1) * n
a :: Integral a => Double -> a -> Double
a x i = if odd i
then - x ^ (2 * i) / (fromIntegral . fac) (2 * i)
else x ^ (2 * i) / (fromIntegral . fac) (2 * i)
myCosTaylor :: Integral a => Double -> a -> Double
myCosTaylor x n = sum $ take (fromIntegral n) (map (a x) [0..])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment