This file contains 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 Graphics.UI.GLUT | |
display :: DisplayCallback | |
display = do | |
clear [ColorBuffer] | |
flush | |
main :: IO () | |
main = do | |
getArgsAndInitialize |
This file contains 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.List (unfoldr) | |
-- dx/dt = f | |
f t x v = v | |
-- dv/dt = g | |
g t x v = - om2 * x | |
-- パラメータ | |
om = 2 | |
om2 = om ** 2 | |
-- 区間と初期値 |
This file contains 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.List (unfoldr) | |
-- dy/dx = f | |
f x y = - a * y | |
-- パラメータ | |
a = 1 | |
-- 区間と初期値 | |
x0 = 0 | |
x1 = 5 | |
y0 = 1 |
This file contains 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.List (unfoldr) | |
-- dy/dx = f | |
f x y = - a * y | |
-- パラメータ | |
a = 1 | |
-- 区間と初期値 | |
x0 = 0 | |
x1 = 5 | |
y0 = 1 |
This file contains 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.List (unfoldr) | |
-- dy/dx = f | |
f x y = - a * y | |
-- パラメータ | |
a = 1 | |
-- 区間と初期値 | |
x0 = 0 | |
x1 = 5 | |
y0 = 1 |
This file contains 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 System.Random | |
import Data.List | |
main :: IO () | |
main = do | |
xGen <- getStdGen | |
yGen <- newStdGen | |
let n = 100000 | |
let xs = take n $ randomRs (0,1) xGen | |
ys = take n $ randomRs (0,1) yGen |
This file contains 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.List (foldl') | |
-- 長方形近似 | |
integral :: Double -> Double -> Double -> (Double -> Double) -> Double | |
integral a b dx f = foldl' (+) 0 $ map ((dx *) . f) xs | |
where xs = [a + dx*x| x <- [0..(b-a)/dx]] | |
-- 台形近似 | |
integral2 :: Double -> Double -> Double -> (Double -> Double) -> Double | |
integral2 a b dx f = foldl' (+) 0 $ map (\(y1,y2) -> dx * (y1 + y2) / 2) $ zip ys (tail ys) |
This file contains 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
{-# LANGUAGE OverloadedStrings #-} | |
import Web.Authenticate.OAuth | |
import Data.ByteString (ByteString) | |
import Data.Text.Encoding (encodeUtf8) | |
import Network.HTTP.Conduit | |
myOAuth :: OAuth | |
myOAuth = newOAuth { oauthServerName = "api.twitter.com" | |
, oauthConsumerKey = "Your Consumer Key" | |
, oauthConsumerSecret = "Your Consumer Secret" |
This file contains 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
{-# LANGUAGE OverloadedStrings #-} | |
{-# LANGUAGE DeriveGeneric #-} | |
import Web.Authenticate.OAuth | |
import Data.Text (Text) | |
import qualified Data.Text.IO as T | |
import Data.Aeson | |
import GHC.Generics | |
import Network.HTTP.Conduit | |
myOAuth :: OAuth |
This file contains 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
{-# LANGUAGE OverloadedStrings #-} | |
import Text.XML.Cursor | |
import Text.HTML.DOM (parseLBS) | |
import Network.HTTP.Conduit | |
import qualified Data.Text as T | |
import qualified Data.Text.IO as T | |
main :: IO () | |
main = do | |
doc <- parseLBS <$> simpleHttp "http://www.ishiy.xyz/archive.html" |