diff options
Diffstat (limited to 'packages')
-rw-r--r-- | packages/sundials/src/Main.hs | 32 |
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 | ||
3 | import qualified Data.Vector.Storable as V | ||
4 | import Numeric.Sundials.Arkode.ODE | 3 | import Numeric.Sundials.Arkode.ODE |
5 | import Numeric.LinearAlgebra | 4 | import Numeric.LinearAlgebra |
6 | 5 | ||
@@ -9,11 +8,10 @@ import qualified Diagrams.Prelude as D | |||
9 | import Diagrams.Backend.Rasterific | 8 | import Diagrams.Backend.Rasterific |
10 | 9 | ||
11 | import Control.Lens | 10 | import Control.Lens |
12 | import Data.List (zip4) | ||
13 | 11 | ||
14 | 12 | brusselator :: a -> [Double] -> [Double] | |
15 | brusselator _t x = [ a - (w + 1) * u + v * u^2 | 13 | brusselator _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 | ||
25 | stiffish :: Double -> [Double] -> [Double] | ||
27 | stiffish t v = [ lamda * u + 1.0 / (1.0 + t * t) - lamda * atan t ] | 26 | stiffish 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 | ||
46 | main :: IO () | 45 | main :: IO () |
47 | main = do | 46 | main = 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 | |||