X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FODE%2FIVP.hs;h=b4fd3dc5a37d32b29ef020a06bba47e0ef4de3ba;hb=59c49750fd2455574fe4e67ddd7e67a20321c8a8;hp=6bde763a8e264549b8dae24ecbe945b57c0b4e99;hpb=fe73028041fe3becce6ce1ff268181d55d54a011;p=numerical-analysis.git diff --git a/src/ODE/IVP.hs b/src/ODE/IVP.hs index 6bde763..b4fd3dc 100644 --- a/src/ODE/IVP.hs +++ b/src/ODE/IVP.hs @@ -1,4 +1,5 @@ {-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE RebindableSyntax #-} -- | Numerical solution of the initial value problem, -- @@ -12,7 +13,12 @@ module ODE.IVP where import Misc (partition) - +import NumericPrelude hiding (abs) +import Algebra.Absolute (abs) +import qualified Algebra.Field as Field +import qualified Algebra.ToInteger as ToInteger +import qualified Algebra.ToRational as ToRational +import qualified Algebra.RealField as RealField -- | A single iteration of Euler's method over the interval -- [$x0$, $x0$+$h$]. @@ -26,7 +32,7 @@ import Misc (partition) -- >>> eulers_method1 x0 y0 f h -- 2.0 -- -eulers_method1 :: (RealFrac a, RealFrac b) +eulers_method1 :: (Field.C a, ToRational.C a, Field.C b) => a -- ^ x0, the initial point -> b -- ^ y0, the initial value at x0 -> (a -> b -> b) -- ^ The function f(x,y) @@ -35,7 +41,7 @@ eulers_method1 :: (RealFrac a, RealFrac b) eulers_method1 x0 y0 f h = y0 + h'*y' where - h' = realToFrac h + h' = fromRational'$ toRational h y' = (f x0 y0) @@ -59,7 +65,11 @@ eulers_method1 x0 y0 f h = -- >>> head ys == y0 -- True -- -eulers_method :: forall a b c. (RealFrac a, RealFrac b, Integral c) +eulers_method :: forall a b c. (Field.C a, + ToRational.C a, + Field.C b, + ToInteger.C c, + Enum c) => a -- ^ x0, the initial point -> b -- ^ y0, the initial value at x0 -> a -- ^ xN, the terminal point @@ -102,7 +112,7 @@ eulers_method x0 y0 xN f n = -- >>> ys == ys' -- True -- -eulers_methodH :: (RealFrac a, RealFrac b) +eulers_methodH :: (RealField.C a, ToRational.C a, Field.C b) => a -- ^ x0, the initial point -> b -- ^ y0, the initial value at x0 -> a -- ^ xN, the terminal point