From 34d80e7ccf5941a9826e67c219e64b7b2802e329 Mon Sep 17 00:00:00 2001 From: Dominic Steinitz Date: Sun, 22 Apr 2018 08:54:57 +0100 Subject: Add example to print Butcher Tableaux --- examples/ButcherTableau.hs | 47 ++++++++++++++++++++++++++++++++++++++++++++++ examples/examples.cabal | 8 ++++++++ 2 files changed, 55 insertions(+) create mode 100644 examples/ButcherTableau.hs (limited to 'examples') 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 @@ +{-# OPTIONS_GHC -Wall #-} + +import Numeric.Sundials.ARKode.ODE +import Numeric.LinearAlgebra + +import Data.List (intercalate) + +import Text.PrettyPrint.HughesPJClass + + +butcherTableauTex :: ButcherTable -> String +butcherTableauTex (ButcherTable m c b b2) = + render $ + vcat [ text ("\n\\begin{array}{c|" ++ (concat $ replicate n "c") ++ "}") + , us + , text "\\hline" + , text bs <+> text "\\\\" + , text b2s <+> text "\\\\" + , text "\\end{array}" + ] + where + n = rows m + rs = toLists m + ss = map (\r -> intercalate " & " $ map show r) rs + ts = zipWith (\i r -> show i ++ " & " ++ r) (toList c) ss + us = vcat $ map (\r -> text r <+> text "\\\\") ts + bs = " & " ++ (intercalate " & " $ map show $ toList b) + b2s = " & " ++ (intercalate " & " $ map show $ toList b2) + +main :: IO () +main = do + + let res = butcherTable (SDIRK_2_1_2 undefined) + putStrLn $ show res + putStrLn $ butcherTableauTex res + + let resA = butcherTable (KVAERNO_4_2_3 undefined) + putStrLn $ show resA + putStrLn $ butcherTableauTex resA + + let resB = butcherTable (SDIRK_5_3_4 undefined) + putStrLn $ show resB + putStrLn $ butcherTableauTex resB + + let resC = butcherTable (FEHLBERG_6_4_5 undefined) + putStrLn $ show resC + 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 hmatrix-sundials, hmatrix-gsl default-language: Haskell2010 + +executable butcherTableau + main-is: ButcherTableau.hs + build-depends: base >=4.10 && <4.11, + hmatrix, + hmatrix-sundials, + pretty + default-language: Haskell2010 -- cgit v1.2.3