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