summaryrefslogtreecommitdiff
path: root/examples/integrate.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2007-09-21 18:28:08 +0000
committerAlberto Ruiz <aruiz@um.es>2007-09-21 18:28:08 +0000
commit0198366bba7a5f2d67338633f9eb90889ffc31b2 (patch)
tree4897d90233b333ee2092e63a4b74c7bcb2d22577 /examples/integrate.hs
parentd4cb2692f9dae748da23371057a983deca4b2f80 (diff)
add examples
Diffstat (limited to 'examples/integrate.hs')
-rw-r--r--examples/integrate.hs17
1 files changed, 17 insertions, 0 deletions
diff --git a/examples/integrate.hs b/examples/integrate.hs
new file mode 100644
index 0000000..6da88ad
--- /dev/null
+++ b/examples/integrate.hs
@@ -0,0 +1,17 @@
1-- Numerical integration
2import 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 a b g1 g2 = quad h a b
8 where h x = quad (f x) (g1 x) (g2 x)
9
10volSphere r = 8 * quad2 (\x y -> sqrt (r*r-x*x-y*y))
11 0 r (const 0) (\x->sqrt (r*r-x*x))
12
13main = do
14 print $ quad (\x -> 4/(x^2+1)) 0 1
15 print pi
16 print $ volSphere 2.5
17 print $ 4/3*pi*2.5**3