# QuantLib_Solver1D man page

Solver1D< Impl > — Base class for 1-D solvers.

## Synopsis

`#include <ql/math/solver1d.hpp>`

Inherits **CuriouslyRecurringTemplate< Impl >**.

### Public Member Functions

**Modifiers**

template<class F >Real solve(const F &f,Realaccuracy,Realguess,Realstep) const

template<class F >Real solve(const F &f,Realaccuracy,Realguess,RealxMin,RealxMax) const

voidsetMaxEvaluations(Sizeevaluations)

voidsetLowerBound(ReallowerBound)

sets the lower bound for the function domain

voidsetUpperBound(RealupperBound)

sets the upper bound for the function domain

### Protected Attributes

Real root_Real xMin_Real xMax_Real fxMin_Real fxMax_Size maxEvaluations_Size evaluationNumber_

### Additional Inherited Members

## Detailed Description

### template<class Impl>

class QuantLib::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 : public Solver1D<Foo> {
public:
...
template <class F>
Real solveImpl(const F& f, Real accuracy) const {
...
}
};
```

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.

## Member Function Documentation

### Real solve (const F & f, Real accuracy, Real guess, Real step) const

This method returns the zero of the function $ f $, determined with the given accuracy $ \psilon $; depending on the particular solver, this might mean that the returned $ x $ is such that $ |f(x)| < \psilon $, or that $ |x-xi| < \psilon $ 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.

### Real solve (const F & f, Real accuracy, Real guess, Real xMin, Real xMax) const

This method returns the zero of the function $ f $, determined with the given accuracy $ \psilon $; depending on the particular solver, this might mean that the returned $ x $ is such that $ |f(x)| < \psilon $, or that $ |x-xi| < \psilon $ 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).

### void setMaxEvaluations (Size evaluations)

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.

## Author

Generated automatically by Doxygen for QuantLib from the source code.

## Referenced By

evaluationNumber_(3), fxMax_(3), fxMin_(3), maxEvaluations_(3), root_(3), setLowerBound(3), setMaxEvaluations(3), setUpperBound(3), solve(3), xMax_(3) and xMin_(3) are aliases of QuantLib_Solver1D(3).