public abstract class SeriesCalculator
extends java.lang.Object
MathContext
is reached.
Stores the factors of the taylor series terms so that future calculations will be faster.
Modifier | Constructor and Description |
---|---|
protected |
SeriesCalculator()
Constructs a
SeriesCalculator that calculates single terms. |
protected |
SeriesCalculator(boolean calculateInPairs)
Constructs a
SeriesCalculator with control over whether the sum terms are calculated in pairs. |
Modifier and Type | Method and Description |
---|---|
java.math.BigDecimal |
calculate(java.math.BigDecimal x,
java.math.MathContext mathContext)
Calculates the series for the specified value x and the precision defined in the
MathContext . |
protected abstract void |
calculateNextFactor()
Calculates the factor of the next term.
|
protected abstract PowerIterator |
createPowerIterator(java.math.BigDecimal x,
java.math.MathContext mathContext)
Creates the
PowerIterator used for this series. |
protected abstract BigRational |
getCurrentFactor()
Returns the factor of the highest term already calculated.
|
protected BigRational |
getFactor(int index)
Returns the factor of the term with specified index.
|
protected SeriesCalculator()
SeriesCalculator
that calculates single terms.protected SeriesCalculator(boolean calculateInPairs)
SeriesCalculator
with control over whether the sum terms are calculated in pairs.
Calculation of pairs is useful for taylor series where the terms alternate the sign. In these cases it is more efficient to calculate two terms at once check then whether the acceptable error has been reached.
calculateInPairs
- true
to calculate the terms in pairs, false
to calculate single termspublic java.math.BigDecimal calculate(java.math.BigDecimal x, java.math.MathContext mathContext)
MathContext
.x
- the value xmathContext
- the MathContext
protected abstract PowerIterator createPowerIterator(java.math.BigDecimal x, java.math.MathContext mathContext)
PowerIterator
used for this series.x
- the value xmathContext
- the MathContext
PowerIterator
protected BigRational getFactor(int index)
index
- the index (starting with 0)protected abstract BigRational getCurrentFactor()
When called for the first time will return the factor of the first term (index 0).
After this call the method calculateNextFactor()
will be called to prepare for the next term.
protected abstract void calculateNextFactor()