math-functions-0.3.4.4: Collection of tools for numeric computations

Copyright | (c) 2011 Bryan O'Sullivan 2018 Alexey Khudyakov
License | BSD3
Maintainer | bos@serpentine.com
Stability | experimental
Portability | portable
Safe Haskell | None
Language | Haskell2010

Numeric.RootFinding

Contents

- Data types
- Ridders algorithm
- Newton-Raphson algorithm
- References

Description

Haskell functions for finding the roots of real functions of real arguments. These algorithms are iterative so we provide both function returning root (or failure to find root) and list of iterations.

Synopsis

- data Root a
  - = NotBracketed
  - | SearchFailed
  - | Root !a
- fromRoot :: a -> Root a -> a
- data Tolerance
  - = RelTol !Double
  - | AbsTol !Double
- withinTolerance :: Tolerance -> Double -> Double -> Bool
- class IterationStep a where
  - matchRoot :: Tolerance -> a -> Maybe (Root Double)
- findRoot :: IterationStep a => Int -> Tolerance -> [a] -> Root Double
- data RiddersParam = RiddersParam {
  - riddersMaxIter :: !Int
  - riddersTol :: !Tolerance
  }
- ridders :: RiddersParam -> (Double, Double) -> (Double -> Double) -> Root Double
- riddersIterations :: (Double, Double) -> (Double -> Double) -> [RiddersStep]
- data RiddersStep
  - = RiddersStep !Double !Double
  - | RiddersBisect !Double !Double
  - | RiddersRoot !Double
  - | RiddersNoBracket
- data NewtonParam = NewtonParam {
  - newtonMaxIter :: !Int
  - newtonTol :: !Tolerance
  }
- newtonRaphson :: NewtonParam -> (Double, Double, Double) -> (Double -> (Double, Double)) -> Root Double
- newtonRaphsonIterations :: (Double, Double, Double) -> (Double -> (Double, Double)) -> [NewtonStep]
- data NewtonStep
  - = NewtonStep !Double !Double
  - | NewtonBisection !Double !Double
  - | NewtonRoot !Double
  - | NewtonNoBracket

# Data types

data Root a Source #

The result of searching for a root of a mathematical function.

Constructors

NotBracketed | The function does not have opposite signs when evaluated at the lower and upper bounds of the search.
SearchFailed | The search failed to converge to within the given error tolerance after the given number of iterations.
Root !a | A root was successfully found.

#### Instances

Instances details

Alternative Root Source # |
Instance details Defined in Numeric.RootFinding Methods empty :: Root a Source # (<|>) :: Root a -> Root a -> Root a Source # some :: Root a -> Root [a] Source # many :: Root a -> Root [a] Source #
Applicative Root Source # |
Instance details Defined in Numeric.RootFinding Methods pure :: a -> Root a Source # (<*>) :: Root (a -> b) -> Root a -> Root b Source # liftA2 :: (a -> b -> c) -> Root a -> Root b -> Root c Source # (*>) :: Root a -> Root b -> Root b Source # (<*) :: Root a -> Root b -> Root a Source #
Functor Root Source # |
Instance details Defined in Numeric.RootFinding Methods fmap :: (a -> b) -> Root a -> Root b Source # (<$) :: a -> Root b -> Root a Source #
Monad Root Source # |
Instance details Defined in Numeric.RootFinding Methods (>>=) :: Root a -> (a -> Root b) -> Root b Source # (>>) :: Root a -> Root b -> Root b Source # return :: a -> Root a Source #
MonadPlus Root Source # |
Instance details Defined in Numeric.RootFinding Methods mzero :: Root a Source # mplus :: Root a -> Root a -> Root a Source #
Foldable Root Source # |

Instance details

Defined in Numeric.RootFinding

Methods

fold :: Monoid m => Root m -> m Source #

foldMap :: Monoid m => (a -> m) -> Root a -> m Source #

