summaryrefslogtreecommitdiff
path: root/examples/integrate.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2014-05-21 10:30:55 +0200
committerAlberto Ruiz <aruiz@um.es>2014-05-21 10:30:55 +0200
commit197e88c3b56d28840217010a2871c6ea3a4dd1a4 (patch)
tree825be9d6c9d87d23f7e5497c0133d11d52c63535 /examples/integrate.hs
parente07c3dee7235496b71a89233106d93f6cc94ada1 (diff)
update dependencies, move examples etc
Diffstat (limited to 'examples/integrate.hs')
-rw-r--r--examples/integrate.hs24
1 files changed, 24 insertions, 0 deletions
diff --git a/examples/integrate.hs b/examples/integrate.hs
new file mode 100644
index 0000000..3a03da6
--- /dev/null
+++ b/examples/integrate.hs
@@ -0,0 +1,24 @@
1-- Numerical integration
2import Numeric.GSL
3
4quad f a b = fst $ integrateQAGS 1E-9 100 f a b
5
6-- A multiple integral can be easily defined using partial application
7quad2 f y1 y2 g1 g2 = quad h y1 y2
8 where
9 h y = quad (flip f y) (g1 y) (g2 y)
10
11volSphere r = 8 * quad2 (\x y -> sqrt (r*r-x*x-y*y))
12 0 r (const 0) (\x->sqrt (r*r-x*x))
13
14-- wikipedia example
15exw = quad2 f 7 10 (const 11) (const 14)
16 where
17 f x y = x**2 + 4*y
18
19main = do
20 print $ quad (\x -> 4/(x^2+1)) 0 1
21 print pi
22 print $ volSphere 2.5
23 print $ 4/3*pi*2.5**3
24 print $ exw