Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Solver1D<Impl>

Base class for 1-D solvers

The implementation of this class uses the so-called "Barton-Nackman trick", also known as "the curiously recurring template pattern". Concrete solvers will be declared as:

 class Foo extends Solver1D<Foo> {

     solveImpl(f: UnaryFunction<Real, Real>, accuracy: Real): Real {
         ...
     }

 }

Before calling solveImpl, the base class will set its protected data members so that:

  • _xMin and _xMax form a valid bracket;
  • _fxMin and _fxMax contain the values of the function in _xMin and _xMax;
  • _root is a valid initial guess. The implementation of solveImpl can safely assume all of the above.
todo
  • clean up the interface so that it is clear whether the accuracy is specified for $x$ or $f(x)$.
  • add target value (now the target value is 0.0)

Type parameters

Hierarchy

Implements

Index

Properties

Protected _evaluationNumber

_evaluationNumber: Size

Protected _fxMax

_fxMax: Real

Protected _fxMin

_fxMin: Real

Private _lowerBound

_lowerBound: Real

Private _lowerBoundEnforced

_lowerBoundEnforced: boolean = false

Protected _maxEvaluations

_maxEvaluations: Size = MAX_FUNCTION_EVALUATIONS

Protected _root

_root: Real

Private _upperBound

_upperBound: Real

Private _upperBoundEnforced

_upperBoundEnforced: boolean = false

Protected _xMax

_xMax: Real

Protected _xMin

_xMin: Real

Methods

Private _enforceBounds

  • Parameters

    Returns Real

impl

  • impl(): any

lowerBound

  • lowerBound(): Real
  • Returns Real

lowerBoundEnforced

  • lowerBoundEnforced(): boolean
  • Returns boolean

setLowerBound

  • setLowerBound(lowerBound: Real): void
  • sets the lower bound for the function domain

    Parameters

    Returns void

setMaxEvaluations

  • setMaxEvaluations(evaluations: Size): void
  • This method sets the maximum number of function evaluations for the bracketing routine. An error is thrown if a bracket is not found after this number of evaluations.

    Parameters

    Returns void

setUpperBound

  • setUpperBound(upperBound: Real): void
  • sets the upper bound for the function domain

    Parameters

    Returns void

solve1

  • This method returns the zero of the function $ f $, determined with the given accuracy $ \epsilon $; depending on the particular solver, this might mean that the returned $ x $ is such that $ |f(x)| < \epsilon $ , or that $ |x-\xi| < \epsilon $ where $ \xi $ is the real zero.

    This method contains a bracketing routine to which an initial guess must be supplied as well as a step used to scan the range of the possible bracketing values.

    Parameters

    Returns Real

solve2

  • This method returns the zero of the function $ f $, determined with the given accuracy $ \epsilon $; depending on the particular solver, this might mean that the returned $ x $ is such that $ |f(x)| < \epsilon $ , or that $ |x-\xi| < \epsilon $ where $ \xi $ is the real zero.

    An initial guess must be supplied, as well as two values $ x_\mathrm{min} $ and $ x_\mathrm{max} $ which must bracket the zero (i.e., either $ f(x_\mathrm{min}) \leq 0 \leq f(x_\mathrm{max}) $, or $ f(x_\mathrm{max}) \leq 0 \leq f(x_\mathrm{min}) $ must be true).

    Parameters

    Returns Real

upperBound

  • upperBound(): Real
  • Returns Real

upperBoundEnforced

  • upperBoundEnforced(): boolean
  • Returns boolean