foldMap' :: Monoid m => (a -> m) -> Root a -> m Source #

foldr :: (a -> b -> b) -> b -> Root a -> b Source #

foldr' :: (a -> b -> b) -> b -> Root a -> b Source #

foldl :: (b -> a -> b) -> b -> Root a -> b Source #

foldl' :: (b -> a -> b) -> b -> Root a -> b Source #

foldr1 :: (a -> a -> a) -> Root a -> a Source #

foldl1 :: (a -> a -> a) -> Root a -> a Source #

toList :: Root a -> [a] Source #

null :: Root a -> Bool Source #

length :: Root a -> Int Source #

elem :: Eq a => a -> Root a -> Bool Source #

maximum :: Ord a => Root a -> a Source #

minimum :: Ord a => Root a -> a Source #

sum :: Num a => Root a -> a Source #

product :: Num a => Root a -> a Source #

Traversable Root Source # |
Instance details Defined in Numeric.RootFinding Methods traverse :: Applicative f => (a -> f b) -> Root a -> f (Root b) Source # sequenceA :: Applicative f => Root (f a) -> f (Root a) Source # mapM :: Monad m => (a -> m b) -> Root a -> m (Root b) Source # sequence :: Monad m => Root (m a) -> m (Root a) Source #
NFData a => NFData (Root a) Source # |
Instance details Defined in Numeric.RootFinding Methods rnf :: Root a -> () Source #
Data a => Data (Root a) Source # |

Instance details

Defined in Numeric.RootFinding

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Root a -> c (Root a) Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Root a) Source #

toConstr :: Root a -> Constr Source #

dataTypeOf :: Root a -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Root a)) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Root a)) Source #

gmapT :: (forall b. Data b => b -> b) -> Root a -> Root a Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Root a -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Root a -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> Root a -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Root a -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Root a -> m (Root a) Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Root a -> m (Root a) Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Root a -> m (Root a) Source #

Generic (Root a) Source # |

Instance details

Defined in Numeric.RootFinding

Associated Types

type Rep (Root a) |

Instance details

Defined in Numeric.RootFinding

