Last active
October 1, 2017 18:07
-
-
Save lagenorhynque/f1a9389f0e2d2b999a3e5f20458e8b20 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
| user> (require '[clojure.math.numeric-tower :as math]) | |
| nil | |
| ;; y = e^xの区間[0,1]の面積の近似 | |
| user> (->> (map * | |
| (repeat 1/1000) | |
| (map #(Math/exp %) (range 0 1 1/1000))) | |
| (apply +)) | |
| 1.7174228307349653 | |
| ;; y = x^2の区間[0,1]の面積の近似 | |
| user> (->> (map * | |
| (repeat 1/1000) | |
| (map #(* % %) (range 0 1 1/1000))) | |
| (apply +) | |
| double) | |
| 0.3328335 | |
| user> |
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 Data.Ratio ((%)) | |
| -- y = e^xの区間[0,1]の面積の近似 | |
| λ> sum $ zipWith (*) (repeat 0.001) (map (\x -> exp . realToFrac $ x) [0, 1%1000..999%1000]) | |
| 1.7174228307349653 | |
| -- y = x^2の区間[0,1]の面積の近似 | |
| λ> realToFrac . sum $ zipWith (*) (repeat $ 1%1000) (map (\x -> x * x) [0, 1%1000..999%1000]) | |
| 0.3328335 | |
| λ> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment