1

快速提问。我得到了 10 000 行信息。我每行有 2 个值。该行的格式为:(时间,水速)。我想使用数值积分来解决通过传感器的水量,但我对如何在 Java 中解决这个问题感到非常困惑。

我会假设一个图表会很好,但我不需要它是图形的,所以也许一个数组列表可以解决问题。

任何提示、提示和技巧将不胜感激。

4

2 回答 2

1

您可以为此使用梯形规则:按时间对间隔进行排序,然后按如下方式计算总和:

// assume that time is expressed using some class
Time[] time = ...
// assume that the water speed is double, expressed in volume per unit of time.
// Further assume that Time units match the units in the denominator of water speed,
// e.g. if the speed is in galons per minute, then the time unit is minutes;
// if the speed is in galons per second, then the time unit is seconds, and so on
double[] speed = ...

double sum = 0;
for (int i = 0 ; i < time.length-1 ; i++) {
    double deltaT = time[i+1].subtract(time[i]).toTimeUnits();
    // This is the formula for the trapezoidal rule on non-uniform grid
    sum += (speed[i]+speed[i+1])*deltaT;
}
double totalFlow = sum / 2;
于 2013-03-18T12:21:30.530 回答
0

如果您已经将这些数据作为(时间、速度)对进行了积分,并且您想对给定时间段内的总流量进行积分,那么为什么不直接使用数值积分(例如 Euler、Simpson、Runga-Kutta)?读取这些值并将它们输入到集成例程中,您就完成了。

也许Apache Commons Math将是一个不错的起点。

图形表示会很好,并且可以很好地检查您的数值结果,但这不是必需的。

于 2013-03-18T12:18:42.360 回答