type Rep (Root a) = D1 ('MetaData "Root" "Numeric.RootFinding" "math-functions-0.3.4.4-KkvSBHYvNi81OgTWzY6YLi" 'False) (C1 ('MetaCons "NotBracketed" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "SearchFailed" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Root" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a))))

Methods

from :: Root a -> Rep (Root a) x Source #

to :: Rep (Root a) x -> Root a Source #

Read a => Read (Root a) Source # |
Instance details Defined in Numeric.RootFinding Methods readsPrec :: Int -> ReadS (Root a) Source # readList :: ReadS [Root a] Source # readPrec :: ReadPrec (Root a) Source # readListPrec :: ReadPrec [Root a] Source #
Show a => Show (Root a) Source # |
Instance details Defined in Numeric.RootFinding Methods showsPrec :: Int -> Root a -> ShowS Source # show :: Root a -> String Source # showList :: [Root a] -> ShowS Source #
Eq a => Eq (Root a) Source # |
Instance details Defined in Numeric.RootFinding Methods (==) :: Root a -> Root a -> Bool Source # (/=) :: Root a -> Root a -> Bool Source #
type Rep (Root a) Source # |

Instance details

Defined in Numeric.RootFinding

type Rep (Root a) = D1 ('MetaData "Root" "Numeric.RootFinding" "math-functions-0.3.4.4-KkvSBHYvNi81OgTWzY6YLi" 'False) (C1 ('MetaCons "NotBracketed" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "SearchFailed" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Root" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a))))

fromRoot Source #

Arguments

:: a | Default value.
-> Root a | Result of search for a root.
-> a |

Returns either the result of a search for a root, or the default value if the search failed.

data Tolerance Source #

Error tolerance for finding root. It describes when root finding algorithm should stop trying to improve approximation.

Constructors

RelTol !Double | Relative error tolerance. Given `RelTol ε` two values are considered approximately equal if \[ \frac{|a - b|}{|\operatorname{max}(a,b)} < \varepsilon \]
AbsTol !Double | Absolute error tolerance. Given `AbsTol δ` two values are considered approximately equal if \[ |a - b| < \delta \]. Note that `AbsTol 0` could be used to require to find approximation within machine precision.

#### Instances

Instances details

Data Tolerance Source # |

Instance details

Defined in Numeric.RootFinding

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Tolerance -> c Tolerance Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Tolerance Source #

toConstr :: Tolerance -> Constr Source #

dataTypeOf :: Tolerance -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Tolerance) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Tolerance) Source #

gmapT :: (forall b. Data b => b -> b) -> Tolerance -> Tolerance Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Tolerance -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Tolerance -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> Tolerance -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Tolerance -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Tolerance -> m Tolerance Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Tolerance -> m Tolerance Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Tolerance -> m Tolerance Source #

Generic Tolerance Source # |

Instance details

Defined in Numeric.RootFinding

Associated Types

type Rep Tolerance |

Instance details

Defined in Numeric.RootFinding

type Rep Tolerance = D1 ('MetaData "Tolerance" "Numeric.RootFinding" "math-functions-0.3.4.4-KkvSBHYvNi81OgTWzY6YLi" 'False) (C1 ('MetaCons "RelTol" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Double)) :+: C1 ('MetaCons "AbsTol" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Double)))

Methods

from :: Tolerance -> Rep Tolerance x Source #

to :: Rep Tolerance x -> Tolerance Source #

Read Tolerance Source # |
Instance details Defined in Numeric.RootFinding Methods readsPrec :: Int -> ReadS Tolerance Source # readList :: ReadS [Tolerance] Source # readPrec :: ReadPrec Tolerance Source # readListPrec :: ReadPrec [Tolerance] Source #
Show Tolerance Source # |
Instance details Defined in Numeric.RootFinding Methods showsPrec :: Int -> Tolerance -> ShowS Source # show :: Tolerance -> String Source # showList :: [Tolerance] -> ShowS Source #
Eq Tolerance Source # |
Instance details Defined in Numeric.RootFinding Methods (==) :: Tolerance -> Tolerance -> Bool Source # (/=) :: Tolerance -> Tolerance -> Bool Source #
type Rep Tolerance Source # |

Instance details

Defined in Numeric.RootFinding

type Rep Tolerance = D1 ('MetaData "Tolerance" "Numeric.RootFinding" "math-functions-0.3.4.4-KkvSBHYvNi81OgTWzY6YLi" 'False) (C1 ('MetaCons "RelTol" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Double)) :+: C1 ('MetaCons "AbsTol" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Double)))

withinTolerance :: Tolerance -> Double -> Double -> Bool Source #

Check that two values are approximately equal. In addition to specification values are considered equal if they're within 1ulp of precision. No further improvement could be done anyway.

class IterationStep a where Source #

Type class for checking whether iteration converged already.

Methods

matchRoot :: Tolerance -> a -> Maybe (Root Double) Source #

Return `Just root` is current iteration converged within required error tolerance. Returns `Nothing` otherwise.

#### Instances

Instances details

IterationStep NewtonStep Source # |
Instance details Defined in Numeric.RootFinding Methods matchRoot :: Tolerance -> NewtonStep -> Maybe (Root Double) Source #
IterationStep RiddersStep Source # |
Instance details Defined in Numeric.RootFinding Methods matchRoot :: Tolerance -> RiddersStep -> Maybe (Root Double) Source #

findRoot Source #

Arguments

:: IterationStep a |
=> Int | Maximum
-> Tolerance | Error tolerance
-> [a] |
-> Root Double |

Find root in lazy list of iterations.

# Ridders algorithm

data RiddersParam Source #

