summaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
Diffstat (limited to 'packages')
-rw-r--r--packages/sundials/src/Main.hs32
1 files changed, 15 insertions, 17 deletions
diff --git a/packages/sundials/src/Main.hs b/packages/sundials/src/Main.hs
index 5e51372..44426f6 100644
--- a/packages/sundials/src/Main.hs
+++ b/packages/sundials/src/Main.hs
@@ -1,6 +1,5 @@
1{-# OPTIONS_GHC -Wall #-} 1{-# OPTIONS_GHC -Wall #-}
2 2
3import qualified Data.Vector.Storable as V
4import Numeric.Sundials.Arkode.ODE 3import Numeric.Sundials.Arkode.ODE
5import Numeric.LinearAlgebra 4import Numeric.LinearAlgebra
6 5
@@ -9,11 +8,10 @@ import qualified Diagrams.Prelude as D
9import Diagrams.Backend.Rasterific 8import Diagrams.Backend.Rasterific
10 9
11import Control.Lens 10import Control.Lens
12import Data.List (zip4)
13 11
14 12brusselator :: a -> [Double] -> [Double]
15brusselator _t x = [ a - (w + 1) * u + v * u^2 13brusselator _t x = [ a - (w + 1) * u + v * u^(2::Int)
16 , w * u - v * u^2 14 , w * u - v * u^(2::Int)
17 , (b - w) / eps - w * u 15 , (b - w) / eps - w * u
18 ] 16 ]
19 where 17 where
@@ -24,6 +22,7 @@ brusselator _t x = [ a - (w + 1) * u + v * u^2
24 v = x !! 1 22 v = x !! 1
25 w = x !! 2 23 w = x !! 2
26 24
25stiffish :: Double -> [Double] -> [Double]
27stiffish t v = [ lamda * u + 1.0 / (1.0 + t * t) - lamda * atan t ] 26stiffish t v = [ lamda * u + 1.0 / (1.0 + t * t) - lamda * atan t ]
28 where 27 where
29 lamda = -100.0 28 lamda = -100.0
@@ -45,15 +44,14 @@ kSaxis xs = P.r2Axis &~ do
45 44
46main :: IO () 45main :: IO ()
47main = do 46main = do
48 let res = odeSolve brusselator [1.2, 3.1, 3.0] (fromList [0.0, 0.1 .. 10.0]) 47 do let res = odeSolve brusselator [1.2, 3.1, 3.0] (fromList [0.0, 0.1 .. 10.0])
49 putStrLn $ show res 48 putStrLn $ show res
50 renderRasterific "diagrams/brusselator.png" 49 renderRasterific "diagrams/brusselator.png"
51 (D.dims2D 500.0 500.0) 50 (D.dims2D 500.0 500.0)
52 (renderAxis $ lSaxis $ [0.0, 0.1 .. 10.0]:(toLists $ tr res)) 51 (renderAxis $ lSaxis $ [0.0, 0.1 .. 10.0]:(toLists $ tr res))
53 52
54 let res = odeSolve stiffish [0.0] (fromList [0.0, 0.1 .. 10.0]) 53 do let res = odeSolve stiffish [0.0] (fromList [0.0, 0.1 .. 10.0])
55 putStrLn $ show res 54 putStrLn $ show res
56 renderRasterific "diagrams/stiffish.png" 55 renderRasterific "diagrams/stiffish.png"
57 (D.dims2D 500.0 500.0) 56 (D.dims2D 500.0 500.0)
58 (renderAxis $ kSaxis $ zip [0.0, 0.1 .. 10.0] (concat $ toLists res)) 57 (renderAxis $ kSaxis $ zip [0.0, 0.1 .. 10.0] (concat $ toLists res))
59