-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Collection of numerical tools for integration, differentiation etc. -- -- Package provides function to perform numeric integration and -- differentiation, function interpolation. -- -- Changes in 0.1.0.1 -- -- @package numeric-tools @version 0.1.0.1 -- | Funtions for numerical integration. quadRomberg or -- quadSimpson are reasonable choices in most cases. For -- non-smooth function they converge poorly and quadTrapezoid -- should be used then. -- -- For example this code intergrates exponent from 0 to 1: -- --
--   >>> let res = quadRomberg defQuad (0, 1) exp
--   
-- --
--   >>> quadRes res     -- Integration result
--   Just 1.718281828459045
--   
-- --
--   >>> quadPrecEst res -- Estimate of precision
--   2.5844957590474064e-16
--   
-- --
--   >>> quadNIter res   -- Number of iterations performed
--   6
--   
module Numeric.Tools.Integration -- | Integration parameters for numerical routines. Note that each -- additional iteration doubles number of function evaluation required to -- compute integral. -- -- Number of iterations is capped at 30. data QuadParam QuadParam :: Double -> Int -> QuadParam -- | Relative precision of answer quadPrecision :: QuadParam -> Double -- | Maximum number of iterations quadMaxIter :: QuadParam -> Int -- | Default parameters for integration functions -- -- defQuad :: QuadParam -- | Result of numeric integration. data QuadRes QuadRes :: Maybe Double -> Double -> Int -> QuadRes -- | Integraion result quadRes :: QuadRes -> Maybe Double -- | Rough estimate of attained precision quadPrecEst :: QuadRes -> Double -- | Number of iterations quadNIter :: QuadRes -> Int -- | Integration of using trapezoids. This is robust algorithm and place -- and useful for not very smooth. But it is very slow. It hundreds times -- slower then quadRomberg if function is sufficiently smooth. quadTrapezoid :: QuadParam -> (Double, Double) -> (Double -> Double) -> QuadRes -- | Integration using Simpson rule. It should be more efficient than -- quadTrapezoid if function being integrated have finite fourth -- derivative. quadSimpson :: QuadParam -> (Double, Double) -> (Double -> Double) -> QuadRes -- | Integration using Romberg rule. For sufficiently smooth functions -- (e.g. analytic) it's a fastest of three. quadRomberg :: QuadParam -> (Double, Double) -> (Double -> Double) -> QuadRes instance Typeable QuadParam instance Typeable QuadRes instance Show QuadParam instance Eq QuadParam instance Data QuadParam instance Show QuadRes instance Eq QuadRes instance Data QuadRes -- | Numerical differentiation. diffRichardson is preferred way to -- calculate derivative. module Numeric.Tools.Differentiation -- | Differentiation result data DiffRes DiffRes :: Double -> Double -> DiffRes -- | Derivative value diffRes :: DiffRes -> Double -- | Rough error estimate diffPrecision :: DiffRes -> Double -- | Calculate derivative using Richaradson's deferred approach to limit. -- This is a preferred method for numeric differentiation since it's most -- precise. Function could be evaluated up to 20 times. -- -- Initial step size should be chosen fairly big. Too small one will -- result reduced precision, too big one in nonsensical answer. diffRichardson :: (Double -> Double) -> Double -> Double -> DiffRes -- | Simplest form of differentiation. Should be used only when function -- evaluation is prohibitively expensive and already computed value at -- point x should be reused. -- --
--   f'(x) = f(x+h) - f(x) / h
--   
diffSimple :: (Double -> Double) -> Double -> (Double, Double) -> Double -- | Simple differentiation. It uses simmetric rule and provide reasonable -- accuracy. It's suitable when function evaluation is expensive and -- precision could be traded for speed. -- --
--   f'(x) = f(x-h) + f(x+h) / 2h
--   
diffSimmetric :: (Double -> Double) -> Double -> Double -> Double -- | For number x and small h return such h' -- that x+h' and x differ by representable number representableDelta :: Double -> Double -> Double instance Typeable DiffRes instance Show DiffRes instance Eq DiffRes instance Data DiffRes -- | Numerical solution of ordinary equations. module Numeric.Tools.Equation -- | Solve equation f(x) = 0 using bisection method. Function is -- must be continous. If function has different signs at the ends of -- initial interval answer is always returned. Nothing is returned -- if function fails to find an answer. solveBisection :: Double -> (Double, Double) -> (Double -> Double) -> Maybe Double module Numeric.Classes.Indexing -- | Type class for array-like data type which support O(1) access -- by integer index starting from zero. class Indexable a where { type family IndexVal a :: *; { x ! i | i < 0 || i > size x = error "Numeric.Classes.Indexing.!: index is out of range" | otherwise = unsafeIndex x i } } size :: Indexable a => a -> Int unsafeIndex :: Indexable a => a -> Int -> IndexVal a (!) :: Indexable a => a -> Int -> IndexVal a -- | Check that index is valid validIndex :: Indexable a => a -> Int -> Bool instance Storable a => Indexable (Vector a) instance Unbox a => Indexable (Vector a) instance Indexable (Vector a) -- | 1-dimensional meshes. Used by Numeric.Tools.Interpolation. module Numeric.Tools.Mesh -- | Class for 1-dimensional meshes. Mesh is ordered set of points. Each -- instance must guarantee that every next point is greater that previous -- and there is at least 2 points in mesh. class Indexable a => Mesh a meshLowerBound :: Mesh a => a -> Double meshUpperBound :: Mesh a => a -> Double meshFindIndex :: Mesh a => a -> Double -> Int -- | Uniform mesh data UniformMesh -- | Create uniform mesh uniformMesh :: (Double, Double) -> Int -> UniformMesh -- | Distance between points uniformMeshStep :: UniformMesh -> Double instance Typeable UniformMesh instance Eq UniformMesh instance Show UniformMesh instance Data UniformMesh instance Mesh UniformMesh instance Indexable UniformMesh -- | Function useful for writing numeric code which works with mutable -- data. module Control.Monad.Numeric -- | For function which act much like for loop in the C forGen :: Monad m => a -> (a -> Bool) -> (a -> a) -> (a -> m ()) -> m () -- | Specialized for loop. Akin to: -- --
--   for( i = 0; i < 10; i++) { ...
--   
for :: Monad m => Int -> Int -> (Int -> m ()) -> m () -- | Function interpolation. -- -- Sine interpolation using cubic splines: -- --
--   >>> let tbl = cubicSpline $ tabulateFun (uniformMesh (0,10) 100) sin
--   
--   >>> tbl `at` 1.786
--   0.9769239849844867
--   
module Numeric.Tools.Interpolation -- | Interpolation for arbitraty meshes class Interpolation a at :: (Interpolation a, (IndexVal m) ~ Double, Mesh m) => a m -> Double -> Double tabulateFun :: (Interpolation a, (IndexVal m) ~ Double, Mesh m) => m -> (Double -> Double) -> a m unsafeTabulate :: (Interpolation a, (IndexVal m) ~ Double, Mesh m, Vector v Double) => m -> v Double -> a m interpolationMesh :: Interpolation a => a m -> m interpolationTable :: Interpolation a => a m -> Vector Double -- | Use table of already evaluated function and mesh. Sizes of mesh and -- table must coincide. tabulate :: (Interpolation a, (IndexVal m) ~ Double, Mesh m, Vector v Double) => m -> v Double -> a m -- | Data for linear interpolation data LinearInterp a -- | Function used to fix types linearInterp :: LinearInterp a -> LinearInterp a -- | Natural cubic splines data CubicSpline a -- | Function used to fix types cubicSpline :: CubicSpline a -> CubicSpline a instance Typeable1 LinearInterp instance Typeable1 CubicSpline instance Show a => Show (LinearInterp a) instance Eq a => Eq (LinearInterp a) instance Data a => Data (LinearInterp a) instance Eq a => Eq (CubicSpline a) instance Show a => Show (CubicSpline a) instance Data a => Data (CubicSpline a) instance Interpolation CubicSpline instance Interpolation LinearInterp instance Mesh a => Indexable (LinearInterp a)