Parameters for `ridders` root finding

Constructors

RiddersParam |

Fields

- riddersMaxIter :: !Int

  Maximum number of iterations. Default = 100

- riddersTol :: !Tolerance

  Error tolerance for root approximation. Default is relative error 4·ε, where ε is machine precision.

#### Instances

Instances details

Default RiddersParam Source # |
Instance details Defined in Numeric.RootFinding Methods def :: RiddersParam #
Data RiddersParam Source # |

Instance details

Defined in Numeric.RootFinding

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> RiddersParam -> c RiddersParam Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c RiddersParam Source #

toConstr :: RiddersParam -> Constr Source #

dataTypeOf :: RiddersParam -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c RiddersParam) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c RiddersParam) Source #

gmapT :: (forall b. Data b => b -> b) -> RiddersParam -> RiddersParam Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> RiddersParam -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> RiddersParam -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> RiddersParam -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> RiddersParam -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> RiddersParam -> m RiddersParam Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> RiddersParam -> m RiddersParam Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> RiddersParam -> m RiddersParam Source #

Generic RiddersParam Source # |

Instance details

Defined in Numeric.RootFinding

Associated Types

type Rep RiddersParam |

Instance details

Defined in Numeric.RootFinding

type Rep RiddersParam = D1 ('MetaData "RiddersParam" "Numeric.RootFinding" "math-functions-0.3.4.4-KkvSBHYvNi81OgTWzY6YLi" 'False) (C1 ('MetaCons "RiddersParam" 'PrefixI 'True) (S1 ('MetaSel ('Just "riddersMaxIter") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int) :*: S1 ('MetaSel ('Just "riddersTol") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Tolerance)))

Methods

from :: RiddersParam -> Rep RiddersParam x Source #

to :: Rep RiddersParam x -> RiddersParam Source #

Read RiddersParam Source # |
Instance details Defined in Numeric.RootFinding Methods readsPrec :: Int -> ReadS RiddersParam Source # readList :: ReadS [RiddersParam] Source # readPrec :: ReadPrec RiddersParam Source # readListPrec :: ReadPrec [RiddersParam] Source #
Show RiddersParam Source # |
Instance details Defined in Numeric.RootFinding Methods showsPrec :: Int -> RiddersParam -> ShowS Source # show :: RiddersParam -> String Source # showList :: [RiddersParam] -> ShowS Source #
Eq RiddersParam Source # |
Instance details Defined in Numeric.RootFinding Methods (==) :: RiddersParam -> RiddersParam -> Bool Source # (/=) :: RiddersParam -> RiddersParam -> Bool Source #
type Rep RiddersParam Source # |

Instance details

Defined in Numeric.RootFinding

type Rep RiddersParam = D1 ('MetaData "RiddersParam" "Numeric.RootFinding" "math-functions-0.3.4.4-KkvSBHYvNi81OgTWzY6YLi" 'False) (C1 ('MetaCons "RiddersParam" 'PrefixI 'True) (S1 ('MetaSel ('Just "riddersMaxIter") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int) :*: S1 ('MetaSel ('Just "riddersTol") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Tolerance)))

ridders Source #

Arguments

:: RiddersParam | Parameters for algorithms. `def` provides reasonable defaults
-> (Double, Double) | Bracket for root
-> (Double -> Double) | Function to find roots
-> Root Double |

Use the method of Ridders[Ridders1979] to compute a root of a function. It doesn't require derivative and provide quadratic convergence (number of significant digits grows quadratically with number of iterations).

The function must have opposite signs when evaluated at the lower and upper bounds of the search (i.e. the root must be bracketed). If there's more that one root in the bracket iteration will converge to some root in the bracket.

riddersIterations :: (Double, Double) -> (Double -> Double) -> [RiddersStep] Source #

List of iterations for Ridders methods. See `ridders` for documentation of parameters

data RiddersStep Source #

Single Ridders step. It's a bracket of root

Constructors

RiddersStep !Double !Double | Ridders step. Parameters are bracket for the root
RiddersBisect !Double !Double | Bisection step. It's fallback which is taken when Ridders update takes us out of bracket
RiddersRoot !Double | Root found
RiddersNoBracket | Root is not bracketed

#### Instances

Instances details

NFData RiddersStep Source # |
Instance details Defined in Numeric.RootFinding Methods rnf :: RiddersStep -> () Source #
Data RiddersStep Source # |

Instance details

Defined in Numeric.RootFinding

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> RiddersStep -> c RiddersStep Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c RiddersStep Source #

toConstr :: RiddersStep -> Constr Source #

dataTypeOf :: RiddersStep -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c RiddersStep) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c RiddersStep) Source #

gmapT :: (forall b. Data b => b -> b) -> RiddersStep -> RiddersStep Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> RiddersStep -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> RiddersStep -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> RiddersStep -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> RiddersStep -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> RiddersStep -> m RiddersStep Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> RiddersStep -> m RiddersStep Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> RiddersStep -> m RiddersStep Source #

Generic RiddersStep Source # |

Instance details

Defined in Numeric.RootFinding

Associated Types

type Rep RiddersStep |

Instance details

Defined in Numeric.RootFinding

type Rep RiddersStep = D1 ('MetaData "RiddersStep" "Numeric.RootFinding" "math-functions-0.3.4.4-KkvSBHYvNi81OgTWzY6YLi" 'False) ((C1 ('MetaCons "RiddersStep" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Double) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Double)) :+: C1 ('MetaCons "RiddersBisect" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Double) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Double))) :+: (C1 ('MetaCons "RiddersRoot" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Double)) :+: C1 ('MetaCons "RiddersNoBracket" 'PrefixI 'False) (U1 :: Type -> Type)))

Methods

from :: RiddersStep -> Rep RiddersStep x Source #

to :: Rep RiddersStep x -> RiddersStep Source #

Read RiddersStep Source # |
Instance details Defined in Numeric.RootFinding Methods readsPrec :: Int -> ReadS RiddersStep Source # readList :: ReadS [RiddersStep] Source # readPrec :: ReadPrec RiddersStep Source # readListPrec :: ReadPrec [RiddersStep] Source #
Show RiddersStep Source # |
Instance details Defined in Numeric.RootFinding Methods showsPrec :: Int -> RiddersStep -> ShowS Source # show :: RiddersStep -> String Source # showList :: [RiddersStep] -> ShowS Source #
Eq RiddersStep Source # |
Instance details Defined in Numeric.RootFinding Methods (==) :: RiddersStep -> RiddersStep -> Bool Source # (/=) :: RiddersStep -> RiddersStep -> Bool Source #
IterationStep RiddersStep Source # |
Instance details Defined in Numeric.RootFinding Methods matchRoot :: Tolerance -> RiddersStep -> Maybe (Root Double) Source #
type Rep RiddersStep Source # |

Instance details

Defined in Numeric.RootFinding

type Rep RiddersStep = D1 ('MetaData "RiddersStep" "Numeric.RootFinding" "math-functions-0.3.4.4-KkvSBHYvNi81OgTWzY6YLi" 'False) ((C1 ('MetaCons "RiddersStep" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Double) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Double)) :+: C1 ('MetaCons "RiddersBisect" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Double) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Double))) :+: (C1 ('MetaCons "RiddersRoot" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Double)) :+: C1 ('MetaCons "RiddersNoBracket" 'PrefixI 'False) (U1 :: Type -> Type)))

# Newton-Raphson algorithm

data NewtonParam Source #

Parameters for `ridders` root finding

Constructors

NewtonParam |

Fields

- newtonMaxIter :: !Int

  Maximum number of iterations. Default = 50

- newtonTol :: !Tolerance

  Error tolerance for root approximation. Default is relative error 4·ε, where ε is machine precision

#### Instances

Instances details

Default NewtonParam Source # |
Instance details Defined in Numeric.RootFinding Methods def :: NewtonParam #
Data NewtonParam Source # |

Instance details

Defined in Numeric.RootFinding

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> NewtonParam -> c NewtonParam Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c NewtonParam Source #

toConstr :: NewtonParam -> Constr Source #

dataTypeOf :: NewtonParam -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c NewtonParam) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c NewtonParam) Source #

