From 1925c123d7d8184a1d2ddc0a413e0fd2776e1083 Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Thu, 8 May 2014 08:48:12 +0200 Subject: empty hmatrix-base --- packages/hmatrix/examples/integrate.hs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 packages/hmatrix/examples/integrate.hs (limited to 'packages/hmatrix/examples/integrate.hs') diff --git a/packages/hmatrix/examples/integrate.hs b/packages/hmatrix/examples/integrate.hs new file mode 100644 index 0000000..3a03da6 --- /dev/null +++ b/packages/hmatrix/examples/integrate.hs @@ -0,0 +1,24 @@ +-- Numerical integration +import Numeric.GSL + +quad f a b = fst $ integrateQAGS 1E-9 100 f a b + +-- A multiple integral can be easily defined using partial application +quad2 f y1 y2 g1 g2 = quad h y1 y2 + where + h y = quad (flip f y) (g1 y) (g2 y) + +volSphere r = 8 * quad2 (\x y -> sqrt (r*r-x*x-y*y)) + 0 r (const 0) (\x->sqrt (r*r-x*x)) + +-- wikipedia example +exw = quad2 f 7 10 (const 11) (const 14) + where + f x y = x**2 + 4*y + +main = do + print $ quad (\x -> 4/(x^2+1)) 0 1 + print pi + print $ volSphere 2.5 + print $ 4/3*pi*2.5**3 + print $ exw -- cgit v1.2.3