diff options
author | Dominic Steinitz <dominic@steinitz.org> | 2018-04-22 08:54:57 +0100 |
---|---|---|
committer | Dominic Steinitz <dominic@steinitz.org> | 2018-04-22 08:54:57 +0100 |
commit | 34d80e7ccf5941a9826e67c219e64b7b2802e329 (patch) | |
tree | 715da604bb61934a8562594e59d109055db7eee8 /examples/ButcherTableau.hs | |
parent | 93c28276e163c8c620a3d1461f4270c7a86763cf (diff) |
Add example to print Butcher Tableaux
Diffstat (limited to 'examples/ButcherTableau.hs')
-rw-r--r-- | examples/ButcherTableau.hs | 47 |
1 files changed, 47 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 | |||
3 | import Numeric.Sundials.ARKode.ODE | ||
4 | import Numeric.LinearAlgebra | ||
5 | |||
6 | import Data.List (intercalate) | ||
7 | |||
8 | import Text.PrettyPrint.HughesPJClass | ||
9 | |||
10 | |||
11 | butcherTableauTex :: ButcherTable -> String | ||
12 | butcherTableauTex (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 | |||
30 | main :: IO () | ||
31 | main = 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 | ||