]> gitweb.michael.orlitzky.com - numerical-analysis.git/blobdiff - src/ODE/IVP.hs
Fix an off-by-one error in Euler's method.
[numerical-analysis.git] / src / ODE / IVP.hs
index 5d715a6356df5fd291c325a0b831ca469facb94e..233e5f872a97f29e4e46dd3a34bc582484ac46ce 100644 (file)
@@ -56,6 +56,8 @@ eulers_method1 x0 y0 f h =
 --   >>> let yN = head $ reverse ys
 --   >>> abs ((exp 1) - yN) < 1/10^3
 --   True
+--   >>> head ys == y0
+--   True
 --
 eulers_method :: forall a b c. (RealFrac a, RealFrac b, Integral c)
                => a -- ^ x0, the initial point
@@ -65,7 +67,7 @@ eulers_method :: forall a b c. (RealFrac a, RealFrac b, Integral c)
                -> c -- ^ n, the number of intervals to use.
                -> [b]
 eulers_method x0 y0 xN f n =
-  go xs y0 f
+  y0 : go xs y0 f
   where
     xs = partition n x0 xN