summaryrefslogtreecommitdiff
path: root/packages/sundials/src/Main.hs
diff options
context:
space:
mode:
authorDominic Steinitz <dominic@steinitz.org>2018-03-31 13:06:35 +0100
committerDominic Steinitz <dominic@steinitz.org>2018-03-31 13:06:35 +0100
commit3c4411e48cbcfaf8035e893ac63aa250fcc56d3e (patch)
tree0542a6ab2c68f2c9245dedf7e04d4e15e279cfd3 /packages/sundials/src/Main.hs
parent5bcc77b1e115a8c8eb94a1aa1a441618bfeb0b54 (diff)
Add in the Jacobian
Diffstat (limited to 'packages/sundials/src/Main.hs')
-rw-r--r--packages/sundials/src/Main.hs27
1 files changed, 21 insertions, 6 deletions
diff --git a/packages/sundials/src/Main.hs b/packages/sundials/src/Main.hs
index 71bcbac..01d3595 100644
--- a/packages/sundials/src/Main.hs
+++ b/packages/sundials/src/Main.hs
@@ -27,11 +27,26 @@ brusselator _t x = [ a - (w + 1) * u + v * u^2
27 v = x !! 1 27 v = x !! 1
28 w = x !! 2 28 w = x !! 2
29 29
30brussJac _t x = (3><3) [ (-(w + 1.0)) + 2.0 * u * v, w - 2.0 * u * v, (-w)
31 , u * u , (-(u * u)) , 0.0
32 , (-u) , u , (-1.0) / eps - u
33 ]
34 where
35 y = toList x
36 u = y !! 0
37 v = y !! 1
38 w = y !! 2
39 eps = 5.0e-6
40
30stiffish t v = [ lamda * u + 1.0 / (1.0 + t * t) - lamda * atan t ] 41stiffish t v = [ lamda * u + 1.0 / (1.0 + t * t) - lamda * atan t ]
31 where 42 where
32 lamda = -100.0 43 lamda = -100.0
33 u = v !! 0 44 u = v !! 0
34 45
46stiffJac _t _v = (1><1) [ lamda ]
47 where
48 lamda = -100.0
49
35lSaxis :: [[Double]] -> P.Axis B D.V2 Double 50lSaxis :: [[Double]] -> P.Axis B D.V2 Double
36lSaxis xs = P.r2Axis &~ do 51lSaxis xs = P.r2Axis &~ do
37 let ts = xs!!0 52 let ts = xs!!0
@@ -77,14 +92,14 @@ main = do
77 putStrLn $ show res 92 putStrLn $ show res
78 putStrLn $ butcherTableauTex res 93 putStrLn $ butcherTableauTex res
79 94
80 let res = odeSolve KVAERNO_4_2_3 brusselator [1.2, 3.1, 3.0] (fromList [0.0, 0.1 .. 10.0]) 95 let res1 = odeSolve KVAERNO_4_2_3 brussJac brusselator [1.2, 3.1, 3.0] (fromList [0.0, 0.1 .. 10.0])
81 putStrLn $ show res 96 putStrLn $ show res1
82 renderRasterific "diagrams/brusselator.png" 97 renderRasterific "diagrams/brusselator.png"
83 (D.dims2D 500.0 500.0) 98 (D.dims2D 500.0 500.0)
84 (renderAxis $ lSaxis $ [0.0, 0.1 .. 10.0]:(toLists $ tr res)) 99 (renderAxis $ lSaxis $ [0.0, 0.1 .. 10.0]:(toLists $ tr res1))
85 100
86 let res = odeSolve KVAERNO_4_2_3 stiffish [0.0] (fromList [0.0, 0.1 .. 10.0]) 101 let res2 = odeSolve KVAERNO_4_2_3 stiffJac stiffish [0.0] (fromList [0.0, 0.1 .. 10.0])
87 putStrLn $ show res 102 putStrLn $ show res2
88 renderRasterific "diagrams/stiffish.png" 103 renderRasterific "diagrams/stiffish.png"
89 (D.dims2D 500.0 500.0) 104 (D.dims2D 500.0 500.0)
90 (renderAxis $ kSaxis $ zip [0.0, 0.1 .. 10.0] (concat $ toLists res)) 105 (renderAxis $ kSaxis $ zip [0.0, 0.1 .. 10.0] (concat $ toLists res2))