From d6f147bb46c47cc5f885b72536f5adbe6039af77 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sun, 9 Dec 2012 04:22:37 -0500 Subject: [PATCH] Fix an off-by-one error in Euler's method. --- src/ODE/IVP.hs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ODE/IVP.hs b/src/ODE/IVP.hs index 5d715a6..233e5f8 100644 --- a/src/ODE/IVP.hs +++ b/src/ODE/IVP.hs @@ -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 -- 2.43.2