+{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE RebindableSyntax #-}
-module Integration.Simpson
+module Integration.Simpson (
+ simpson,
+ simpson_1 )
where
-import Misc (partition)
+import Misc ( partition )
-import NumericPrelude hiding (abs)
-import qualified Algebra.RealField as RealField
-import qualified Algebra.ToInteger as ToInteger
-import qualified Algebra.ToRational as ToRational
+import NumericPrelude hiding ( abs )
+import qualified Algebra.RealField as RealField ( C )
+import qualified Algebra.ToInteger as ToInteger ( C )
+import qualified Algebra.ToRational as ToRational ( C )
-- | Use the Simpson's rule to numerically integrate @f@ over the
-- interval [@a@, @b@].
+{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE RebindableSyntax #-}
-module Integration.Trapezoid
+module Integration.Trapezoid (
+ trapezoid,
+ trapezoid_1 )
where
-import Misc (partition)
+import Misc ( partition )
+
+import NumericPrelude hiding ( abs )
+import qualified Algebra.Field as Field ( C )
+import qualified Algebra.RealField as RealField ( C )
+import qualified Algebra.ToInteger as ToInteger ( C )
+import qualified Algebra.ToRational as ToRational ( C )
-import NumericPrelude hiding (abs)
-import qualified Algebra.Field as Field
-import qualified Algebra.RealField as RealField
-import qualified Algebra.ToInteger as ToInteger
-import qualified Algebra.ToRational as ToRational
-- | Use the trapezoid rule to numerically integrate @f@ over the
-- interval [@a@, @b@].
+{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
-- | Classical iterative methods to solve the system Ax = b.
-module Linear.Iteration
+module Linear.Iteration (
+ gauss_seidel_iteration,
+ gauss_seidel_iterations,
+ gauss_seidel_method,
+ jacobi_iteration,
+ jacobi_iterations,
+ jacobi_method,
+ rayleigh_quotient,
+ sor_iteration,
+ sor_iterations,
+ sor_method )
where
-import Data.List (find)
-import Data.Maybe (fromJust)
-import Data.Vector.Fixed (Arity, N1, S)
-import NumericPrelude hiding ((*))
-import qualified Algebra.Algebraic as Algebraic
-import qualified Algebra.Field as Field
-import qualified Algebra.RealField as RealField
-import qualified Algebra.ToRational as ToRational
-import qualified Prelude as P
+import Data.List ( find )
+import Data.Maybe ( fromJust )
+import Data.Vector.Fixed ( Arity, N1, S )
+import NumericPrelude hiding ( (*) )
+import qualified Algebra.Algebraic as Algebraic ( C )
+import qualified Algebra.Field as Field ( C )
+import qualified Algebra.RealField as RealField ( C )
+import qualified Algebra.ToRational as ToRational ( C )
+
+import Linear.Matrix (
+ Mat(..),
+ (!!!),
+ (*),
+ diagonal_part,
+ dot,
+ lt_part_strict,
+ transpose )
+import Linear.System ( forward_substitute )
+import Normed ( Normed(..) )
-import Linear.Matrix
-import Linear.System
-import Normed
-- | A generalized implementation for Jacobi, Gauss-Seidel, etc. All
-- that we really need to know is how to construct the matrix M, so we
--
-- Examples:
--
+-- >>> import Linear.Matrix ( Mat2, fromList, vec2d )
+--
-- >>> let m = fromList [[4,2],[2,2]] :: Mat2 Double
-- >>> let x0 = vec2d (0, 0::Double)
-- >>> let b = vec2d (1, 1::Double)
--
-- Examples:
--
+-- >>> import Linear.Matrix ( Mat2, fromList, vec2d )
+--
-- >>> let m = fromList [[4,2],[2,2]] :: Mat2 Double
-- >>> let x0 = vec2d (0, 0::Double)
-- >>> let b = vec2d (1, 1::Double)
--
-- Examples:
--
+-- >>> import Linear.Matrix ( Mat2, fromList, vec2d )
+--
-- >>> let m = fromList [[4,2],[2,2]] :: Mat2 Double
-- >>> let x0 = vec2d (0, 0::Double)
-- >>> let b = vec2d (1, 1::Double)
--
-- Examples:
--
+-- >>> import Linear.Matrix ( Mat2, fromList, vec2d )
+--
-- >>> let m = fromList [[4,2],[2,2]] :: Mat2 Double
-- >>> let x0 = vec2d (0, 0::Double)
-- >>> let b = vec2d (1, 1::Double)
--
-- Examples:
--
+-- >>> import Linear.Matrix ( Mat2, fromList, vec2d )
+--
-- >>> let m = fromList [[3,1],[1,2]] :: Mat2 Rational
-- >>> let v = vec2d (1, 1::Rational)
-- >>> rayleigh_quotient m v
toList,
zipWith
)
-import Data.Vector.Fixed.Cont (Arity, arity)
-import Linear.Vector
-import Normed
+import Data.Vector.Fixed.Cont ( Arity, arity )
+import Linear.Vector ( Vec, delete, element_sum )
+import Normed ( Normed(..) )
import NumericPrelude hiding ( (*), abs )
import qualified NumericPrelude as NP ( (*) )
import qualified Algebra.Absolute as Absolute ( C )
import Algebra.Absolute ( abs )
-import qualified Algebra.Additive as Additive
-import qualified Algebra.Algebraic as Algebraic
-import Algebra.Algebraic (root)
-import qualified Algebra.Ring as Ring
-import qualified Algebra.Module as Module
-import qualified Algebra.RealRing as RealRing
-import qualified Algebra.ToRational as ToRational
-import qualified Algebra.Transcendental as Transcendental
-import qualified Prelude as P
+import qualified Algebra.Additive as Additive ( C )
+import qualified Algebra.Algebraic as Algebraic ( C )
+import Algebra.Algebraic ( root )
+import qualified Algebra.Ring as Ring ( C )
+import qualified Algebra.Module as Module ( C )
+import qualified Algebra.RealRing as RealRing ( C )
+import qualified Algebra.ToRational as ToRational ( C )
+import qualified Algebra.Transcendental as Transcendental ( C )
+import qualified Prelude as P ( map )
data Mat m n a = (Arity m, Arity n) => Mat (Vec m (Vec n a))
type Mat1 a = Mat N1 N1 a
import qualified Algebra.Algebraic as Algebraic ( C )
import Data.Vector.Fixed ( ifoldl )
import Data.Vector.Fixed.Cont ( Arity )
-import Debug.Trace
import NumericPrelude hiding ( (*) )
import Linear.Matrix (
-- factorization. We keep the pair updated by multiplying @q@ and
-- @r@ by the new rotator (or its transpose).
--
+-- We do not require that the diagonal elements of R are positive,
+-- so our factorization is a little less unique than usual.
+--
-- Examples:
--
-- >>> import Linear.Matrix
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
-module Linear.System
+module Linear.System (
+ backward_substitute,
+ forward_substitute )
where
-import Data.Vector.Fixed (Arity, N1)
+import Data.Vector.Fixed ( Arity, N1 )
+import NumericPrelude hiding ( (*), abs )
+import qualified NumericPrelude as NP ( (*) )
+import qualified Algebra.Field as Field ( C )
-import Linear.Matrix
-
-import NumericPrelude hiding ((*), abs)
-import qualified NumericPrelude as NP ((*))
-import qualified Algebra.Field as Field
+import Linear.Matrix ( Mat(..), (!!!), construct, transpose )
-- | Solve the system m' * x = b', where m' is upper-triangular. Will
--
-- Examples:
--
+-- >>> import Linear.Matrix ( Mat2, Mat3, fromList, vec2d, vec3d )
+--
-- >>> let identity = fromList [[1,0,0],[0,1,0],[0,0,1]] :: Mat3 Double
-- >>> let b = vec3d (1, 2, 3::Double)
-- >>> forward_substitute identity b
--
-- Examples:
--
+-- >>> import Linear.Matrix ( Mat3, fromList, vec3d )
+--
-- >>> let identity = fromList [[1,0,0],[0,1,0],[0,0,1]] :: Mat3 Double
-- >>> let b = vec3d (1, 2, 3::Double)
-- >>> backward_substitute identity b
where
import NumericPrelude
-import Algebra.Field
-import Algebra.RealRing
-import Algebra.ToInteger
+import Algebra.Field ( C )
+import Algebra.RealRing ( C )
+import Algebra.ToInteger ( C )
-- | Partition the interval [@a@, @b@] into @n@ subintervals, which we
-- then return as a list of pairs.
import NumericPrelude hiding ( abs )
import Algebra.Absolute ( abs )
-import qualified Algebra.Absolute as Absolute
-import qualified Algebra.Algebraic as Algebraic
+import qualified Algebra.Absolute as Absolute ( C )
+import qualified Algebra.Algebraic as Algebraic ( C )
import Algebra.Algebraic ( root )
-import qualified Algebra.RealField as RealField
-import qualified Algebra.ToInteger as ToInteger
+import qualified Algebra.RealField as RealField ( C )
+import qualified Algebra.ToInteger as ToInteger ( C )
import qualified Algebra.ToRational as ToRational ( C )
import Data.Vector.Fixed ( S, Z )
import qualified Data.Vector.Fixed as V (
import Linear.Vector ( element_sum )
+
+-- | Instances of the 'Normed' class know how to compute their own
+-- p-norms for p=1,2,...,infinity.
+--
class Normed a where
norm_p :: (ToInteger.C c, Algebraic.C b, Absolute.C b) => c -> a -> b
norm_infty :: (RealField.C b) => a -> b
- -- | The "usual" norm. Defaults to the Euclidean norm.
+ -- | The \"usual\" norm. Defaults to the 2-norm.
norm :: (Algebraic.C b, Absolute.C b) => a -> b
norm = norm_p (2 :: Integer)
-- for x in [x0, xN].
--
-module ODE.IVP
+module ODE.IVP (
+ eulers_method,
+ eulers_method1,
+ eulers_methodH )
where
-import Misc (partition)
-import NumericPrelude hiding (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
+import Misc ( partition )
+import NumericPrelude hiding ( abs )
+import qualified Algebra.Field as Field ( C )
+import qualified Algebra.ToInteger as ToInteger ( C )
+import qualified Algebra.ToRational as ToRational ( C )
+import qualified Algebra.RealField as RealField ( C )
-- | A single iteration of Euler's method over the interval
-- [$x0$, $x0$+$h$].
--
-- where w(x) is some non-negative (or non-positive) weight function.
--
-module Polynomials.Orthogonal
+module Polynomials.Orthogonal (
+ legendre )
where
import NumericPrelude
-import qualified Algebra.RealField as RealField
+import qualified Algebra.RealField as RealField ( C )
import qualified Prelude as P
-- values to the next iteration of a function rather than passing
-- the function and the points at which to (re)evaluate it.
-module Roots.Fast
+module Roots.Fast (
+ bisect,
+ fixed_point_iterations,
+ fixed_point_with_iterations,
+ has_root,
+ trisect )
where
-import Data.List (find)
-import Data.Maybe (fromMaybe)
+import Data.List ( find )
+import Data.Maybe ( fromMaybe )
-import Normed
+import Normed ( Normed(..) )
+
+import NumericPrelude hiding ( abs )
+import qualified Algebra.Absolute as Absolute ( C )
+import qualified Algebra.Additive as Additive ( C )
+import qualified Algebra.Algebraic as Algebraic ( C )
+import qualified Algebra.RealRing as RealRing ( C )
+import qualified Algebra.RealField as RealField ( C )
-import NumericPrelude hiding (abs)
-import qualified Algebra.Absolute as Absolute
-import qualified Algebra.Additive as Additive
-import qualified Algebra.Algebraic as Algebraic
-import qualified Algebra.RealRing as RealRing
-import qualified Algebra.RealField as RealField
has_root :: (RealField.C a,
RealRing.C b,
-- where f is assumed to be continuous on the interval of interest.
--
-module Roots.Simple
+module Roots.Simple (
+ bisect,
+ fixed_point,
+ fixed_point_error_ratios,
+ fixed_point_iteration_count,
+ has_root,
+ newtons_method,
+ secant_method,
+ trisect )
where
import Data.List (find)
+import NumericPrelude hiding ( abs )
+import Algebra.Absolute ( abs )
+import qualified Algebra.Additive as Additive ( C )
+import qualified Algebra.Algebraic as Algebraic ( C )
+import qualified Algebra.Field as Field ( C )
+import qualified Algebra.RealField as RealField ( C )
+import qualified Algebra.RealRing as RealRing ( C )
-import Normed
+import Normed ( Normed(..) )
+import qualified Roots.Fast as F (
+ bisect,
+ fixed_point_iterations,
+ fixed_point_with_iterations,
+ has_root,
+ trisect )
-import qualified Roots.Fast as F
-
-import NumericPrelude hiding (abs)
-import Algebra.Absolute (abs)
-import qualified Algebra.Additive as Additive
-import qualified Algebra.Algebraic as Algebraic
-import qualified Algebra.Field as Field
-import qualified Algebra.RealField as RealField
-import qualified Algebra.RealRing as RealRing
-- | Does the (continuous) function @f@ have a root on the interval
-- [a,b]? If f(a) <] 0 and f(b) ]> 0, we know that there's a root in