Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
5
Task/Euler-method/Haskell/euler-method-1.hs
Normal file
5
Task/Euler-method/Haskell/euler-method-1.hs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
-- the solver
|
||||
dsolveBy _ _ [] _ = error "empty solution interval"
|
||||
dsolveBy method f mesh x0 = zip mesh results
|
||||
where results = scanl (method f) x0 intervals
|
||||
intervals = zip mesh (tail mesh)
|
||||
14
Task/Euler-method/Haskell/euler-method-2.hs
Normal file
14
Task/Euler-method/Haskell/euler-method-2.hs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
-- 1-st order Euler
|
||||
euler f x (t1,t2) = x + (t2 - t1) * f t1 x
|
||||
|
||||
-- 2-nd order Runge-Kutta
|
||||
rk2 f x (t1,t2) = x + h * f (t1 + h/2) (x + h/2*f t1 x)
|
||||
where h = t2 - t1
|
||||
|
||||
-- 4-th order Runge-Kutta
|
||||
rk4 f x (t1,t2) = x + h/6 * (k1 + 2*k2 + 2*k3 + k4)
|
||||
where k1 = f t1 x
|
||||
k2 = f (t1 + h/2) (x + h/2*k1)
|
||||
k3 = f (t1 + h/2) (x + h/2*k2)
|
||||
k4 = f (t1 + h) (x + h*k3)
|
||||
h = t2 - t1
|
||||
23
Task/Euler-method/Haskell/euler-method-3.hs
Normal file
23
Task/Euler-method/Haskell/euler-method-3.hs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import Graphics.EasyPlot
|
||||
|
||||
newton t temp = -0.07 * (temp - 20)
|
||||
|
||||
exactSolution t = 80*exp(-0.07*t)+20
|
||||
|
||||
test1 = plot (PNG "euler1.png")
|
||||
[ Data2D [Title "Step 10", Style Lines] [] sol1
|
||||
, Data2D [Title "Step 5", Style Lines] [] sol2
|
||||
, Data2D [Title "Step 1", Style Lines] [] sol3
|
||||
, Function2D [Title "exact solution"] [Range 0 100] exactSolution ]
|
||||
where sol1 = dsolveBy euler newton [0,10..100] 100
|
||||
sol2 = dsolveBy euler newton [0,5..100] 100
|
||||
sol3 = dsolveBy euler newton [0,1..100] 100
|
||||
|
||||
test2 = plot (PNG "euler2.png")
|
||||
[ Data2D [Title "Euler"] [] sol1
|
||||
, Data2D [Title "RK2"] [] sol2
|
||||
, Data2D [Title "RK4"] [] sol3
|
||||
, Function2D [Title "exact solution"] [Range 0 100] exactSolution ]
|
||||
where sol1 = dsolveBy euler newton [0,10..100] 100
|
||||
sol2 = dsolveBy rk2 newton [0,10..100] 100
|
||||
sol3 = dsolveBy rk4 newton [0,10..100] 100
|
||||
Loading…
Add table
Add a link
Reference in a new issue