Class HarmonicSeries
java.lang.Object
org.episteme.core.mathematics.analysis.series.HarmonicSeries
- All Implemented Interfaces:
InfiniteSeries<Real>
Harmonic series: Σ 1/n, n=1..∞
The harmonic series is known to diverge, though it grows very slowly. It is useful in many areas of mathematics and computer science.
The partial sum H_n ≈ ln(n) + γ where γ ≈ 0.5772 is the Euler-Mascheroni constant.
Example
HarmonicSeries series = new HarmonicSeries(); Real h10 = series.partialSum(10); // 1 + 1/2 + 1/3 + ... + 1/10
- Since:
- 1.0
- Author:
- Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final RealEuler-Mascheroni constant γ ≈ 0.5772156649 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionapproximateSum(int n) Approximates the n-th harmonic number using the asymptotic formula.increment(int n) Returns the difference between consecutive harmonic numbers.booleanDetermines if this series is convergent.limit()Returns the limit of the series if convergent.partialSum(int n) Computes the partial sum of the first n terms.term(int k) Returns the k-th term of this series.toString()
-
Field Details
-
EULER_MASCHERONI
Euler-Mascheroni constant γ ≈ 0.5772156649
-
-
Constructor Details
-
HarmonicSeries
public HarmonicSeries()
-
-
Method Details
-
term
Description copied from interface:InfiniteSeriesReturns the k-th term of this series.- Specified by:
termin interfaceInfiniteSeries<Real>- Parameters:
k- the term index (k ≥ 0)- Returns:
- the term a(k)
-
partialSum
Description copied from interface:InfiniteSeriesComputes the partial sum of the first n terms.S_n = Σ a(k), k=0..n
- Specified by:
partialSumin interfaceInfiniteSeries<Real>- Parameters:
n- the number of terms to sum (n ≥ 0)- Returns:
- the partial sum S_n
-
isConvergent
public boolean isConvergent()Description copied from interface:InfiniteSeriesDetermines if this series is convergent.A series converges if lim(n→∞) S_n exists and is finite.
- Specified by:
isConvergentin interfaceInfiniteSeries<Real>- Returns:
- true if convergent, false if divergent
-
limit
Description copied from interface:InfiniteSeriesReturns the limit of the series if convergent.L = lim(n→∞) S_n
- Specified by:
limitin interfaceInfiniteSeries<Real>- Returns:
- the limit L
-
approximateSum
Approximates the n-th harmonic number using the asymptotic formula.H_n ≈ ln(n) + γ + 1/(2n) for large n
- Parameters:
n- the index- Returns:
- approximate value of H_n
-
increment
Returns the difference between consecutive harmonic numbers.H_n - H_{n-1} = 1/n
- Parameters:
n- the index (n > 0)- Returns:
- 1/n
-
toString
-