namespace DTS.Common.Calculations { public static class Integral { /// /// integrates a channel over an interval /// /// data to integrate /// index to start integration at (inclusive) /// index to end integration at (inclusive) /// public static double DefiniteIntegral(double[] input, int start, int end, double SPS) { //we use trapezoidal summation to get integral, there is an assumption that the input data is //tightly time aligned (otherwise we'd have to divide each interval by the actual distance, and not 1/2) //=(SUMPRODUCT(H25:H56,A26:A57)-SUMPRODUCT(A25:A56,H26:H57)+A57*H57-A25*H25)/2 double d = 0; for (int i = start + 1; i < end; i++) { d += 2D * input[i]; } d += input[start]; d += input[end]; return .5D * d / SPS; } } }