summaryrefslogtreecommitdiff
path: root/examples/tests.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2007-06-16 15:52:07 +0000
committerAlberto Ruiz <aruiz@um.es>2007-06-16 15:52:07 +0000
commitb2af660f87a55dd15f4519b21e66837ec811dc25 (patch)
treef48a2dc5b1d996595e7cd69fbbff6397d3e7b600 /examples/tests.hs
parentcc2c8c39dc088dcace0d2749cfe9180bf5fdbfd2 (diff)
Fourier, minimization, polySolve
Diffstat (limited to 'examples/tests.hs')
-rw-r--r--examples/tests.hs33
1 files changed, 32 insertions, 1 deletions
diff --git a/examples/tests.hs b/examples/tests.hs
index 3b1d878..22c4674 100644
--- a/examples/tests.hs
+++ b/examples/tests.hs
@@ -12,11 +12,14 @@ import GSL.Vector
12import GSL.Integration 12import GSL.Integration
13import GSL.Differentiation 13import GSL.Differentiation
14import GSL.Special 14import GSL.Special
15import GSL.Fourier
16import GSL.Polynomials
15import LAPACK 17import LAPACK
16import Test.QuickCheck 18import Test.QuickCheck
17import Test.HUnit 19import Test.HUnit
18import Complex 20import Complex
19 21
22
20{- 23{-
21-- Bravo por quickCheck! 24-- Bravo por quickCheck!
22 25
@@ -244,6 +247,29 @@ pinvSVDR m = linearSolveSVDR Nothing m (ident (rows m))
244 247
245pinvSVDC m = linearSolveSVDC Nothing m (ident (rows m)) 248pinvSVDC m = linearSolveSVDC Nothing m (ident (rows m))
246 249
250--------------------------------------------------------------------
251
252polyEval cs x = foldr (\c ac->ac*x+c) 0 cs
253
254polySolveTest' p = length p <2 || last p == 0|| 1E-8 > maximum (map magnitude $ map (polyEval (map (:+0) p)) (polySolve p))
255 where l1 |~~| l2 = eps > aproxL magnitude l1 l2
256
257polySolveTest = assertBool "polySolve" (polySolveTest' [1,2,3,4])
258
259---------------------------------------------------------------------
260
261quad f a b = fst $ integrateQAGS 1E-9 100 f a b
262
263-- A multiple integral can be easily defined using partial application
264quad2 f a b g1 g2 = quad h a b
265 where h x = quad (f x) (g1 x) (g2 x)
266
267volSphere r = 8 * quad2 (\x y -> sqrt (r*r-x*x-y*y))
268 0 r (const 0) (\x->sqrt (r*r-x*x))
269
270integrateTest = assertBool "integrate" (abs (volSphere 2.5 - 4/3*pi*2.5^3) < eps)
271
272
247--------------------------------------------------------------------- 273---------------------------------------------------------------------
248 274
249arit1 u = vectorMapValR PowVS 2 (vectorMapR Sin u) 275arit1 u = vectorMapValR PowVS 2 (vectorMapR Sin u)
@@ -271,6 +297,8 @@ exponentialTest = do
271tests = TestList 297tests = TestList
272 [ TestCase $ besselTest 298 [ TestCase $ besselTest
273 , TestCase $ exponentialTest 299 , TestCase $ exponentialTest
300 , TestCase $ polySolveTest
301 , TestCase $ integrateTest
274 ] 302 ]
275 303
276---------------------------------------------------------------------- 304----------------------------------------------------------------------
@@ -315,9 +343,12 @@ main = do
315 quickCheck arit2 343 quickCheck arit2
316 putStrLn "--------- GSL ------" 344 putStrLn "--------- GSL ------"
317 runTestTT tests 345 runTestTT tests
346 quickCheck $ \v -> ifft (fft v) ~~ v
318 347
319kk = (2><2) 348kk = (2><2)
320 [ 1.0, 0.0 349 [ 1.0, 0.0
321 , -1.5, 1.0 ::Double] 350 , -1.5, 1.0 ::Double]
322 351
323v = 11 # [0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0::Double] \ No newline at end of file 352v = 11 # [0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0::Double]
353
354pol = [14.125,-7.666666666666667,-14.3,-13.0,-7.0,-9.6,4.666666666666666,13.0,0.5] \ No newline at end of file