summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominic Steinitz <dominic@steinitz.org>2018-04-22 08:54:57 +0100
committerDominic Steinitz <dominic@steinitz.org>2018-04-22 08:54:57 +0100
commit34d80e7ccf5941a9826e67c219e64b7b2802e329 (patch)
tree715da604bb61934a8562594e59d109055db7eee8
parent93c28276e163c8c620a3d1461f4270c7a86763cf (diff)
Add example to print Butcher Tableaux
-rw-r--r--examples/ButcherTableau.hs47
-rw-r--r--examples/examples.cabal8
2 files changed, 55 insertions, 0 deletions
diff --git a/examples/ButcherTableau.hs b/examples/ButcherTableau.hs
new file mode 100644
index 0000000..e667ef1
--- /dev/null
+++ b/examples/ButcherTableau.hs
@@ -0,0 +1,47 @@
1{-# OPTIONS_GHC -Wall #-}
2
3import Numeric.Sundials.ARKode.ODE
4import Numeric.LinearAlgebra
5
6import Data.List (intercalate)
7
8import Text.PrettyPrint.HughesPJClass
9
10
11butcherTableauTex :: ButcherTable -> String
12butcherTableauTex (ButcherTable m c b b2) =
13 render $
14 vcat [ text ("\n\\begin{array}{c|" ++ (concat $ replicate n "c") ++ "}")
15 , us
16 , text "\\hline"
17 , text bs <+> text "\\\\"
18 , text b2s <+> text "\\\\"
19 , text "\\end{array}"
20 ]
21 where
22 n = rows m
23 rs = toLists m
24 ss = map (\r -> intercalate " & " $ map show r) rs
25 ts = zipWith (\i r -> show i ++ " & " ++ r) (toList c) ss
26 us = vcat $ map (\r -> text r <+> text "\\\\") ts
27 bs = " & " ++ (intercalate " & " $ map show $ toList b)
28 b2s = " & " ++ (intercalate " & " $ map show $ toList b2)
29
30main :: IO ()
31main = do
32
33 let res = butcherTable (SDIRK_2_1_2 undefined)
34 putStrLn $ show res
35 putStrLn $ butcherTableauTex res
36
37 let resA = butcherTable (KVAERNO_4_2_3 undefined)
38 putStrLn $ show resA
39 putStrLn $ butcherTableauTex resA
40
41 let resB = butcherTable (SDIRK_5_3_4 undefined)
42 putStrLn $ show resB
43 putStrLn $ butcherTableauTex resB
44
45 let resC = butcherTable (FEHLBERG_6_4_5 undefined)
46 putStrLn $ show resC
47 putStrLn $ butcherTableauTex resC
diff --git a/examples/examples.cabal b/examples/examples.cabal
index c2fed7e..5e85a3d 100644
--- a/examples/examples.cabal
+++ b/examples/examples.cabal
@@ -19,3 +19,11 @@ executable sundials
19 hmatrix-sundials, 19 hmatrix-sundials,
20 hmatrix-gsl 20 hmatrix-gsl
21 default-language: Haskell2010 21 default-language: Haskell2010
22
23executable butcherTableau
24 main-is: ButcherTableau.hs
25 build-depends: base >=4.10 && <4.11,
26 hmatrix,
27 hmatrix-sundials,
28 pretty
29 default-language: Haskell2010