gov.sandia.cognition.math

## Class LentzMethod

• All Implemented Interfaces:
AnytimeAlgorithm<java.lang.Double>, IterativeAlgorithm, StoppableAlgorithm, CloneableSerializable, java.io.Serializable, java.lang.Cloneable

```@PublicationReference(author={"William H. Press","Saul A. Teukolsky","William T. Vetterling","Brian P. Flannery"},
title="Numerical Recipes in C, Second Edition",
type=Book,
year=1992,
pages={169,171},
url="http://www.nrbook.com/a/bookcpdf.php")
public class LentzMethod
extends AbstractAnytimeAlgorithm<java.lang.Double>```
This class implements Lentz's method for evaluating continued fractions. This is an iterative, approximate approach that has good convergence. By specifying the fraction as f(x) = b0 + a1/(b1+a1/(b2+a3/(b3+...))). Each iteration, we take the (a,b) coefficients and improve the approximation of f(x) and terminate after too many iterations or convergence.
Since:
2.1
Author:
Kevin R. Dixon
Serialized Form

• ### Fields inherited from class gov.sandia.cognition.algorithm.AbstractAnytimeAlgorithm

`maxIterations`
• ### Fields inherited from class gov.sandia.cognition.algorithm.AbstractIterativeAlgorithm

`DEFAULT_ITERATION, iteration`
• ### Constructor Summary

Constructors
Constructor and Description
`LentzMethod()`
Creates a new instance of LentzMethod
```LentzMethod(int maxIterations, double tolerance, double minDenominator)```
Creates a new instance of LentzMethod
• ### Method Summary

All Methods
Modifier and Type Method and Description
`double` `getFractionValue()`
Getter for fractionValue
`boolean` `getKeepGoing()`
Getter for keepGoing
`double` `getMinDenominator()`
Getter for minDenominator
`java.lang.Double` `getResult()`
Gets the current result of the algorithm.
`double` `getTolerance()`
Getter for tolerance
`boolean` `initializeAlgorithm(double b0)`
Initializes Lentz's method using the given values
`boolean` ```iterate(double a, double b)```
Step of Lentz's iteration
`protected void` `setFractionValue(double fractionValue)`
Setter for fractionValue
`void` `setMinDenominator(double minDenominator)`
Setter for minDenominator
`void` `setTolerance(double tolerance)`
Setter for tolerance
`void` `stop()`
Requests that the algorithm stop at the next appropriate point.
• ### Methods inherited from class gov.sandia.cognition.algorithm.AbstractAnytimeAlgorithm

`getMaxIterations, isResultValid, setMaxIterations`
• ### Methods inherited from class gov.sandia.cognition.algorithm.AbstractIterativeAlgorithm

`addIterativeAlgorithmListener, clone, fireAlgorithmEnded, fireAlgorithmStarted, fireStepEnded, fireStepStarted, getIteration, getListeners, removeIterativeAlgorithmListener, setIteration, setListeners`
• ### Methods inherited from class java.lang.Object

`equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• ### Methods inherited from interface gov.sandia.cognition.algorithm.IterativeAlgorithm

`addIterativeAlgorithmListener, getIteration, removeIterativeAlgorithmListener`
• ### Constructor Detail

• #### LentzMethod

`public LentzMethod()`
Creates a new instance of LentzMethod
• #### LentzMethod

```public LentzMethod(int maxIterations,
double tolerance,
double minDenominator)```
Creates a new instance of LentzMethod
Parameters:
`maxIterations` - Maximum number of iterations before stopping
`tolerance` - Tolerance of the algorithm for convergence
`minDenominator` - Value to keep denominators from equaling 0.0
• ### Method Detail

• #### initializeAlgorithm

`public boolean initializeAlgorithm(double b0)`
Initializes Lentz's method using the given values
Parameters:
`b0` - Initial "b" coefficient of the continued fraction
Returns:
keep going flag
• #### iterate

```public boolean iterate(double a,
double b)```
Step of Lentz's iteration
Parameters:
`a` - coefficient "a" from the next recursion of the continued fraction
`b` - coefficient "b" from the next recursion of the continued fraction
Returns:
keep going flag
• #### getTolerance

`public double getTolerance()`
Getter for tolerance
Returns:
Tolerance of the algorithm for convergence
• #### setTolerance

`public void setTolerance(double tolerance)`
Setter for tolerance
Parameters:
`tolerance` - Tolerance of the algorithm for convergence
• #### getMinDenominator

`public double getMinDenominator()`
Getter for minDenominator
Returns:
The minimum denominator.
• #### setMinDenominator

`public void setMinDenominator(double minDenominator)`
Setter for minDenominator
Parameters:
`minDenominator` - Value to keep denominators from equaling 0.0
• #### getResult

`public java.lang.Double getResult()`
Description copied from interface: `AnytimeAlgorithm`
Gets the current result of the algorithm.
Returns:
Current result of the algorithm.
• #### stop

`public void stop()`
Description copied from interface: `StoppableAlgorithm`
Requests that the algorithm stop at the next appropriate point. The stopping point is determined by the algorithm. The algorithm should try to balance between stopping as soon as possible and leaving the results in some consistent state.
• #### getKeepGoing

`public boolean getKeepGoing()`
Getter for keepGoing
Returns:
Flag to keep going or stop
• #### getFractionValue

`public double getFractionValue()`
Getter for fractionValue
Returns:
Running (intermediate) value of the fraction value
• #### setFractionValue

`protected void setFractionValue(double fractionValue)`
Setter for fractionValue
Parameters:
`fractionValue` - Running (intermediate) value of the fraction value