public class Summation extends Object
Summation.Term
s, xi, we have
\[
S = \sum (x_i)
\]
If a threshold
is specified, the summation is treated as a convergent series.
The summing process stops after \(x_i < \texttt{threshold}\).
Sample usages:
Summation series = new Summation(new Summation.Term() {
public double evaluate(double i) {
return i;
}
});
double sum = series.sum(1, 100);
Summation series = new Summation(new Summation.Term() {
public double evaluate(double i) {
return 1d / i;
}
}, 0.0001);
double sum = series.sumToInfinity(1);
Modifier and Type | Class and Description |
---|---|
static interface |
Summation.Term
Define the terms in a summation series.
|
Constructor and Description |
---|
Summation(Summation.Term term)
Construct a finite summation series.
|
Summation(Summation.Term term,
double threshold)
Construct a summation series.
|
Modifier and Type | Method and Description |
---|---|
double |
sum(double[] indices)
Partial summation of the selected terms.
|
double |
sum(double from,
double to,
double inc)
Sum up the terms from
from to to with the increment inc . |
double |
sum(int from,
int to)
Sum up the terms from
from to to with the increment 1. |
double |
sum(int from,
int to,
int inc)
Sum up the terms from
from to to with the increment inc . |
double |
sumToInfinity(double from,
double inc)
Sum up the terms from
from to infinity with increment inc until the series
converges. |
double |
sumToInfinity(int from)
Sum up the terms from
from to infinity with increment 1 until the series converges. |
public Summation(Summation.Term term, double threshold)
threshold
for all terms after a
certain index.term
- the terms to sum upthreshold
- the convergence threshold. When a term falls below it, the summing process
stops. For a finite summation, it should be set to 0.public Summation(Summation.Term term)
term
- the terms to sum uppublic double sum(int from, int to)
from
to to
with the increment 1.from
- the starting indexto
- the ending index (inclusive)public double sum(int from, int to, int inc)
from
to to
with the increment inc
.from
- the starting indexto
- the ending index (inclusive)inc
- the incrementpublic double sum(double from, double to, double inc)
from
to to
with the increment inc
.from
- the starting indexto
- the ending index (inclusive)inc
- the incrementpublic double sum(double[] indices)
indices
- the indices to the selected termspublic double sumToInfinity(int from)
from
to infinity with increment 1 until the series converges.from
- the starting indexpublic double sumToInfinity(double from, double inc)
from
to infinity with increment inc
until the series
converges.from
- the starting indexinc
- the incrementCopyright © 2010-2020 NM FinTech Ltd.. All Rights Reserved.