HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulemath-functions-0.3.4.4Haskell2010

Numeric.RootFinding

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.

  • 6 types
  • 1 class
  • 7 values

Data types

6 declarations
datadata Root a
#

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.

Instances14Monad, Functor, Applicative, Foldable, Traversable, Alternative, …
valuefromRoot
  1. :: a

    Default value.

  2. -> Root a

    Result of search for a root.

  3. -> a
#

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

datadata Tolerance
#

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.

Instances6Eq, Data, Read, Show, Generic, Rep

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.

Ridders algorithm

4 declarations
datadata RiddersParam
#

Parameters for ridders root finding

Constructors

Instances7Eq, Data, Read, Show, Generic, Default, …
valueridders
  1. :: RiddersParam

    Parameters for algorithms. def provides reasonable defaults

  2. -> (Double, Double)

    Bracket for root

  3. -> (Double -> Double)

    Function to find roots

  4. -> 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.

datadata RiddersStep
#

Single Ridders step. It's a bracket of root

Constructors

Instances8Eq, Data, Read, Show, Generic, NFData, …

Newton-Raphson algorithm

4 declarations
datadata NewtonParam
#

Parameters for ridders root finding

Constructors

Instances7Eq, Data, Read, Show, Generic, Default, …
valuenewtonRaphson
  1. :: NewtonParam

    Parameters for algorithm. def provide reasonable defaults.

  2. -> (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

  3. -> (Double -> (Double, Double))

    Function to find root of. It returns pair of function value and its first derivative

  4. -> 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.

datadata NewtonStep
#

Steps for Newton iterations

Constructors

Instances8Eq, Data, Read, Show, Generic, NFData, …

References

0 declarations
  • 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.