From: Michael Orlitzky Date: Fri, 12 Oct 2012 17:16:36 +0000 (-0400) Subject: Make numbers == 3000.1.* required. X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=3a03a2bdc233f1504764b21149a13162486fc3bf;p=numerical-analysis.git Make numbers == 3000.1.* required. Import Data.Number.BigFloat in the .ghci file. Add a doctest for newtons_method using BigFloat. --- diff --git a/.ghci b/.ghci index 12335d1..e5788ad 100644 --- a/.ghci +++ b/.ghci @@ -4,5 +4,8 @@ -- Load everything. :l src/Roots/Simple.hs +-- Just for convenience. +import Data.Number.BigFloat + -- Use a calmer prompt. :set prompt "numerical-analysis> " diff --git a/numerical-analysis.cabal b/numerical-analysis.cabal index 7bd0fb4..995395d 100644 --- a/numerical-analysis.cabal +++ b/numerical-analysis.cabal @@ -20,6 +20,8 @@ library build-depends: base == 4.5.*, + numbers == 3000.1.*, + -- Test deps HUnit == 1.2.*, QuickCheck == 2.*, test-framework == 0.6.*, @@ -53,6 +55,7 @@ test-suite doctests main-is: Doctests.hs build-depends: base == 4.5.*, + numbers == 3000.1.*, -- Additional test dependencies. doctest == 0.7.* diff --git a/src/Roots/Simple.hs b/src/Roots/Simple.hs index 1ab9034..79750e8 100644 --- a/src/Roots/Simple.hs +++ b/src/Roots/Simple.hs @@ -114,6 +114,14 @@ newton_iterations f f' x0 = -- >>> abs (f root) < 1/100000 -- True -- +-- >>> import Data.Number.BigFloat +-- >>> let eps = 1/(10^20) :: BigFloat Prec50 +-- >>> let Just root = newtons_method f f' eps 2 +-- >>> root +-- 1.13472413840151949260544605450647284028100785303643e0 +-- >>> abs (f root) < eps +-- True +-- newtons_method :: (Fractional a, Ord a) => (a -> a) -- ^ The function @f@ whose root we seek -> (a -> a) -- ^ The derivative of @f@