gmapT :: (forall b. Data b => b -> b) -> NewtonParam -> NewtonParam Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> NewtonParam -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> NewtonParam -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> NewtonParam -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> NewtonParam -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> NewtonParam -> m NewtonParam Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> NewtonParam -> m NewtonParam Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> NewtonParam -> m NewtonParam Source #

Generic NewtonParam Source # |

Instance details

Defined in Numeric.RootFinding

Associated Types

type Rep NewtonParam |

Instance details

Defined in Numeric.RootFinding

type Rep NewtonParam = D1 ('MetaData "NewtonParam" "Numeric.RootFinding" "math-functions-0.3.4.4-KkvSBHYvNi81OgTWzY6YLi" 'False) (C1 ('MetaCons "NewtonParam" 'PrefixI 'True) (S1 ('MetaSel ('Just "newtonMaxIter") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int) :*: S1 ('MetaSel ('Just "newtonTol") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Tolerance)))

Methods

from :: NewtonParam -> Rep NewtonParam x Source #

to :: Rep NewtonParam x -> NewtonParam Source #

Read NewtonParam Source # |
Instance details Defined in Numeric.RootFinding Methods readsPrec :: Int -> ReadS NewtonParam Source # readList :: ReadS [NewtonParam] Source # readPrec :: ReadPrec NewtonParam Source # readListPrec :: ReadPrec [NewtonParam] Source #
Show NewtonParam Source # |
Instance details Defined in Numeric.RootFinding Methods showsPrec :: Int -> NewtonParam -> ShowS Source # show :: NewtonParam -> String Source # showList :: [NewtonParam] -> ShowS Source #
Eq NewtonParam Source # |
Instance details Defined in Numeric.RootFinding Methods (==) :: NewtonParam -> NewtonParam -> Bool Source # (/=) :: NewtonParam -> NewtonParam -> Bool Source #
type Rep NewtonParam Source # |

Instance details

Defined in Numeric.RootFinding

type Rep NewtonParam = D1 ('MetaData "NewtonParam" "Numeric.RootFinding" "math-functions-0.3.4.4-KkvSBHYvNi81OgTWzY6YLi" 'False) (C1 ('MetaCons "NewtonParam" 'PrefixI 'True) (S1 ('MetaSel ('Just "newtonMaxIter") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int) :*: S1 ('MetaSel ('Just "newtonTol") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Tolerance)))

newtonRaphson Source #

Arguments

:: NewtonParam | Parameters for algorithm. `def` provide reasonable defaults.
-> (Double, Double, Double) | Triple of `(low bound, initial guess, upper bound)`. If initial guess if out of bracket middle of bracket is taken as approximation
-> (Double -> (Double, Double)) | Function to find root of. It returns pair of function value and its first derivative
-> Root Double |

Solve equation using Newton-Raphson iterations.

This method require both initial guess and bounds for root. If Newton step takes us out of bounds on root function reverts to bisection.

newtonRaphsonIterations :: (Double, Double, Double) -> (Double -> (Double, Double)) -> [NewtonStep] Source #

List of iteration for Newton-Raphson algorithm. See documentation for `newtonRaphson` for meaning of parameters.

data NewtonStep Source #

Steps for Newton iterations

Constructors

NewtonStep !Double !Double | Normal Newton-Raphson update. Parameters are: old guess, new guess
NewtonBisection !Double !Double | Bisection fallback when Newton-Raphson iteration doesn't work. Parameters are bracket on root
NewtonRoot !Double | Root is found
NewtonNoBracket | Root is not bracketed

#### Instances

Instances details

NFData NewtonStep Source # |
Instance details Defined in Numeric.RootFinding Methods rnf :: NewtonStep -> () Source #
Data NewtonStep Source # |

Instance details

Defined in Numeric.RootFinding

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> NewtonStep -> c NewtonStep Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c NewtonStep Source #

toConstr :: NewtonStep -> Constr Source #

dataTypeOf :: NewtonStep -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c NewtonStep) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c NewtonStep) Source #

gmapT :: (forall b. Data b => b -> b) -> NewtonStep -> NewtonStep Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> NewtonStep -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> NewtonStep -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> NewtonStep -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> NewtonStep -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> NewtonStep -> m NewtonStep Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> NewtonStep -> m NewtonStep Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> NewtonStep -> m NewtonStep Source #

Generic NewtonStep Source # |

Instance details

Defined in Numeric.RootFinding

Associated Types

type Rep NewtonStep |

Instance details

Defined in Numeric.RootFinding

type Rep NewtonStep = D1 ('MetaData "NewtonStep" "Numeric.RootFinding" "math-functions-0.3.4.4-KkvSBHYvNi81OgTWzY6YLi" 'False) ((C1 ('MetaCons "NewtonStep" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Double) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Double)) :+: C1 ('MetaCons "NewtonBisection" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Double) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Double))) :+: (C1 ('MetaCons "NewtonRoot" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Double)) :+: C1 ('MetaCons "NewtonNoBracket" 'PrefixI 'False) (U1 :: Type -> Type)))

Methods

from :: NewtonStep -> Rep NewtonStep x Source #

to :: Rep NewtonStep x -> NewtonStep Source #

Read NewtonStep Source # |
Instance details Defined in Numeric.RootFinding Methods readsPrec :: Int -> ReadS NewtonStep Source # readList :: ReadS [NewtonStep] Source # readPrec :: ReadPrec NewtonStep Source # readListPrec :: ReadPrec [NewtonStep] Source #
Show NewtonStep Source # |
Instance details Defined in Numeric.RootFinding Methods showsPrec :: Int -> NewtonStep -> ShowS Source # show :: NewtonStep -> String Source # showList :: [NewtonStep] -> ShowS Source #
Eq NewtonStep Source # |
Instance details Defined in Numeric.RootFinding Methods (==) :: NewtonStep -> NewtonStep -> Bool Source # (/=) :: NewtonStep -> NewtonStep -> Bool Source #
IterationStep NewtonStep Source # |
Instance details Defined in Numeric.RootFinding Methods matchRoot :: Tolerance -> NewtonStep -> Maybe (Root Double) Source #
type Rep NewtonStep Source # |

Instance details

Defined in Numeric.RootFinding

type Rep NewtonStep = D1 ('MetaData "NewtonStep" "Numeric.RootFinding" "math-functions-0.3.4.4-KkvSBHYvNi81OgTWzY6YLi" 'False) ((C1 ('MetaCons "NewtonStep" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Double) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Double)) :+: C1 ('MetaCons "NewtonBisection" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Double) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Double))) :+: (C1 ('MetaCons "NewtonRoot" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Double)) :+: C1 ('MetaCons "NewtonNoBracket" 'PrefixI 'False) (U1 :: Type -> Type)))

# References

- Ridders, C.F.J. (1979) A new algorithm for computing a single root of a real continuous function. IEEE Transactions on Circuits and Systems 26:979–980.
- Press W.H.; Teukolsky S.A.; Vetterling W.T.; Flannery B.P. (2007). "Section 9.2.1. Ridders' Method". /Numerical Recipes: The Art of Scientific Computing (3rd ed.)./ New York: Cambridge University Press. ISBN 978-0-521-88068-8.