Anonymous user
Euler method: Difference between revisions
→{{header|Haskell}}: Fixed some typos
m (→{{header|Sidef}}: modified the code to work with Sidef 2.30) |
(→{{header|Haskell}}: Fixed some typos) |
||
Line 1,179:
dsolveBy method f mesh x0 = zip mesh results
where results = scanl (method f) x0 intervals
intervals = zip mesh (tail mesh)</lang>
euler f x (t1,t2) = x + (t2 - t1) * f t1 x</lang>▼
It is better to use strict <code>Data.List.scanl'</code> in the solver but avoiding highlighting problems we leave lazy <code>scanl</code> function.
<lang haskell>--
-- 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
|